From 0263eab6d1e6347454714bbce87adaad27fb5867 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 6 Aug 2025 11:03:11 +0200 Subject: [PATCH] Add extra mutations to `plan` Vuex module. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They're not actually needed though. 🙄 --- .../src/store/modules/plan/mutations.js | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/www/client/source/src/store/modules/plan/mutations.js b/lib/www/client/source/src/store/modules/plan/mutations.js index 96bf205..f1c9637 100644 --- a/lib/www/client/source/src/store/modules/plan/mutations.js +++ b/lib/www/client/source/src/store/modules/plan/mutations.js @@ -1,18 +1,47 @@ function transform (item) { - item.ts0 = new Date(item.ts0); - item.ts1 = new Date(item.ts1); - return item; + const newItem = {...item} + newItem.ts0 = new Date(newItem.ts0); + newItem.ts1 = new Date(newItem.ts1); + return newItem; } // ATTENTION: This relies on the new planner endpoint // as per issue #281. +function setRemarks (state, remarks) { + state.remarks = remarks; +} + +function setSequence (state, sequence) { + state.sequences.push(Object.freeze(transform(sequence))); +} + +function deleteSequence (state, sequence) { + const seq = transform(sequence) + const idx = state.sequences?.findIndex( s => Object.keys(seq).every( k => JSON.stringify(s[k]) == JSON.stringify(seq[k]) )); + if (idx != -1) { + state.sequences.splice(idx, 1) + } +} + +function replaceSequence (state, [oldSequence, newSequence]) { + console.log("replaceSequence", oldSequence, newSequence); + const seq = transform(oldSequence) + const idx = state.sequences?.findIndex( s => Object.keys(seq).every( k => JSON.stringify(s[k]) == JSON.stringify(seq[k]) )); + console.log("idx", idx); + if (idx != -1) { + state.sequences.splice(idx, 1, transform(newSequence)) + console.log("spliced in"); + } +} + function setPlan (state, plan) { // We don't need or want the planned sequences array to be reactive - state.sequences = Object.freeze(plan.sequences.map(transform)); - state.remarks = plan.remarks; + state.sequences = []; + plan.sequences.forEach( sequence => setSequence(state, sequence) ); + setRemarks(state, plan.remarks); } function setPlanLoading (state, abortController = new AbortController()) { @@ -51,6 +80,10 @@ function abortPlanLoading (state) { } export default { + setRemarks, + setSequence, + deleteSequence, + replaceSequence, setPlan, setPlanLoading, clearPlanLoading,