added pot todos functionality

This commit is contained in:
2024-02-28 14:48:18 +01:00
parent c327355c8a
commit fcc6517110
17 changed files with 1798 additions and 45 deletions

View File

@ -146,8 +146,12 @@ const confirmDeletePOT = async () => {
store.commit('undoDelete');
store.commit('changeToTemplatelist');
} catch (err) {
// console.log(err.response.statusText);
console.log(err);
console.log(err.response.statusText);
}
try {
await Axios.delete(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/deleteTodosPOT/${chosenPOTId.value}`);
} catch (err) {
console.log(err.response.statusText);
}
} else {
store.commit('undoDelete');
@ -161,9 +165,7 @@ const getProductionOrderTemplates = async () => {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getAllProductionOrderTemplates`);
productionOrderTemplates.value = response.data;
} catch (err) {
// console.log(err.response.statusText);
console.log(err);
console.log(err.response.statusText);
}
}
@ -212,6 +214,8 @@ const updateCustomerID = async () => {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCustomerByName/${pot.value.customer}`);
customer.value = response.data;
pot.value.customerID = customer.value.customerID;
store.commit('toggleClientChanged');
store.commit('toggleClientId', pot.value.customerID);
} catch (err) {
console.log(err.response.statusText);
}
@ -237,6 +241,8 @@ const updateNewCustomerID = async () => {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCustomerByName/${newCustomer.value}`);
newCustomerID.value = response.data.customerID;
store.commit('toggleClientChanged');
store.commit('toggleClientId', newCustomerID.value)
} catch (err) {
console.log(err.response.statusText);
}

View File

