This commit is contained in:
@@ -97,6 +97,8 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
import GzWoItemScheduledUsers from "../components/work-order-item-scheduled-users.vue";
|
||||
/*
|
||||
|
||||
todo: delete at shell must walk graph backwards where save would be forwards so delete break out into separate methods called first
|
||||
todo: stop using parent vm directly to control state in graph and instead pass down values via props to children and pass up values to parent via events
|
||||
https://www.smashingmagazine.com/2020/01/data-components-vue-js/
|
||||
|
||||
@@ -113,6 +115,7 @@ import GzWoItemScheduledUsers from "../components/work-order-item-scheduled-user
|
||||
todo: failed saved on a grandchild item shouldn't preclude the rest saving
|
||||
e.g. if there is a concurrency error on a child that shouldn't block the rest but a fatal error probably should
|
||||
todo: do we need a dirty indicator at every level??
|
||||
todo: "delete selected item" text instead of "Delete" for subitems
|
||||
*/
|
||||
export default {
|
||||
components: {
|
||||
|
||||
@@ -312,7 +312,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
flagGraphItemForDelete: function(item) {
|
||||
console.log(item);
|
||||
switch (item.atype) {
|
||||
case window.$gz.type.WorkOrderItem:
|
||||
this.deletedGraphItems.items.push(item.id);
|
||||
@@ -408,16 +407,20 @@ export default {
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
//###############################
|
||||
//#######################################################
|
||||
//walk the tree and save dirty
|
||||
//items in order
|
||||
//individual save will throw on
|
||||
//exception short circuiting here
|
||||
//###############################
|
||||
//Delete flagged items first upwards from bottom of graph
|
||||
//one by one individually
|
||||
//then save all items downwards from top of graph
|
||||
//mostly via workorderitem
|
||||
//########################################################
|
||||
let fail = false;
|
||||
let isNew = this.obj.concurrency == 0;
|
||||
|
||||
//STATE first if unlocking only
|
||||
//### STATE first if unlocking only
|
||||
//if moving to another locked state this will block further updates below but we're accepting that
|
||||
//and user can unlock first to finish updating
|
||||
let stateSaved = false;
|
||||
@@ -426,17 +429,32 @@ export default {
|
||||
stateSaved = true;
|
||||
}
|
||||
|
||||
//HEADER
|
||||
//############# DELETE GRAPH ###############
|
||||
//SCHEDULED USERS
|
||||
if (!fail) {
|
||||
fail = await saveItems(vm);
|
||||
fail = await deleteScheduledUsers(vm);
|
||||
}
|
||||
|
||||
//todo: other children
|
||||
|
||||
//WOITEMS
|
||||
if (!fail) {
|
||||
fail = await deleteItems(vm);
|
||||
}
|
||||
|
||||
//############ SAVE GRAPH ###############
|
||||
//HEADER
|
||||
if (!fail) {
|
||||
fail = await saveHeader(vm);
|
||||
}
|
||||
|
||||
//STATE last normally
|
||||
//WOITEMS
|
||||
if (!fail) {
|
||||
//This saves all bottom level collections as well
|
||||
fail = await saveItems(vm);
|
||||
}
|
||||
|
||||
//### STATE last normally
|
||||
//in case it locks or is completed
|
||||
if (!stateSaved && !fail) {
|
||||
fail = await saveState(vm);
|
||||
@@ -609,26 +627,25 @@ async function saveHeader(vm) {
|
||||
/////////////////////////////
|
||||
// ITEMS
|
||||
//
|
||||
async function saveItems(vm) {
|
||||
let totalItems = vm.obj.items.length;
|
||||
let totalDeletedItems = vm.deletedGraphItems.items.length;
|
||||
if (totalItems == 0 && totalDeletedItems == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//delete
|
||||
for (let i = 0; i < totalDeletedItems; i++) {
|
||||
async function deleteItems(vm) {
|
||||
while (vm.deletedGraphItems.items.length) {
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/${vm.deletedGraphItems.items[i]}`
|
||||
`${API_BASE_URL}items/${vm.deletedGraphItems.items[0]}`
|
||||
);
|
||||
if (res.error) {
|
||||
displayResError(vm, res);
|
||||
return false;
|
||||
} else {
|
||||
vm.deletedGraphItems.items.splice(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function saveItems(vm) {
|
||||
let totalItems = vm.obj.items.length;
|
||||
if (totalItems == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//upsert
|
||||
// console.log("saveItems processing this many items: ", totalItems);
|
||||
for (let i = 0; i < totalItems; i++) {
|
||||
let o = vm.obj.items[i];
|
||||
// console.log("checking for save item: ", { item: o, index: i });
|
||||
@@ -668,20 +685,29 @@ async function saveItems(vm) {
|
||||
/////////////////////////////
|
||||
// SCHEDULED USERS
|
||||
//
|
||||
async function deleteScheduledUsers(vm) {
|
||||
while (vm.deletedGraphItems.scheduledUsers.length) {
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/scheduledusers/${vm.deletedGraphItems.scheduledUsers[0]}`
|
||||
);
|
||||
if (res.error) {
|
||||
displayResError(vm, res);
|
||||
return false;
|
||||
} else {
|
||||
vm.deletedGraphItems.scheduledUsers.splice(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function saveScheduledUsers(vm, woitemindex) {
|
||||
// console.log("SaveSchedUsersProcessing for woitemindex:", woitemindex);
|
||||
let totalItems = vm.obj.items[woitemindex].scheduledUsers.length;
|
||||
if (totalItems == 0) {
|
||||
// console.log("saveschedusers no items to save bailing");
|
||||
return true;
|
||||
}
|
||||
// console.log("saveschedusers processing this many items: ", totalItems);
|
||||
for (let i = 0; i < totalItems; i++) {
|
||||
let o = vm.obj.items[woitemindex].scheduledUsers[i];
|
||||
// console.log("checking for save scheduseritem: ", { item: o, index: i });
|
||||
if (o.isDirty) {
|
||||
let isPost = o.id == 0;
|
||||
// console.log("sched user Is dirty, saving now");
|
||||
let res = await window.$gz.api.upsert(
|
||||
`${API_BASE_URL}items/scheduledusers`,
|
||||
o
|
||||
@@ -702,7 +728,6 @@ async function saveScheduledUsers(vm, woitemindex) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// console.log("schedUserItem not dirty skipping save");
|
||||
}
|
||||
}
|
||||
return true; //made it
|
||||
|
||||
Reference in New Issue
Block a user