This commit is contained in:
@@ -355,11 +355,40 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addTaskGroup() {
|
async addTaskGroup() {
|
||||||
//add the tasks in the task group ID specified
|
//add the tasks in the task group ID specified
|
||||||
//verify the id is real
|
//verify the id is real
|
||||||
console.log("Selected taskgroupid", this.selectedTaskGroup);
|
//console.log("Selected taskgroupid", this.selectedTaskGroup);
|
||||||
//fetch it from the server
|
//fetch it from the server
|
||||||
|
let res = await window.$gz.api.get(
|
||||||
|
`task-group/${this.selectedTaskGroup}`
|
||||||
|
);
|
||||||
|
if (res.data && res.data.items) {
|
||||||
|
let newIndex = this.value.items[this.activeWoItemIndex].tasks.length;
|
||||||
|
let incompleteViz = this.pvm.selectLists.woItemTaskCompletionTypes.find(
|
||||||
|
s => s.id == 1 //incomplete
|
||||||
|
).name;
|
||||||
|
res.data.items.forEach(z => {
|
||||||
|
newIndex++;
|
||||||
|
|
||||||
|
this.value.items[this.activeWoItemIndex].tasks.push({
|
||||||
|
id: 0,
|
||||||
|
concurrency: 0,
|
||||||
|
sequence: newIndex,
|
||||||
|
task: z.task,
|
||||||
|
status: 1, //incomplete==1
|
||||||
|
statusViz: incompleteViz,
|
||||||
|
completedByUserId: null,
|
||||||
|
completedDate: null,
|
||||||
|
isDirty: true,
|
||||||
|
workOrderItemId: this.value.items[this.activeWoItemIndex].id,
|
||||||
|
uid: Date.now() //used for error tracking / display
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.$emit("change");
|
||||||
|
this.selectedRow = [{ index: newIndex }];
|
||||||
|
this.activeItemIndex = newIndex;
|
||||||
|
}
|
||||||
//iterate and append to the current task list
|
//iterate and append to the current task list
|
||||||
//flag dirty if necessary
|
//flag dirty if necessary
|
||||||
this.taskGroupDialog = false;
|
this.taskGroupDialog = false;
|
||||||
|
|||||||
@@ -788,6 +788,10 @@ async function saveItems(vm) {
|
|||||||
z => (z.workorderItemId = vm.obj.items[i].id)
|
z => (z.workorderItemId = vm.obj.items[i].id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
vm.obj.items[i].tasks.forEach(
|
||||||
|
z => (z.workorderItemId = vm.obj.items[i].id)
|
||||||
|
);
|
||||||
|
|
||||||
vm.obj.items[i].labors.forEach(
|
vm.obj.items[i].labors.forEach(
|
||||||
z => (z.workorderItemId = vm.obj.items[i].id)
|
z => (z.workorderItemId = vm.obj.items[i].id)
|
||||||
);
|
);
|
||||||
@@ -810,6 +814,9 @@ async function saveItems(vm) {
|
|||||||
if (!vm.saveResult.fatal) {
|
if (!vm.saveResult.fatal) {
|
||||||
await saveScheduledUsers(vm, i);
|
await saveScheduledUsers(vm, i);
|
||||||
}
|
}
|
||||||
|
if (!vm.saveResult.fatal) {
|
||||||
|
await saveTasks(vm, i);
|
||||||
|
}
|
||||||
if (!vm.saveResult.fatal) {
|
if (!vm.saveResult.fatal) {
|
||||||
await saveLabors(vm, i);
|
await saveLabors(vm, i);
|
||||||
}
|
}
|
||||||
@@ -944,6 +951,61 @@ async function deleteScheduledUsers(vm, woItemIndex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// SCHEDULED USERS
|
||||||
|
//
|
||||||
|
async function saveTasks(vm, woItemIndex) {
|
||||||
|
//DELETE FLAGGED ITEMS FIRST
|
||||||
|
await deleteTasks(vm, woItemIndex);
|
||||||
|
if (vm.saveResult.fatal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < vm.obj.items[woItemIndex].tasks.length; i++) {
|
||||||
|
let o = vm.obj.items[woItemIndex].tasks[i];
|
||||||
|
if (o.isDirty) {
|
||||||
|
const isPost = o.id == 0;
|
||||||
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/tasks`, o);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "tasks",
|
||||||
|
childUid: o.uid
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
|
||||||
|
vm.obj.items[woItemIndex].tasks.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return; //made it
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteTasks(vm, woItemIndex) {
|
||||||
|
//walk the array backwards as items may be spliced out
|
||||||
|
for (var i = vm.obj.items[woItemIndex].tasks.length - 1; i >= 0; i--) {
|
||||||
|
const d = vm.obj.items[woItemIndex].tasks[i];
|
||||||
|
if (!d.deleted) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let res = await window.$gz.api.remove(`${API_BASE_URL}items/tasks/${d.id}`);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "tasks",
|
||||||
|
childUid: d.uid
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vm.obj.items[woItemIndex].tasks.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// LABOR
|
// LABOR
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user