@ -1,5 +1,6 @@
<template>
<div :class="['data', darkMode ? 'div-darkmode' : 'div-lightmode']">
<section v-if="!addBool"
:class="['template-checklist-information', darkMode ? 'section-darkmode' : 'section-lightmode']">
<div :class="['label', darkMode ? 'label-darkmode' : 'label-lightmode']">Checklist:</div>
<table class="data-table" id="template-checkklist">
<tbody>
@ -15,21 +16,127 @@
Task</th>
<th :class="['Comments', darkMode ? 'th-darkmode' : 'th-lightmode']">Comments</th>
</tr>
<tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<tr v-for="todo in potTodos" :key="todo.primaryID"
:class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<td
:class="['Step', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Step-darkmode' : 'Step-lightmode']">
...</td>
{{ todo.rowID }}
</td>
<td v-if="!editable"
:class="['Asset', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Asset-darkmode' : 'Asset-lightmode']">
{{ todo.asset }}</td>
<td v-if="editable"
:class="['Asset', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Asset-darkmode' : 'Asset-lightmode']">
<select id="customersDropDownChosenCI" v-model="todo.asset" @change="updatePOTTodo(todo)"
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="ci in configItemList" :key="ci.primaryID">
{{ ci.assetName }}
</option>
</select>
</td>
<td v-if="!editable"
:class="['Task', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Task-darkmode' : 'Task-lightmode']">
{{ todo.task }}</td>
<td v-if="editable"
:class="['Task', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Task-darkmode' : 'Task-lightmode']">
<input type="text" v-model="todo.task" @change="updatePOTTodo(todo)"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</td>
<td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']"> {{ todo.comments
}}</td>
<td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']"> <input type="text"
v-model="todo.comments" @change="updatePOTTodo(todo)"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']"> <button
:class="[darkMode ? 'deletePOTTodos-darkmode' : 'deletePOTTodos-lightmode']"
@click="deletePOTTodo(todo.primaryID)">-</button>
</td>
</tr>
<tr v-if="editable && addRow" :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<td
:class="['Step', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Step-darkmode' : 'Step-lightmode']">
{{ newStepTodo }}
</td>
<td
:class="['Asset', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Asset-darkmode' : 'Asset-lightmode']">
...</td>
<select id="customersDropDownChosenCI" v-model="newAssetTodo"
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="ci in configItemList" :key="ci.primaryID">
{{ ci.assetName }}
</option>
</select>
</td>
<td
:class="['Task', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Task-darkmode' : 'Task-lightmode']">
...</td>
<td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">...</td>
<input type="text" v-model="newTaskTodo"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</td>
<td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']"><input type="text"
v-model="newCommentsTodo"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']"> <button
:class="[darkMode ? 'savePOTTodos-darkmode' : 'savePOTTodos-lightmode']"
@click="addPOTTodo()">Save</button> <button
:class="[darkMode ? 'deleteLastPOTTodos-darkmode' : 'deleteLastPOTTodos-lightmode']"
@click="deleteNewRow()">-</button>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-if="editable && !addBool" id="editPOTTodos">
<button :class="[darkMode ? 'editPOTTodos-darkmode' : 'editPOTTodos-lightmode']"
@click="addChecklistRow()">+</button>
</section>
<section v-if="addBool"
:class="['template-checklist-information', darkMode ? 'section-darkmode' : 'section-lightmode']">
<div :class="['label', darkMode ? 'label-darkmode' : 'label-lightmode']">Checklist:</div>
<table class="data-table" id="template-checkklist">
<tbody>
<tr :class="['table-row', darkMode ? 'tr-head-darkmode' : 'tr-head-lightmode']" id="table-head">
<th
:class="['Step', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Step-darkmode' : 'Step-lightmode']">
Step</th>
<th
:class="['Asset', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Asset-darkmode' : 'Asset-lightmode']">
Asset</th>
<th
:class="['Task', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Task-darkmode' : 'Task-lightmode']">
Task</th>
<th :class="['Comments', darkMode ? 'th-darkmode' : 'th-lightmode']">Comments</th>
</tr>
<tr v-for="(newT, index) in newTodos" :key="index"
:class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
<td
:class="['Step', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Step-darkmode' : 'Step-lightmode']">
{{ newT.rowID }}
</td>
<td
:class="['Asset', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Asset-darkmode' : 'Asset-lightmode']">
<select id="customersDropDownChosenCI" v-model="newT.asset"
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="ci in configItemList" :key="ci.primaryID">
{{ ci.assetName }}
</option>
</select>
</td>
<td
:class="['Task', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Task-darkmode' : 'Task-lightmode']">
<input type="text" v-model="newT.task"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</td>
<td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']"> <input type="text"
v-model="newT.comments"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']"> <button
:class="[darkMode ? 'deletePOTTodos-darkmode' : 'deleteLastPOTTodos-lightmode']"
@click="deletePOTTodoFromNewTodos(index)">-</button>
</td>
</tr>
</tbody>
</table>
</section>
<section v-if="addBool" id="editPOTTodos">
<button :class="[darkMode ? 'editPOTTodos-darkmode' : 'editPOTTodos-lightmode']"
@click="addRowForNewPOT()">+</button>
</section>
<section v-if="addBool" id="saveNewPOT">
<button :class="[darkMode ? 'saveNewPOT-darkmode' : 'saveNewPOT-lightmode']" @click="addPOT()">Safe</button>
</section>
@ -37,7 +144,7 @@
<script setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../../clientsideConfig.js';
import { useStore } from 'vuex';
@ -45,6 +152,7 @@ import { computed } from 'vue';
const store = useStore();
const addBool = computed(() => store.state.new);
const editable = computed(() => store.state.editable);
const newNamePOT = computed(() => store.state.newNamePOT);
const newCustomerIDPOT = computed(() => store.state.newCustomerIDPOT);
@ -53,9 +161,37 @@ const newLastViewPOT = computed(() => store.state.newLastViewPOT);
const newUserPOT = computed(() => store.state.newUserPOT);
const newDescriptionPOT = computed(() => store.state.newDescriptionPOT);
const newNotesPOT = computed(() => store.state.newNotesPOT);
const newStepTodo = computed(() => potTodos.value.length);
const chosenPOTId = computed(() => store.state.chosenPOTId);
const clientChanged = computed(() => store.state.clientChanged);
const changedClientId = computed(() => store.state.changedClientId);
const darkMode = ref(true)
const addRow = ref(false);
const configItemList = ref([]);
const productionOrderTemplates = ref([]);
const potTodos = ref([])
const pot = ref({})
const newAssetTodo = ref('');
const newTaskTodo = ref('');
const newCommentsTodo = ref('');
const newTodos = reactive([]);
const newRowId = computed(() => newTodos.length)
// delete new todo row
const deleteNewRow = () => {
newAssetTodo.value = '';
newTaskTodo.value = '';
newCommentsTodo.value = '';
addRow.value = false;
}
const deletePOTTodoFromNewTodos = (index) => {
newTodos.splice(index, 1);
newTodos.forEach((todo, i) => {
todo.rowID = i
})
}
// add new production order template
const addPOT = async () => {
@ -82,6 +218,16 @@ const addPOT = async () => {
alert("Please choose a client!");
return;
}
let allFine = true;
newTodos.forEach(todo => {
if (todo.asset.length === 0) {
alert(`Please choose a config item for all todos.`);
allFine = false
}
})
if (!allFine) {
return
}
try {
const response = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/addPOT`,
{
@ -95,11 +241,101 @@ const addPOT = async () => {
});
store.commit('resetStore');
store.commit('changeToTemplatelist');
newTodos.forEach(async todo => {
try {
const res = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/addTodoPOT`,
{
templateID: response.data,
rowID: todo.rowID,
asset: todo.asset,
task: todo.task,
comment: todo.comments,
});
} catch (err) {
console.log(err.response.statusText);
}
})
} catch (err) {
console.log(err.response.statusText);
}
}
// add new row of todo for the new pot
const addRowForNewPOT = async () => {
if (newCustomerPOT.value.length === 0) {
alert("Please choose a client first!");
return;
}
await getConfigItemsFromClient();
newTodos.push({
templateID: chosenPOTId.value,
rowID: newRowId.value,
asset: '',
task: '',
comments: ''
});
}
//update data
const updatePOTTodo = async (todo) => {
if (todo.asset.length === 0) {
alert(`Please add the missing config item in row ${todo.rowID}!`);
return;
}
try {
await Axios.put(
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/updatePOTTodo`,
{
primaryID: todo.primaryID,
templateID: todo.templateID,
rowID: todo.rowID,
asset: todo.asset,
task: todo.task,
comments: todo.comments,
}
);
await getPOTById();
} catch (err) {
console.log(err.response.statusText);
}
}
// add new production order template todo
const addPOTTodo = async () => {
// check if all input data is valid
if (newAssetTodo.value.length === 0) {
alert("Please choose an asset for the new todo!");
return;
}
try {
const response = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/addTodoPOT`,
{
templateID: chosenPOTId.value,
rowID: newStepTodo.value,
asset: newAssetTodo.value,
task: newTaskTodo.value,
comment: newCommentsTodo.value,
});
addRow.value = false;
await getPOTTodosById();
newAssetTodo.value = '';
newTaskTodo.value = '';
newCommentsTodo.value = '';
} catch (err) {
console.log(err.response.statusText);
}
}
// add new row for the template checklist
const addChecklistRow = async () => {
await getConfigItemsFromClient();
if (addRow.value) {
alert('Please confirm the last added row first.')
return
}
addRow.value = true
}
//get all production order templates
const getProductionOrderTemplates = async () => {
try {
@ -117,9 +353,74 @@ const triggerBackendCallsWithDelay = async (fetchDataFunc) => {
}, 1000);
}
onMounted(() => {
triggerBackendCallsWithDelay(getProductionOrderTemplates);
// get production order template todos from id
const getPOTTodosById = async () => {
if (!addBool.value) {
try {
const response = await Axios.get(
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getTodosProductionOrderTemplate/${chosenPOTId.value}`
);
potTodos.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
}
//get all config items from the selected client
const getConfigItemsFromClient = async () => {
if (!addBool.value) {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCIFromClient/${pot.value.customerID}`);
configItemList.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
} else {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCIFromClient/${changedClientId.value}`);
configItemList.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
if (clientChanged.value) {
store.commit('toggleClientChanged');
}
}
// get production order template from id
const getPOTById = async () => {
if (!addBool.value) {
try {
const response = await Axios.get(
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getProductionOrderTemplate/${chosenPOTId.value}`
);
pot.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
await getConfigItemsFromClient();
}
const deletePOTTodo = async (id) => {
if (confirm("Do you really want to delete this production order template todo? It cannot be undone!")) {
try {
await Axios.delete(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/deletePOTTodo/${id}`);
} catch (err) {
console.log(err.response.statusText);
}
}
await getPOTTodosById();
}
watch(clientChanged, getPOTById);
onMounted(() => {
getPOTTodosById();
getPOTById();
triggerBackendCallsWithDelay(getProductionOrderTemplates);
});
</script>
@ -133,25 +434,53 @@ export default {
<style scoped>
.data {
display: flex;
flex-direction: column;
flex-direction: row;
align-items: flex-start;
justify-content: center;
align-self: stretch;
width: 100%;
padding: 1.25rem 1.875rem;
gap: 1.25rem;
border-radius: 0.625rem;
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
padding: 0 0.625rem;
border-radius: 0.3125rem;
box-shadow: 0.0625rem 0.0625rem 0.25rem 0rem rgba(0, 0, 0, 0.25) inset;
letter-spacing: 5%;
font: 400 0.75rem/250% Overpass, sans-serif;
}
.div-darkmode {
.section-darkmode {
background-color: #2c2c2c;
}
.div-lightmode {
.section-lightmode {
background-color: #fff;
}
.data-darkmode {
background-color: #212121;
color: #fff;
}
.data-lightmode {
background-color: #EBEBEB;
color: #000;
}
.select-darkmode {
border: none;
color: white;
background: #212121;
padding: 0.4rem;
border-radius: 0.3125rem;
}
.select-lightmode {
border: none;
color: black;
background: #EBEBEB;
padding: 0.4rem;
border-radius: 0.3125rem;
}
.input {
border: none;
}
.data-table {
width: 100%;
padding: 0 0.625rem;
@ -209,6 +538,16 @@ th {
color: #000;
}
.template-checklist-information {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
padding: 1.25rem 1.875rem;
border-radius: 0.625rem;
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}
.Step {
width: 8%;
}
@ -247,6 +586,7 @@ th {
.Comments {
width: 35%;
display: flex;
}
.label {
@ -268,6 +608,29 @@ th {
color: #000;
}
.editPOTTodos-darkmode {
background: #2c2c2c;
color: #fff;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
padding: 0.825rem 0.7rem;
width: 4%;
border-radius: 0.625rem;
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}
.savePOTTodos-darkmode {
background: #212121;
color: #fff;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 10rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.saveNewPOT-darkmode {
background: #2c2c2c;
color: #fff;
@ -279,6 +642,73 @@ th {
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}
.deletePOTTodos-darkmode {
background: #212121;
color: #fff;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 15.8rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.deleteLastPOTTodos-darkmode {
background: #212121;
color: #fff;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 2rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.editPOTTodos-lightmode {
background: #EBEBEB;
color: #212121;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
margin-left: 15rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
border-radius: 0.625rem;
}
.savePOTTodos-lightmode {
background: #EBEBEB;
color: #212121;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 10rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.deletePOTTodos-lightmode {
background: #EBEBEB;
color: #212121;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 15.8rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.deleteLastPOTTodos-lightmode {
background: #EBEBEB;
color: #212121;
font: 400 0.875rem/1.875rem Overpass, sans-serif;
border: none;
border-radius: 0.625rem;
margin-left: 2rem;
padding-left: 0.9rem;
padding-right: 0.9rem;
}
.saveNewPOT-lightmode {
background: #EBEBEB;
color: #212121;
@ -290,11 +720,21 @@ th {
box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}
.deletePOTTodos-darkmode:hover,
.deleteLastPOTTodos-darkmode:hover,
.savePOTTodos-darkmode:hover,
.editPOTTodos-darkmode:hover,
.saveNewPOT-darkmode:hover {
background-color: #444444;
cursor: pointer;
}
.deletePOTTodos-lightmode:hover,
.deleteLastPOTTodos-lightmode:hover,
.savePOTTodos-lightmode:hover,
.editPOTTodos-lightmode:hover,
.saveNewPOT-lightmode:hover {
background-color: #ACACAC;
cursor: pointer;
@ -303,4 +743,8 @@ th {
#saveNewPOT {
text-align: center;
}
#editPOTTodos {
text-align: right;
}
</style>