This commit is contained in:
@@ -149,7 +149,7 @@ export default {
|
|||||||
longitude: null,
|
longitude: null,
|
||||||
items: [],
|
items: [],
|
||||||
states: [],
|
states: [],
|
||||||
isDirty: false,
|
isDirty: true,
|
||||||
isLockedAtServer: false
|
isLockedAtServer: false
|
||||||
},
|
},
|
||||||
formState: {
|
formState: {
|
||||||
@@ -613,11 +613,14 @@ async function saveHeader(vm) {
|
|||||||
if (!vm.obj.isDirty) {
|
if (!vm.obj.isDirty) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let isPost = vm.obj.id == 0;
|
const isPost = vm.obj.id == 0;
|
||||||
const clone = { items: undefined, states: undefined, ...vm.obj };
|
|
||||||
|
|
||||||
console.log("CLONING RESULT:", { obj: vm.obj, clone: clone });
|
//the purpose of this is to remove the child collections so only the header itself is submitted
|
||||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}`, vm.obj);
|
//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) {
|
if (res.error) {
|
||||||
displayResError(vm, res);
|
displayResError(vm, res);
|
||||||
return false;
|
return false;
|
||||||
@@ -687,11 +690,23 @@ async function saveItems(vm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 });
|
//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) {
|
if (o.isDirty) {
|
||||||
// console.log("Is dirty, saving now for ", i);
|
const isPost = o.id == 0;
|
||||||
let isPost = o.id == 0;
|
|
||||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
displayResError(vm, res);
|
displayResError(vm, res);
|
||||||
@@ -699,15 +714,17 @@ async function saveItems(vm) {
|
|||||||
} else {
|
} else {
|
||||||
//update any server changed fields
|
//update any server changed fields
|
||||||
//put fields
|
//put fields
|
||||||
o.concurrency = res.data.concurrency;
|
vm.obj.items[i].concurrency = res.data.concurrency;
|
||||||
o.isDirty = false;
|
vm.obj.items[i].isDirty = false;
|
||||||
|
|
||||||
//fields to update if post
|
//fields to update if post
|
||||||
if (isPost) {
|
if (isPost) {
|
||||||
o.id = res.data.id;
|
vm.obj.items[i].id = res.data.id;
|
||||||
o.workorderId = res.data.workorderId;
|
vm.obj.items[i].workorderId = res.data.workorderId;
|
||||||
//walk all unsaved children and set the workorder id so they can save
|
//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
|
//todo: other grandchildren
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -753,7 +770,7 @@ async function saveScheduledUsers(vm, woitemindex) {
|
|||||||
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];
|
||||||
if (o.isDirty) {
|
if (o.isDirty) {
|
||||||
let isPost = o.id == 0;
|
const isPost = o.id == 0;
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user