This commit is contained in:
@@ -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
|
- confirm Create, Retrieve, Update, Delete works completely
|
||||||
- try to start with a new workorder if possible
|
- try to start with a new workorder if possible
|
||||||
- make minimal front end enough for POC wokorder->
|
- make minimal front end enough for POC wokorder->
|
||||||
|
|||||||
@@ -453,24 +453,30 @@ export default {
|
|||||||
//exception short circuiting here
|
//exception short circuiting here
|
||||||
//###############################
|
//###############################
|
||||||
let fail = false;
|
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
|
//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;
|
||||||
if (this.obj.isLockedAtServer) {
|
if (this.obj.isLockedAtServer) {
|
||||||
console.log("savestateFirst");
|
|
||||||
fail = await saveState(vm);
|
fail = await saveState(vm);
|
||||||
stateSaved = true;
|
stateSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WOITEMS
|
|
||||||
|
|
||||||
//HEADER
|
//HEADER
|
||||||
|
if (!fail) {
|
||||||
|
fail = await saveItems(vm);
|
||||||
|
}
|
||||||
|
|
||||||
//STATE last normally in case it locks
|
//WOITEMS
|
||||||
//or is completed
|
if (!fail) {
|
||||||
if (!stateSaved && !fail && !this.obj.isLockedAtServer) {
|
fail = await saveHeader(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
//STATE last normally
|
||||||
|
//in case it locks or is completed
|
||||||
|
if (!stateSaved && !fail) {
|
||||||
fail = await saveState(vm);
|
fail = await saveState(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,6 +620,84 @@ export default {
|
|||||||
|
|
||||||
//########################################## SAVE METHODS ##############################################
|
//########################################## 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
|
// STATES
|
||||||
//
|
//
|
||||||
@@ -628,10 +712,8 @@ async function saveState(vm) {
|
|||||||
if (o.concurrency == null) {
|
if (o.concurrency == null) {
|
||||||
//it's new so save it
|
//it's new so save it
|
||||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
|
||||||
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
vm.formState.serverError = res.error;
|
displayResError(vm, res);
|
||||||
window.$gz.form.setErrorBoxErrors(vm);
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
vm.obj.states[i] = res.data;
|
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 ###########################################
|
//######################################### UTILITY METHODS ###########################################
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user