From c0722be846127abfe8c0665398b84288cc4eb4bc Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 12 Apr 2021 22:53:39 +0000 Subject: [PATCH] --- ayanova/src/views/svc-workorder.vue | 47 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/ayanova/src/views/svc-workorder.vue b/ayanova/src/views/svc-workorder.vue index 39427928..0837b31f 100644 --- a/ayanova/src/views/svc-workorder.vue +++ b/ayanova/src/views/svc-workorder.vue @@ -149,7 +149,7 @@ export default { longitude: null, items: [], states: [], - isDirty: false, + isDirty: true, isLockedAtServer: false }, formState: { @@ -613,11 +613,14 @@ async function saveHeader(vm) { if (!vm.obj.isDirty) { return true; } - let isPost = vm.obj.id == 0; - const clone = { items: undefined, states: undefined, ...vm.obj }; + const isPost = vm.obj.id == 0; - console.log("CLONING RESULT:", { obj: vm.obj, clone: clone }); - let res = await window.$gz.api.upsert(`${API_BASE_URL}`, vm.obj); + //the purpose of this is to remove the child collections so only the header itself is submitted + //this was the cleanest way I could find to accomplish this + //https://stackoverflow.com/a/58206483/8939 + const { items: removedKey1, states: removedKey2, ...headerOnly } = vm.obj; + + let res = await window.$gz.api.upsert(`${API_BASE_URL}`, headerOnly); if (res.error) { displayResError(vm, res); return false; @@ -687,11 +690,23 @@ async function saveItems(vm) { } for (let i = 0; i < totalItems; i++) { - let o = vm.obj.items[i]; - // console.log("checking for save item: ", { item: o, index: i }); + // let o = vm.obj.items[i]; + //get item only without children + const { + expenses: removedKey1, + labors: removedKey2, + loans: removedKey3, + parts: removedKey4, + partRequests: removedKey5, + scheduledUsers: removedKey6, + tasks: removedKey7, + travels: removedKey8, + units: removedKey9, + outsideServices: removedKey10, + ...o + } = vm.obj.items[i]; if (o.isDirty) { - // console.log("Is dirty, saving now for ", i); - let isPost = o.id == 0; + const isPost = o.id == 0; let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o); if (res.error) { displayResError(vm, res); @@ -699,15 +714,17 @@ async function saveItems(vm) { } else { //update any server changed fields //put fields - o.concurrency = res.data.concurrency; - o.isDirty = false; + vm.obj.items[i].concurrency = res.data.concurrency; + vm.obj.items[i].isDirty = false; //fields to update if post if (isPost) { - o.id = res.data.id; - o.workorderId = res.data.workorderId; + vm.obj.items[i].id = res.data.id; + vm.obj.items[i].workorderId = res.data.workorderId; //walk all unsaved children and set the workorder id so they can save - o.scheduledUsers.forEach(z => (z.workorderItemId = o.id)); + vm.obj.items[i].scheduledUsers.forEach( + z => (z.workorderItemId = vm.obj.items[i].id) + ); //todo: other grandchildren } } @@ -753,7 +770,7 @@ async function saveScheduledUsers(vm, woitemindex) { for (let i = 0; i < totalItems; i++) { let o = vm.obj.items[woitemindex].scheduledUsers[i]; if (o.isDirty) { - let isPost = o.id == 0; + const isPost = o.id == 0; let res = await window.$gz.api.upsert( `${API_BASE_URL}items/scheduledusers`, o