mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:47:07 +00:00
Add extra mutations to plan Vuex module.
They're not actually needed though. 🙄
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user