This commit is contained in:
2021-04-08 14:58:59 +00:00
parent f72b6b3c30
commit 461d3cd375
2 changed files with 101 additions and 10 deletions

View File

@@ -212,7 +212,8 @@ todo: many biz objects are not using new PUT methodology
CURRENTLY DOING: add delete button, add Add() methods for item and scheduser then is ready to test full graph partial updating system
CURRENTLY DOING: add save methods in shell graph save for item and scheduser
- test full graph partial updating system
- confirm Create, Retrieve, Update, Delete works completely
- try to start with a new workorder if possible
- make minimal front end enough for POC wokorder->

View File

@@ -453,24 +453,30 @@ export default {
//exception short circuiting here
//###############################
let fail = false;
let isNew = this.obj.concurrency == 0;
//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;
if (this.obj.isLockedAtServer) {
console.log("savestateFirst");
fail = await saveState(vm);
stateSaved = true;
}
//WOITEMS
//HEADER
if (!fail) {
fail = await saveItems(vm);
}
//STATE last normally in case it locks
//or is completed
if (!stateSaved && !fail && !this.obj.isLockedAtServer) {
//WOITEMS
if (!fail) {
fail = await saveHeader(vm);
}
//STATE last normally
//in case it locks or is completed
if (!stateSaved && !fail) {
fail = await saveState(vm);
}
@@ -614,6 +620,84 @@ export default {
//########################################## SAVE METHODS ##############################################
/////////////////////////////
// HEADER
//
async function saveHeader(vm) {
if (!vm.obj.isDirty) {
return;
}
let res = await window.$gz.api.upsert(`${API_BASE_URL}`, o);
if (res.error) {
displayResError(vm, res);
return false;
} else {
//update any server changed fields
vm.obj.concurrency = res.concurrency;
vm.obj.id = res.id;
vm.obj.serial = res.serial;
vm.obj.isDirty = false;
}
}
/////////////////////////////
// ITEMS
//
async function saveItems(vm) {
let totalItems = vm.obj.items.length;
if (totalItems == 0) {
return;
}
for (let i = 0; i < totalItems; i++) {
let o = vm.obj.items[i];
if (o.isDirty) {
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
if (res.error) {
displayResError(vm, res);
return false;
} else {
//update any server changed fields
o.concurrency = res.concurrency;
o.id = res.id;
o.workorderId = res.workorderId;
o.isDirty = false;
}
}
//------
//save grandchildren
if (!(await saveScheduledUsers(vm, o.id))) {
return false;
}
//------
}
}
/////////////////////////////
// SCHEDULED USERS
//
async function saveScheduledUsers(vm, woitemid) {
let totalItems = vm.obj.items[woitemid].scheduledUsers.length;
if (totalItems == 0) {
return;
}
for (let i = 0; i < totalItems; i++) {
let o = vm.obj.items[woitemid].scheduledUsers[i];
if (o.isDirty) {
let res = await window.$gz.api.upsert(`${API_BASE_URL}scheduledusers`, o);
if (res.error) {
displayResError(vm, res);
return false;
} else {
//update any server changed fields
o.concurrency = res.concurrency;
o.id = res.id;
o.workOrderItemId = res.workOrderItemId;
o.isDirty = false;
}
}
}
}
/////////////////////////////
// STATES
//
@@ -628,10 +712,8 @@ async function saveState(vm) {
if (o.concurrency == null) {
//it's new so save it
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
displayResError(vm, res);
return false;
} else {
vm.obj.states[i] = res.data;
@@ -642,6 +724,14 @@ async function saveState(vm) {
}
}
/////////////////////////////
// Error display
//
function displayResError(vm, res) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
}
//######################################### UTILITY METHODS ###########################################
/////////////////////////////
//