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

@@ -66,7 +66,7 @@
const FORM_KEY = "notifications";
export default {
async created() {
let vm = this;
const vm = this;
try {
await initForm(vm);
@@ -116,70 +116,41 @@ export default {
});
},
async deleteItem(item) {
//prompt
//delete
let vm = this;
try {
let dialogResult = await window.$gz.dialog.confirmDelete();
const dialogResult = await window.$gz.dialog.confirmDelete();
if (dialogResult != true) {
return;
}
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.remove(
window.$gz.form.deleteAllErrorBoxErrors(this);
const res = await window.$gz.api.remove(
`notify/${item.id}`,
this.selectedItems
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
}
await this.getDataFromApi();
} catch (ex) {
window.$gz.errorHandler.handleFormError(ex, vm);
window.$gz.errorHandler.handleFormError(ex, this);
}
},
async getDataFromApi() {
let vm = this;
try {
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.get("notify/app-notifications");
window.$gz.form.deleteAllErrorBoxErrors(this);
const res = await window.$gz.api.get("notify/app-notifications");
if (res.error) {
//Not found?
if (res.error.code == "2010") {
window.$gz.form.handleObjectNotFound(vm);
window.$gz.form.handleObjectNotFound(this);
}
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} else {
//pre-make the display list object
//source object:
//[ { "id": 1, "concurrency": 18835104, "userId": 1, "created": "2020-07-20T19:35:49.665888Z", "ayaType": 2,
// "objectId": 101, "eventType": 2, "notifySubscriptionId": 1, "message": null, "fetched": true } ]
//display object:
//{event:"",objectname:"",objecttype:null,icon:null,eventdate:null,openurl:null,suburl:null,eventid}
let temp = res.data;
//Nice touch to show super faded just before deletion but don't have time for this at the moment
// let dtNow = window.$gz.DateTime.local();
// let dtToday = window.$gz.DateTime.local(
// dtNow.year,
// dtNow.month,
// dtNow.day
// );
// let dtPrecipice = dtToday.plus({ days: -85 }).toUTC();
const temp = res.data;
const timeZoneName = window.$gz.locale.getResolvedTimeZoneName();
const languageName = window.$gz.locale.getResolvedLanguage();
const hour12 = window.$gz.store.state.userOptions.hour12;
const currencyName = window.$gz.locale.getCurrencyName();
for (let i = 0; i < temp.length; i++) {
temp[
i
@@ -190,24 +161,20 @@ export default {
hour12
);
temp[i]["uievent"] = vm.selectLists.eventTypes.find(
temp[i]["uievent"] = this.selectLists.eventTypes.find(
z => z.id == temp[i].eventType
).name;
temp[i]["uiayatype"] = vm.selectLists.ayaTypes.find(
temp[i]["uiayatype"] = this.selectLists.ayaTypes.find(
z => z.id == temp[i].ayaType
).name;
temp[i].icon = window.$gz.util.iconForType(temp[i].ayaType);
if (temp[i].name == "~SERVER~") {
temp[i].name = vm.$ay.t("Server");
temp[i].name = this.$ay.t("Server");
}
// if (temp[i].message && temp[i].message.includes("\n")) {
// temp[i].message = temp[i].message.replace("\n", "<br/>");
// }
temp[i].ageValueViz = window.$gz.locale.durationLocalized(
temp[i].ageValue
);
@@ -228,33 +195,30 @@ export default {
temp[i].decValueViz = "";
}
}
vm.obj = [...temp];
//modify the menu as necessary
generateMenu(vm);
//Update the form status
this.obj = [...temp];
generateMenu(this);
window.$gz.form.setFormState({
vm: vm,
vm: this,
dirty: false,
valid: true,
loading: false
});
//Check the new count and update accordingly
//this is to ensure that when a user is viewing the latest notifications they don't see the NEW count still in the bell icon in menu since they are viewing them live
let status = await window.$gz.api.get("notify/new-count");
const status = await window.$gz.api.get("notify/new-count");
if (status.error) {
//throw new Error(status.error);
throw new Error(window.$gz.errorHandler.errorToString(status, vm));
throw new Error(
window.$gz.errorHandler.errorToString(status, this)
);
}
window.$gz.store.commit("setNewNotificationCount", status.data);
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.errorHandler.handleFormError(error, this);
} finally {
window.$gz.form.setFormState({
vm: vm,
vm: this,
loading: false
});
}
@@ -269,16 +233,12 @@ async 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 "refresh":
await m.vm.getDataFromApi();
break;
// case "directnotify":
// let res = await m.vm.$refs.extensions.open();
// break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
@@ -292,7 +252,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: true,
icon: "$ayiBell",
title: "Notifications",