From 3613565b39590e0f59eea0a746876d10043881e3 Mon Sep 17 00:00:00 2001 From: "selina.mail" Date: Tue, 12 Mar 2024 20:36:26 +0100 Subject: [PATCH] added bools for actionbar rendering --- app.vue | 2 +- backend/models/solutionsModel.js | 4 +- components/AssetSearch.vue | 29 +- components/server/AssetSolutionList.vue | 73 +++- layouts/Actionbar.vue | 111 ++++-- plugins/vuex.js | 315 +++++++++++++----- .../api/getSelectedSolutionsByAsset/[id].ts | 23 ++ server/middleware/solutions.ts | 35 +- 8 files changed, 475 insertions(+), 117 deletions(-) create mode 100644 server/api/getSelectedSolutionsByAsset/[id].ts diff --git a/app.vue b/app.vue index 2dfae6a..1051332 100644 --- a/app.vue +++ b/app.vue @@ -19,7 +19,7 @@ useHead({ //title: `Tüit ERP - ${route.meta.title}`, - title: `Tüit ERP`, + title: `tüit app`, link: [{ rel: "icon", type: "image/png", href: "/favicon-gelb-rot-32x32.png" }] }) diff --git a/backend/models/solutionsModel.js b/backend/models/solutionsModel.js index f014466..d92317d 100644 --- a/backend/models/solutionsModel.js +++ b/backend/models/solutionsModel.js @@ -103,8 +103,8 @@ export const getSelectedSolutionsBySolutionName = async (selected, result) => { //get all selected solutions by asset name export const getSelectedSolutionsByAssetName = async (selected, result) => { try { - let sql = `SELECT * FROM solutions WHERE LOWER(assetName) LIKE '%${selected.toLowerCase()}%' ORDER BY assetName ASC`; - const results = await ownConn.execute(sql) + let sql = `SELECT * FROM solutions WHERE assetName = ? ORDER BY solutionName ASC`; + const results = await ownConn.execute(sql, [selected]) result(null, results); } catch (err) { diff --git a/components/AssetSearch.vue b/components/AssetSearch.vue index f7a909d..61ee3b8 100644 --- a/components/AssetSearch.vue +++ b/components/AssetSearch.vue @@ -1,15 +1,40 @@ - - + + + \ No newline at end of file +} + \ No newline at end of file diff --git a/plugins/vuex.js b/plugins/vuex.js index c1974df..6e42171 100644 --- a/plugins/vuex.js +++ b/plugins/vuex.js @@ -12,6 +12,19 @@ const store = createStore({ changedCustomerId: -1, filteredByCustomer: '', + addIcon: false, + addSolutionIcon: false, + solutionIcon: false, + addInstanceIcon: false, + filterIcon: false, + searchIcon: false, + instancesIcon: false, + attachmentsIcon: false, + sellIcon: false, + archiveIcon: false, + editIcon: false, + deleteIcon: false, + onAssetlist: true, onCustomerAssetlist: false, onAsset: false, @@ -150,92 +163,86 @@ const store = createStore({ state.changedCustomerId = id }, + refresh() { + // + }, + // functions to change the asset pages changeToAssetlist(state) { state.onAssetlist = true state.onCustomerAssetlist = false state.onAsset = false state.onSolutionlistAsset = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToCustomerAssetlist(state) { state.onAssetlist = false state.onCustomerAssetlist = true state.onAsset = false state.onSolutionlistAsset = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToAsset(state) { state.onAssetlist = false state.onCustomerAssetlist = false state.onAsset = true state.onSolutionlistAsset = false + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = true + state.addInstanceIcon = false + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = true + state.sellIcon = false + state.archiveIcon = false + state.editIcon = true + state.deleteIcon = true }, changeToSolutionlistAsset(state) { state.onAssetlist = false state.onCustomerAssetlist = false state.onAsset = false state.onSolutionlistAsset = true - }, - setChosenAsset(state, id) { - state.chosenAssetId = id - }, - resetAssetStore(state) { - state.editable = false - state.filtered = false - state.searchable = false - state.deleteAsset = false - state.chosenAssetId = -1 - state.filteredByCustomer = '' - state.newAssetName = '' - state.newCustomerID = '' - state.newCustomer = '' - state.newLocation = '' - state.newRemoteLocation = '' - state.newType = '' - state.newDescription = '' - state.newNotes = '' - state.newState = '' - state.newLastView = '' - state.newUser = '' - state.hardwareBool = false - state.newModel = '' - state.newSerialnumber = '' - state.newCPU = '' - state.newRAM = '' - state.newStorageConfiguration = '' - state.newMiscellaneous = '' - state.softwareBool = false - state.newSoftware = '' - state.newVersion = '' - state.newLicense = '' - }, - // functions to change the production order and maintenance visit pages - changeToTemplatelist(state) { - state.onTemplatelist = true - state.onCustomerTemplatelist = false - state.onTemplate = false - state.onInstancelist = false - state.onInstance = false - }, - changeToCustomerTemplatelist(state) { - state.onTemplatelist = false - state.onCustomerTemplatelist = true - state.onTemplate = false - state.onInstancelist = false - state.onInstance = false - }, - changeToTemplate(state) { - state.onTemplatelist = false - state.onCustomerTemplatelist = false - state.onTemplate = true - state.onInstancelist = false - state.onInstance = false - }, - changeToInstancelist(state) { - state.onTemplatelist = false - state.onCustomerTemplatelist = false - state.onTemplate = false - state.onInstancelist = true - state.onInstance = false + + state.addIcon = false + state.addSolutionIcon = true + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, // functions to change the production order and maintenance visit pages @@ -245,6 +252,19 @@ const store = createStore({ state.onTemplate = false state.onInstancelist = false state.onInstance = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToCustomerTemplatelist(state) { state.onTemplatelist = false @@ -252,6 +272,19 @@ const store = createStore({ state.onTemplate = false state.onInstancelist = false state.onInstance = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToTemplate(state) { state.onTemplatelist = false @@ -259,6 +292,19 @@ const store = createStore({ state.onTemplate = true state.onInstancelist = false state.onInstance = false + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = true + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = true + state.attachmentsIcon = true + state.sellIcon = false + state.archiveIcon = false + state.editIcon = true + state.deleteIcon = true }, changeToInstancelist(state) { state.onTemplatelist = false @@ -266,21 +312,19 @@ const store = createStore({ state.onTemplate = false state.onInstancelist = true state.onInstance = false - }, - doDeleteAsset(state) { - state.deleteAsset = true - }, - undoDeleteAsset(state) { - state.deleteAsset = false - }, - toggleAssetSearchable(state) { - if (state.searchable == false) { - state.searchable = true - state.filtered = false - } else { - state.searchable = false - } - state.filteredByCustomer = '' + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = true + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, addNewAsset(state) { state.newAsset = true @@ -298,16 +342,55 @@ const store = createStore({ state.onSolutionlist = true state.onCustomerSolutionlist = false state.onSolution = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToCustomerSolutionlist(state) { state.onSolutionlist = false state.onCustomerSolutionlist = true state.onSolution = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToSolution(state) { state.onSolutionlist = false state.onCustomerSolutionlist = false state.onSolution = true + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = true + state.sellIcon = false + state.archiveIcon = false + state.editIcon = true + state.deleteIcon = true }, // functions to change the issue slip pages @@ -315,16 +398,55 @@ const store = createStore({ state.onIssueSliplist = true state.onCustomerIssueSliplist = false state.onIssueSlip = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToCustomerIssueSliplist(state) { state.onIssueSliplist = false state.onCustomerIssueSliplist = true state.onIssueSlip = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToIssueSlip(state) { state.onIssueSliplist = false state.onCustomerIssueSliplist = false state.onIssueSlip = true + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = true + state.sellIcon = false + state.archiveIcon = false + state.editIcon = true + state.deleteIcon = true }, // functions to change the issue pages @@ -332,16 +454,55 @@ const store = createStore({ state.onIssueItemList = true state.onIssueItem = false state.onIssueItemVariant = false + + state.addIcon = true + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = false + state.editIcon = false + state.deleteIcon = false }, changeToIssueItem(state) { state.onIssueItemList = false state.onIssueItem = true state.onIssueItemVariant = false + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = true + state.searchIcon = true + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = false + state.archiveIcon = true + state.editIcon = true + state.deleteIcon = true }, changeToIssueItemVariant(state) { state.onIssueItemList = false state.onIssueItem = false state.onIssueItemVariant = true + + state.addIcon = false + state.addSolutionIcon = false + state.solutionIcon = false + state.addInstanceIcon = false + state.filterIcon = false + state.searchIcon = false + state.instancesIcon = false + state.attachmentsIcon = false + state.sellIcon = true + state.archiveIcon = true + state.editIcon = true + state.deleteIcon = true }, // functions to update the asset diff --git a/server/api/getSelectedSolutionsByAsset/[id].ts b/server/api/getSelectedSolutionsByAsset/[id].ts new file mode 100644 index 0000000..6643c7b --- /dev/null +++ b/server/api/getSelectedSolutionsByAsset/[id].ts @@ -0,0 +1,23 @@ +import { selectedSolutionsByAsset, errorMsg } from "../../middleware/solutions"; +import { OutgoingMessage } from 'http'; + +export default defineEventHandler(async (event) => { + + const headers: Record[1]> = { + 'Access-Control-Allow-Origin': 'https://tueitapp.tueit.de', + 'Access-Control-Allow-Headers': 'authorization, content-type', + 'Access-Control-Allow-Methods': 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE', + 'Access-Control-Allow-Credentials': 'true', + }; + setResponseHeaders(event, headers) + + if (!(errorMsg === '')) { + throw createError({ + statusCode: 400, + statusMessage: errorMsg, + }) + } + + setResponseStatus(event, 200) + return selectedSolutionsByAsset +}) diff --git a/server/middleware/solutions.ts b/server/middleware/solutions.ts index 6bc9d3c..8bbe46c 100644 --- a/server/middleware/solutions.ts +++ b/server/middleware/solutions.ts @@ -6,6 +6,7 @@ let solutions = []; let solution = {}; let selectedSolutionsByCustomer = []; let selectedSolutionsBySolution = []; +let selectedSolutionsByAsset = []; let solTodosBySolutionId = []; let insertId = -1; let errorMsg = ''; @@ -84,6 +85,38 @@ export default defineEventHandler(async (event) => { } } + if (event.path.startsWith("/api/getSelectedSolutionsByAsset")) { + // get selected solutions object by asset from backend + let filteredAsset = null; + const path = event._path; + const pathSegments = path.split('/'); + filteredAsset = pathSegments[pathSegments.length - 1]; + + try { + let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/selectedSolutionsByAssetName/${filteredAsset}`); + selectedSolutionsByAsset = res.data; + } catch (err) { + if (axios.isAxiosError(err)) { + const axiosError = err as AxiosError; + + if (axiosError.response) { + // Axios error + console.error(axiosError.response.data.message); + errorMsg = axiosError.response.data.message; + } else if (axiosError.request) { + // If error was caused by the request + console.error(axiosError.request); + } else { + // Other errors + console.error('Error', axiosError.message); + } + } else { + // No AxiosError + console.error('Error', err); + } + } + } + if (event.path.startsWith("/api/getSelectedSolutionsBySolution")) { // get selected solutions object by asset from backend let filteredSolution = null; @@ -391,4 +424,4 @@ export default defineEventHandler(async (event) => { }) -export { solutions, solution, selectedSolutionsByCustomer, selectedSolutionsBySolution, solTodosBySolutionId, insertId, errorMsg }; \ No newline at end of file +export { solutions, solution, selectedSolutionsByAsset, selectedSolutionsByCustomer, selectedSolutionsBySolution, solTodosBySolutionId, insertId, errorMsg }; \ No newline at end of file