implemented mvt and solutions

This commit is contained in:
2024-03-04 10:24:55 +01:00
parent 1e001bb4a1
commit 488eba45e1
57 changed files with 3389 additions and 1125 deletions

View File

@ -1,15 +1,96 @@
<template>
<section :class="['information', darkMode ? 'section-darkmode' : 'section-lightmode']">
<h2 :class="['solution-name', darkMode ? 'h2-darkmode' : 'h2-lightmode']">Solution name</h2>
<section v-if="!addBool" :class="['information', darkMode ? 'section-darkmode' : 'section-lightmode']">
<h2 v-if="!editable" :class="['solution-name', darkMode ? 'h2-darkmode' : 'h2-lightmode']">{{ sol.solutionName
}}</h2>
<input v-if="editable" v-model="sol.solutionName" @change="updateSolution()"
:class="['data', 'solution-name-input', darkMode ? 'h2-darkmode' : 'h2-lightmode', darkMode ? 'h2-input-darkmode' : 'h2-input-lightmode', 'input']">
<div class="solution-data">
<div class="client-asset">
<div class="data-field" id="client">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Client:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">...</pre>
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Customer:</pre>
<pre v-if="!editable"
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ sol.customer }}</pre>
<select v-if="editable" id="customersDropDownChosenCI" v-model="sol.customer"
@change="updateCustomerID()" :class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="cust in customers" :key="cust.primaryID">
{{ cust.customername }}
</option>
</select>
</div>
<div class="data-field" id="asset">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Asset:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">...</pre>
<pre v-if="!editable"
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ sol.assetName }}</pre>
<select v-if="editable" id="customersDropDownChosenCI" v-model="sol.assetName"
@change="updateSolution()" :class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="ci in configItems" :key="ci.primaryID">
{{ ci.assetName }}
</option>
</select>
</div>
</div>
<div class="info">
<div class="data-field" id="user">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">User:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ sol.user }}</pre>
</div>
<div class="type-id">
<div class="data-field" id="type">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Type:</pre>
<pre v-if="!editable"
:class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ sol.type }}</pre>
<input v-if="editable" v-model="sol.type" @change="updateSolution()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</div>
<div class="data-field" id="id">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">ID:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ sol.primaryID }}</pre>
</div>
</div>
</div>
</div>
<div class="solution-data">
<div class="additional">
<div class="description">
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Description of the
problem/intended use:</h3>
<input v-model="sol.description" :readonly="!editable" @change="updateSolution()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="description">
</div>
</div>
</div>
<div class="solution-data">
<div class="additional">
<div class="notes">
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Notes:</h3>
<input v-model="sol.notes" :readonly="!editable" @change="updateSolution()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="notes">
</div>
</div>
</div>
</section>
<section v-if="addBool" :class="['information', darkMode ? 'section-darkmode' : 'section-lightmode']">
<input v-model="newSolutionName" @change="updateSol()"
:class="['data', 'solution-name-input', darkMode ? 'h2-darkmode' : 'h2-lightmode', darkMode ? 'h2-input-darkmode' : 'h2-input-lightmode', 'input']">
<div class="solution-data">
<div class="client-asset">
<div class="data-field" id="client">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Customer:</pre>
<select id="customersDropDownChosenCI" v-model="newCustomer" @change="updateNewCustomerID()"
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="cust in customers" :key="cust.primaryID">
{{ cust.customername }}
</option>
</select>
</div>
<div class="data-field" id="asset">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Asset:</pre>
<select id="customersDropDownChosenCI" v-model="newAssetName" @change="updateSol()"
:class="[darkMode ? 'select-darkmode' : 'select-lightmode']">
<option v-for="ci in configItems" :key="ci.primaryID">
{{ ci.assetName }}
</option>
</select>
</div>
</div>
<div class="info">
@ -17,13 +98,14 @@
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">User:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">...</pre>
</div>
<div class="type-state">
<div class="type-id">
<div class="data-field" id="type">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">Type:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">...</pre>
<input v-model="newType" @change="updateSol()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
</div>
<div class="data-field" id="state">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">State:</pre>
<div class="data-field" id="id">
<pre :class="['label', darkMode ? 'pre-darkmode' : 'pre-lightmode']">ID:</pre>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">...</pre>
</div>
</div>
@ -34,7 +116,8 @@
<div class="description">
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Description of the
problem/intended use:</h3>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']" id="description">...</pre>
<input v-model="newDescription" @change="updateSol()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="description">
</div>
</div>
</div>
@ -42,27 +125,235 @@
<div class="additional">
<div class="notes">
<h3 :class="['area-title', darkMode ? 'h3-darkmode' : 'h3-lightmode']">Notes:</h3>
<pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']" id="notes">...</pre>
<input v-model="newNotes" @change="updateSol()"
:class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']" id="notes">
</div>
</div>
</div>
</section>
</template>
<script setup>
import { ref } from 'vue';
const darkMode = ref(true)
<script setup>
import { ref, onMounted, watch } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../../clientsideConfig.js';
import { useStore } from 'vuex';
import { computed } from 'vue';
const store = useStore();
const editable = computed(() => store.state.editable);
const chosenSolutionId = computed(() => store.state.chosenSolutionId);
const deleteBool = computed(() => store.state.deleteBool);
const addBool = computed(() => store.state.new);
const darkMode = ref(true);
const sol = ref({});
const customer = ref({});
const solutions = ref([]);
const customers = ref([]);
const configItems = ref([]);
const newAssetName = ref('');
const newCustomerID = ref('');
const newCustomer = ref('');
const newSolutionName = ref('');
const newType = ref('');
const newDescription = ref('');
const newNotes = ref('');
const newLastView = ref('');
const newUser = ref('');
const changedClientId = computed(() => store.state.changedClientId);
const clientChanged = computed(() => store.state.clientChanged);
// get solution from id
const getSolutionById = async () => {
if (!addBool.value) {
try {
const response = await Axios.get(
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getSolution/${chosenSolutionId.value}`
);
sol.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
await getConfigItemsFromClient();
}
//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/${sol.value.customerID}`);
configItems.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}`);
configItems.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
if (clientChanged.value) {
store.commit('toggleClientChanged');
}
}
// update solution fields in the store
const updateSol = () => {
const solution = {
solutionName: newSolutionName.value,
customerId: newCustomerID.value,
customer: newCustomer.value,
assetName: newAssetName.value,
lastView: newLastView.value,
type: newType.value,
description: newDescription.value,
notes: newNotes.value,
user: newUser.value
};
store.commit('updateSolutionComponent', solution);
}
//update data
const updateSolution = async () => {
if (sol.value.solutionName.trim() === "") {
alert("Please add a solution name!");
return;
} else {
var counter = 0;
// check if solution name already exists
solutions.value.forEach(s => {
if (s.solutionName === sol.value.solutionName) {
counter += 1;
}
});
if (counter == 1) {
alert("This solution name already exists. Please choose an unique solution name or modify respectively delete the old one!");
sol.value.solutionName = '';
return;
}
try {
await Axios.put(
`https://${clientsideConfig.url}:${clientsideConfig.port}/api/updateSolution`,
{
primaryID: sol.value.primaryID,
solutionName: sol.value.solutionName,
customerID: sol.value.customerID,
customer: sol.value.customer,
assetName: sol.value.assetName,
type: sol.value.type,
description: sol.value.description,
notes: sol.value.notes,
lastView: sol.value.lastView,
user: sol.value.user,
}
)
await getSolutionById();
} catch (err) {
console.log(err.response.statusText);
}
}
}
//get all customers
const getCustomers = async () => {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getAllCustomers`
);
customers.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
const confirmDeleteSolution = async () => {
if (deleteBool.value === true) {
if (confirm("Do you really want to delete this solution? It cannot be undone!")) {
try {
await Axios.delete(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/deleteSolution/${chosenSolutionId.value}`);
store.commit('undoDelete');
store.commit('changeToSolutionlist');
} catch (err) {
console.log(err.response.statusText);
}
try {
await Axios.delete(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/deleteTodosSolution/${chosenSolutionId.value}`);
} catch (err) {
console.log(err.response.statusText);
}
} else {
store.commit('undoDelete');
}
}
}
//get all solutions
const getSolutions = async () => {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getAllSolutions`);
solutions.value = response.data;
} catch (err) {
console.log(err.response.statusText);
}
}
// update customerid if customer was changed
const updateCustomerID = async () => {
try {
const response = await Axios.get(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/getCustomerByName/${sol.value.customer}`);
customer.value = response.data;
sol.value.customerID = customer.value.customerID;
store.commit('toggleClientChanged');
store.commit('toggleClientId', sol.value.customerID);
} catch (err) {
console.log(err.response.statusText);
}
await updateSolution();
}
// update customerid if customer was changed
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);
}
updateSol();
await getConfigItemsFromClient();
}
// include delay to avoid 503 error
const triggerBackendCallsWithDelay = async (fetchDataFunc) => {
setTimeout(() => {
fetchDataFunc();
}, 1500);
}
watch(deleteBool, confirmDeleteSolution);
watch(clientChanged, getSolutionById);
onMounted(() => {
getSolutionById();
getSolutions();
triggerBackendCallsWithDelay(getCustomers);
});
</script>
<script>
export default {
name: "Solution",
};
</script>
</script>
<style scoped>
.information {
display: flex;
@ -83,7 +374,15 @@ export default {
background-color: #fff;
}
.solution-name-input {
padding: 1rem 0;
margin: 1rem;
font-size: initial;
letter-spacing: 5%;
text-decoration-line: underline;
font: italic 400 1rem/187.5% Overpass, -apple-system, Roboto, Helvetica,
sans-serif;
}
.solution-name {
align-self: stretch;
@ -102,17 +401,41 @@ export default {
color: #000;
}
.h2-input-darkmode {
background-color: #212121;
}
.h2-input-lightmode {
background-color: #EBEBEB;
}
.data-field {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
width: 100%;
padding: 0 1.875rem;
padding: 0.8rem 1.875rem;
gap: 1.25rem;
border-radius: 0.625rem;
}
.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;
}
.data-field#street-name {
width: 70%;
}
@ -175,6 +498,10 @@ export default {
border-radius: 0.3125rem;
}
.input {
border: none;
}
.additional {
display: flex;
flex-direction: column;
@ -199,7 +526,7 @@ export default {
color: #000;
}
.type-state {
.type-id {
display: flex;
flex-direction: row;
align-items: center;