re-factor / cleanup

This commit is contained in:
2022-01-11 22:08:38 +00:00
parent e871708b20
commit e0be8a7cfe
251 changed files with 14680 additions and 15693 deletions

View File

@@ -23,8 +23,8 @@
:pvm="this"
:goto="this.goto"
data-cy="woItems"
@change="setDirty()"
class="mt-16"
@change="setDirty()"
/>
</v-form>
</div>
@@ -39,7 +39,7 @@
<!-- ################################################################################-->
<template>
<v-row justify="center">
<v-dialog persistent max-width="600px" v-model="duplicateDlg">
<v-dialog v-model="duplicateDlg" persistent max-width="600px">
<v-card>
<v-card-title>{{ duplicateDlgTitle }}</v-card-title>
<v-card-text>
@@ -54,7 +54,7 @@
></v-checkbox>
</v-card-text>
<v-card-actions>
<v-btn text @click="duplicateDlg = false" color="primary">{{
<v-btn text color="primary" @click="duplicateDlg = false">{{
$ay.t("Cancel")
}}</v-btn>
<v-spacer></v-spacer>
@@ -82,6 +82,156 @@ export default {
GzWoHeader,
GzWoItems
},
data() {
return {
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
obj: {
id: 0,
concurrency: 0,
serial: 0,
notes: null,
wiki: null,
customFields: "{}",
tags: [],
customerId: 0, //part of rule breaking, flip to null on new triggers broken rule
projectId: null,
contractId: null,
internalReferenceNumber: null,
customerReferenceNumber: null,
customerContactName: null,
fromQuoteId: null,
fromPMId: null,
serviceDate: null,
completeByDate: null,
durationToCompleted: "00:00:00",
invoiceNumber: null,
onsite: true,
customerSignature: null,
customerSignatureName: null,
customerSignatureCaptured: null,
techSignature: null,
techSignatureName: null,
techSignatureCaptured: null,
postAddress: null,
postCity: null,
postRegion: null,
postCountry: null,
postCode: null,
address: null,
city: null,
region: null,
country: null,
latitude: null,
longitude: null,
items: [],
states: [],
isDirty: true,
isLockedAtServer: false,
alertViz: null
},
formState: {
ready: false,
dirty: false,
valid: true,
readOnly: false,
loading: true,
errorBoxMessage: null,
appError: null,
serverError: {}
},
rights: window.$gz.role.defaultRightsObject(),
ayaType: window.$gz.type.WorkOrder,
currencyName: window.$gz.locale.getCurrencyName(),
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage(),
hour12: window.$gz.locale.getHour12(),
selectLists: {
wostatus: [],
allowedwostatus: [],
woItemPriorities: [],
woItemStatus: [],
woItemTaskCompletionTypes: [],
loanUnitRateUnits: []
},
maxTableNotesLength: 50, //value to cut off notes in tables
saveResult: {
fatal: false, //fatal error, further save is pointless, bail early and report
errors: null //contains error objects from save
},
lastGetContractId: -1, //note: -1 so that a new record updates
lastGetCustomerId: -1,
goto: null, //{type:ayatype,id:wodescendant id} picked up by woitem when set non-null to trigger navigate to the item in question
duplicateDlg: false,
duplicateDlgTitle: null,
duplicateTo: null, //"pm","wo" or "quote"
genCopyWiki: false,
genCopyAttachments: false
};
},
computed: {
currentState() {
//return actual status object from top level shell based on current state
//if state is unknown then it should return a placeholder dummy state showing an error condition or empty I guess
if (this.obj.states != null && this.obj.states.length > 0) {
//find it in the status collection
//and return here
const laststate = this.obj.states[this.obj.states.length - 1];
const found = this.selectLists.wostatus.find(
z => z.id == laststate.workOrderStatusId
);
if (found) {
return found;
}
}
//default
return {
id: 0,
name: "-",
active: true,
color: "#ffffff", //invisible
completed: false,
locked: false
};
},
useInventory() {
return window.$gz.store.state.globalSettings.useInventory;
},
alertTechNotes() {
return this.obj.customerTechNotesViz
? `${this.$ay.t("CustomerTechNotes")}\n${this.obj.customerTechNotesViz}`
: null;
}
},
watch: {
formState: {
handler: function(val) {
if (this.formState.loading) {
return;
}
if (val.dirty && val.valid) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
}
if (!val.dirty && val.valid && !val.readOnly) {
window.$gz.eventBus.$emit(
"menu-enable-item",
FORM_KEY + ":duplicate"
);
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
} else {
window.$gz.eventBus.$emit(
"menu-disable-item",
FORM_KEY + ":duplicate"
);
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
}
},
deep: true
}
},
async created() {
const vm = this;
@@ -250,156 +400,6 @@ export default {
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
data() {
return {
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
obj: {
id: 0,
concurrency: 0,
serial: 0,
notes: null,
wiki: null,
customFields: "{}",
tags: [],
customerId: 0, //part of rule breaking, flip to null on new triggers broken rule
projectId: null,
contractId: null,
internalReferenceNumber: null,
customerReferenceNumber: null,
customerContactName: null,
fromQuoteId: null,
fromPMId: null,
serviceDate: null,
completeByDate: null,
durationToCompleted: "00:00:00",
invoiceNumber: null,
onsite: true,
customerSignature: null,
customerSignatureName: null,
customerSignatureCaptured: null,
techSignature: null,
techSignatureName: null,
techSignatureCaptured: null,
postAddress: null,
postCity: null,
postRegion: null,
postCountry: null,
postCode: null,
address: null,
city: null,
region: null,
country: null,
latitude: null,
longitude: null,
items: [],
states: [],
isDirty: true,
isLockedAtServer: false,
alertViz: null
},
formState: {
ready: false,
dirty: false,
valid: true,
readOnly: false,
loading: true,
errorBoxMessage: null,
appError: null,
serverError: {}
},
rights: window.$gz.role.defaultRightsObject(),
ayaType: window.$gz.type.WorkOrder,
currencyName: window.$gz.locale.getCurrencyName(),
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage(),
hour12: window.$gz.locale.getHour12(),
selectLists: {
wostatus: [],
allowedwostatus: [],
woItemPriorities: [],
woItemStatus: [],
woItemTaskCompletionTypes: [],
loanUnitRateUnits: []
},
maxTableNotesLength: 50, //value to cut off notes in tables
saveResult: {
fatal: false, //fatal error, further save is pointless, bail early and report
errors: null //contains error objects from save
},
lastGetContractId: -1, //note: -1 so that a new record updates
lastGetCustomerId: -1,
goto: null, //{type:ayatype,id:wodescendant id} picked up by woitem when set non-null to trigger navigate to the item in question
duplicateDlg: false,
duplicateDlgTitle: null,
duplicateTo: null, //"pm","wo" or "quote"
genCopyWiki: false,
genCopyAttachments: false
};
},
watch: {
formState: {
handler: function(val) {
if (this.formState.loading) {
return;
}
if (val.dirty && val.valid) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
}
if (!val.dirty && val.valid && !val.readOnly) {
window.$gz.eventBus.$emit(
"menu-enable-item",
FORM_KEY + ":duplicate"
);
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
} else {
window.$gz.eventBus.$emit(
"menu-disable-item",
FORM_KEY + ":duplicate"
);
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
}
},
deep: true
}
},
computed: {
currentState() {
//return actual status object from top level shell based on current state
//if state is unknown then it should return a placeholder dummy state showing an error condition or empty I guess
if (this.obj.states != null && this.obj.states.length > 0) {
//find it in the status collection
//and return here
const laststate = this.obj.states[this.obj.states.length - 1];
const found = this.selectLists.wostatus.find(
z => z.id == laststate.workOrderStatusId
);
if (found) {
return found;
}
}
//default
return {
id: 0,
name: "-",
active: true,
color: "#ffffff", //invisible
completed: false,
locked: false
};
},
useInventory() {
return window.$gz.store.state.globalSettings.useInventory;
},
alertTechNotes() {
return this.obj.customerTechNotesViz
? `${this.$ay.t("CustomerTechNotes")}\n${this.obj.customerTechNotesViz}`
: null;
}
},
methods: {
setDirty: function() {
this.formState.dirty = true;
@@ -887,8 +887,9 @@ async function saveHeader(vm) {
//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
/* eslint-disable no-unused-vars */
const { items: removedKey1, states: removedKey2, ...headerOnly } = vm.obj;
/* eslint-enable no-unused-vars */
//remove *Viz keys so they don't generate traffic
headerOnly.alertViz = undefined;
headerOnly.projectViz = undefined;
@@ -979,6 +980,7 @@ async function saveItems(vm) {
for (let i = 0; i < vm.obj.items.length; i++) {
if (vm.obj.items[i].isDirty) {
//get copy of item without child collections for independant submit
/* eslint-disable no-unused-vars */
const {
expenses: removedKey1,
labors: removedKey2,
@@ -992,7 +994,7 @@ async function saveItems(vm) {
outsideServices: removedKey10,
...o
} = vm.obj.items[i];
/* eslint-enable no-unused-vars */
const isPost = o.id == 0;
const res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
if (res.error) {
@@ -1907,17 +1909,19 @@ async function clickHandler(menuItem) {
m.vm.duplicateDlg = true;
break;
case "report":
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.WorkOrder,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
{
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.WorkOrder,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
}
window.$gz.form.setLastReportMenuItem(FORM_KEY, res, m.vm);
}
window.$gz.form.setLastReportMenuItem(FORM_KEY, res, m.vm);
break;
case "statuslist":
m.vm.$router.push({
@@ -2142,7 +2146,7 @@ let JUST_DELETED = false;
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
await fetchTranslatedText();
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
await populateSelectionLists(vm);
}
@@ -2151,7 +2155,7 @@ async function initForm(vm) {
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations([
"WorkOrder",
"CopyWiki",