This commit is contained in:
@@ -97,6 +97,8 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
import GzWoItemScheduledUsers from "../components/work-order-item-scheduled-users.vue";
|
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
|
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/
|
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
|
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
|
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: do we need a dirty indicator at every level??
|
||||||
|
todo: "delete selected item" text instead of "Delete" for subitems
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -312,7 +312,6 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
flagGraphItemForDelete: function(item) {
|
flagGraphItemForDelete: function(item) {
|
||||||
console.log(item);
|
|
||||||
switch (item.atype) {
|
switch (item.atype) {
|
||||||
case window.$gz.type.WorkOrderItem:
|
case window.$gz.type.WorkOrderItem:
|
||||||
this.deletedGraphItems.items.push(item.id);
|
this.deletedGraphItems.items.push(item.id);
|
||||||
@@ -408,16 +407,20 @@ export default {
|
|||||||
//clear any errors vm might be around from previous submit
|
//clear any errors vm might be around from previous submit
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
|
|
||||||
//###############################
|
//#######################################################
|
||||||
//walk the tree and save dirty
|
//walk the tree and save dirty
|
||||||
//items in order
|
//items in order
|
||||||
//individual save will throw on
|
//individual save will throw on
|
||||||
//exception short circuiting here
|
//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 fail = false;
|
||||||
let isNew = this.obj.concurrency == 0;
|
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
|
//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
|
//and user can unlock first to finish updating
|
||||||
let stateSaved = false;
|
let stateSaved = false;
|
||||||
@@ -426,17 +429,32 @@ export default {
|
|||||||
stateSaved = true;
|
stateSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//HEADER
|
//############# DELETE GRAPH ###############
|
||||||
|
//SCHEDULED USERS
|
||||||
if (!fail) {
|
if (!fail) {
|
||||||
fail = await saveItems(vm);
|
fail = await deleteScheduledUsers(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo: other children
|
||||||
|
|
||||||
//WOITEMS
|
//WOITEMS
|
||||||
|
if (!fail) {
|
||||||
|
fail = await deleteItems(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
//############ SAVE GRAPH ###############
|
||||||
|
//HEADER
|
||||||
if (!fail) {
|
if (!fail) {
|
||||||
fail = await saveHeader(vm);
|
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
|
//in case it locks or is completed
|
||||||
if (!stateSaved && !fail) {
|
if (!stateSaved && !fail) {
|
||||||
fail = await saveState(vm);
|
fail = await saveState(vm);
|
||||||
@@ -609,26 +627,25 @@ async function saveHeader(vm) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// ITEMS
|
// ITEMS
|
||||||
//
|
//
|
||||||
async function saveItems(vm) {
|
async function deleteItems(vm) {
|
||||||
let totalItems = vm.obj.items.length;
|
while (vm.deletedGraphItems.items.length) {
|
||||||
let totalDeletedItems = vm.deletedGraphItems.items.length;
|
|
||||||
if (totalItems == 0 && totalDeletedItems == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete
|
|
||||||
for (let i = 0; i < totalDeletedItems; i++) {
|
|
||||||
let res = await window.$gz.api.remove(
|
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) {
|
if (res.error) {
|
||||||
displayResError(vm, res);
|
displayResError(vm, res);
|
||||||
return false;
|
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++) {
|
for (let i = 0; i < totalItems; i++) {
|
||||||
let o = vm.obj.items[i];
|
let o = vm.obj.items[i];
|
||||||
// console.log("checking for save item: ", { item: o, index: i });
|
// console.log("checking for save item: ", { item: o, index: i });
|
||||||
@@ -668,20 +685,29 @@ async function saveItems(vm) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// SCHEDULED USERS
|
// 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) {
|
async function saveScheduledUsers(vm, woitemindex) {
|
||||||
// console.log("SaveSchedUsersProcessing for woitemindex:", woitemindex);
|
|
||||||
let totalItems = vm.obj.items[woitemindex].scheduledUsers.length;
|
let totalItems = vm.obj.items[woitemindex].scheduledUsers.length;
|
||||||
if (totalItems == 0) {
|
if (totalItems == 0) {
|
||||||
// console.log("saveschedusers no items to save bailing");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// console.log("saveschedusers processing this many items: ", totalItems);
|
|
||||||
for (let i = 0; i < totalItems; i++) {
|
for (let i = 0; i < totalItems; i++) {
|
||||||
let o = vm.obj.items[woitemindex].scheduledUsers[i];
|
let o = vm.obj.items[woitemindex].scheduledUsers[i];
|
||||||
// console.log("checking for save scheduseritem: ", { item: o, index: i });
|
|
||||||
if (o.isDirty) {
|
if (o.isDirty) {
|
||||||
let isPost = o.id == 0;
|
let isPost = o.id == 0;
|
||||||
// console.log("sched user Is dirty, saving now");
|
|
||||||
let res = await window.$gz.api.upsert(
|
let res = await window.$gz.api.upsert(
|
||||||
`${API_BASE_URL}items/scheduledusers`,
|
`${API_BASE_URL}items/scheduledusers`,
|
||||||
o
|
o
|
||||||
@@ -702,7 +728,6 @@ async function saveScheduledUsers(vm, woitemindex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// console.log("schedUserItem not dirty skipping save");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true; //made it
|
return true; //made it
|
||||||
|
|||||||
Reference in New Issue
Block a user