HUGE REFACTOR / CLEANUP

if there is a issue it's probably something in here that was changed
This commit is contained in:
2021-09-28 20:19:44 +00:00
parent 51eddfede9
commit d0afdd9855
238 changed files with 3127 additions and 8614 deletions

View File

@@ -4,7 +4,6 @@
<v-form data-cy="dlcForm" ref="form">
<v-row>
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
<template v-for="(item, index) in editView">
<v-col :key="item.key" cols="12" sm="6" lg="4" xl="3" px-2>
<v-card
@@ -66,15 +65,11 @@
</v-row>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// CUSTOMIZE A DATA GRID'S VISIBLE COLUMNS
//
const FORM_KEY = "ay-data-list-column-view";
const API_BASE_URL = "data-list-column-view/";
export default {
async beforeRouteLeave(to, from, next) {
if (!this.formState.dirty) {
@@ -91,14 +86,12 @@ export default {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
async created() {
let vm = this;
const vm = this;
try {
vm.dataListKey = this.$route.params.dataListKey;
if (this.$route.params.hiddenAffectiveColumns) {
vm.hiddenAffectiveColumns = this.$route.params.hiddenAffectiveColumns;
}
await initForm(vm);
vm.formState.ready = true;
window.$gz.eventBus.$on("menu-click", clickHandler);
@@ -138,17 +131,13 @@ export default {
rights: window.$gz.role.fullRightsObject()
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
//,oldval is available here too if necessary
if (this.formState.loading) {
return;
}
//enable / disable save button
let canSave = val.dirty && val.valid && !val.readOnly;
const canSave = val.dirty && val.valid && !val.readOnly;
if (canSave) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
@@ -180,7 +169,7 @@ export default {
});
},
move: function(direction, index) {
let totalItems = this.editView.length;
const totalItems = this.editView.length;
let newIndex = 0;
//calculate new index
switch (direction) {
@@ -198,13 +187,11 @@ export default {
if (newIndex > totalItems - 1) {
newIndex = totalItems - 1;
}
break;
case "end":
newIndex = totalItems - 1;
break;
}
this.editView.splice(newIndex, 0, this.editView.splice(index, 1)[0]);
window.$gz.form.setFormState({
vm: this,
@@ -221,53 +208,41 @@ export default {
},
async submit() {
if (this.canSave) {
let vm = this;
vm.formState.loading = true;
let url = API_BASE_URL;
let columnView = {
userId: vm.$store.state.userId,
listKey: vm.dataListKey,
columns: JSON.stringify(generateColumnViewFromEditView(vm)),
sort: vm.obj.sort //not set here, just keep existing one that was fetched when opened this form
this.formState.loading = true;
const columnView = {
userId: this.$store.state.userId,
listKey: this.dataListKey,
columns: JSON.stringify(generateColumnViewFromEditView(this)),
sort: this.obj.sort //not set here, just keep existing one that was fetched when opened this form
};
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(this);
try {
let res = await window.$gz.api.post(url, columnView);
vm.formState.loading = false;
const res = await window.$gz.api.post(API_BASE_URL, columnView);
this.formState.loading = false;
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} else {
vm.obj = res.data;
initWorkingView(vm);
this.obj = res.data;
initWorkingView(this);
window.$gz.form.setFormState({
vm: vm,
vm: this,
dirty: false,
valid: true
});
}
} catch (error) {
vm.formState.loading = false;
window.$gz.errorHandler.handleFormError(error, vm);
this.formState.loading = false;
window.$gz.errorHandler.handleFormError(error, this);
}
}
},
async reset() {
let vm = this;
const vm = this;
try {
vm.formState.loading = true;
let url = API_BASE_URL + vm.dataListKey;
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.remove(url);
const res = await window.$gz.api.remove(API_BASE_URL + vm.dataListKey);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
@@ -282,7 +257,6 @@ export default {
});
}
} catch (error) {
//Update the form status
window.$gz.form.setFormState({
vm: vm,
loading: false
@@ -300,7 +274,7 @@ function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
const m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
case "save":
@@ -325,7 +299,7 @@ function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: "$ayiColumns",
@@ -384,11 +358,10 @@ async function fetchTranslatedText(vm) {
////////////////////
//
async function populateFieldDefinitions(vm) {
let res = await window.$gz.api.get(
const res = await window.$gz.api.get(
"data-list/listfields?DataListKey=" + vm.dataListKey
);
if (res.error) {
//throw new Error(res.error);
throw new Error(window.$gz.errorHandler.errorToString(res, vm));
} else {
vm.fieldDefinitions = res.data;
@@ -400,9 +373,9 @@ async function populateFieldDefinitions(vm) {
// Ensures column names are present in translation table
//
async function fetchTranslatedFieldNames(vm) {
let columnKeys = [];
const columnKeys = [];
for (let i = 0; i < vm.fieldDefinitions.length; i++) {
let cm = vm.fieldDefinitions[i];
const cm = vm.fieldDefinitions[i];
if (!columnKeys.includes(cm.tKey)) {
columnKeys.push(cm.tKey);
}
@@ -418,7 +391,7 @@ async function fetchTranslatedFieldNames(vm) {
//
//
async function fetchColumnView(vm) {
let res = await window.$gz.api.get(API_BASE_URL + vm.dataListKey);
const res = await window.$gz.api.get(API_BASE_URL + vm.dataListKey);
if (res.error) {
throw new Error(window.$gz.errorHandler.errorToString(res, vm));
} else {
@@ -434,68 +407,55 @@ function initWorkingView(vm) {
"ay-data-list::initWorkingView - fieldDefinitions are not set"
);
}
let ret = [];
let columns = JSON.parse(vm.obj.columns);
const ret = [];
const columns = JSON.parse(vm.obj.columns);
//Pass 1, iterate the columns first
for (let i = 0; i < columns.length; i++) {
let fld = vm.fieldDefinitions.find(z => z.fieldKey == columns[i]);
const fld = vm.fieldDefinitions.find(z => z.fieldKey == columns[i]);
//there can be a column definition that doesn't exist due to updates or misconfiguration or other issues so ignore it if that's the case
if (fld) {
let o = {
const o = {
key: fld.fieldKey,
title: null,
include: true
};
if (fld.tKeySection != null) {
o.title = vm.$ay.t(fld.tKeySection) + "." + vm.$ay.t(fld.tKey);
} else {
o.title = vm.$ay.t(fld.tKey);
}
if (fld.isRowId) {
o.rid = true;
}
ret.push(o);
}
}
//Pass 2, remaining fields not already dealt with
for (let i = 0; i < vm.fieldDefinitions.length; i++) {
let fld = vm.fieldDefinitions[i];
const fld = vm.fieldDefinitions[i];
if (null == ret.find(z => z.key == fld.fieldKey)) {
//nope, so add it
let o = {
const o = {
key: fld.fieldKey,
title: null,
include: false
};
if (fld.tKeySection != null) {
o.title = vm.$ay.t(fld.tKeySection) + "." + vm.$ay.t(fld.tKey);
} else {
o.title = vm.$ay.t(fld.tKey);
}
if (fld.isRowId) {
o.rid = true;
o.include = true;
}
if (vm.hiddenAffectiveColumns.includes(fld.fieldKey)) {
o.affective = true;
}
ret.push(o);
}
}
vm.editView = ret;
//eoc
}
//////////////////////////////////////////////////////////
@@ -503,18 +463,14 @@ function initWorkingView(vm) {
// Convert editedList view to real list view and return
//
function generateColumnViewFromEditView(vm) {
let ret = [];
const ret = [];
for (let i = 0; i < vm.editView.length; i++) {
let ev = vm.editView[i];
const ev = vm.editView[i];
if (!ev.include) {
continue;
}
ret.push(ev.key);
}
return ret;
//eoc
}
/////////////END OF FORM//////////////////
</script>