This commit is contained in:
2020-07-20 17:36:59 +00:00
parent 311db14b7a
commit a6ca999130
5 changed files with 149 additions and 14 deletions

View File

@@ -55,7 +55,9 @@ todo: //NEW NOTIFICATION SUBSCRIPTION EVENT TYPE:
BACKEND
todo: remove fetched date column from notification table? (doesn't appear to be used in current system)
although, would be useful for bolding new items maybe?
todo: BAckend server routes for App notification fetch and clear etc
todo: Back end notification related settings

View File

@@ -111,7 +111,7 @@ export default {
window.$gz.eventBus.$on("menu-click", clickHandler);
//NOTE: this would normally be in getDataFromAPI but this form doesn't really need that function so doing it here
//modify the menu as necessary
generateMenu(vm, false); //default is never read only and passing in this vm
generateMenu(vm);
//init disable save button so it can be enabled only on edit to show dirty form
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete");

View File

@@ -86,7 +86,7 @@ export default {
window.$gz.eventBus.$on("menu-click", clickHandler);
//NOTE: this would normally be in getDataFromAPI but this form doesn't really need that function so doing it here
//modify the menu as necessary
generateMenu(vm, false); //default is never read only and passing in this vm
generateMenu(vm);
//init disable save button so it can be enabled only on edit to show dirty form
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
} catch (err) {

View File

@@ -447,7 +447,7 @@ export default {
window.$gz.eventBus.$on("menu-click", clickHandler);
//NOTE: this would normally be in getDataFromAPI but this form doesn't really need that function so doing it here
//modify the menu as necessary
generateMenu(vm, false); //default is never read only and passing in this vm
generateMenu(vm);
//init disable save button so it can be enabled only on edit to show dirty form
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
vm.formState.loading = false;

View File

@@ -1,24 +1,157 @@
<template>
<div>
<h1>New notification count: {{ newNotificationCount() }}</h1>
<v-list three-line>
<v-list-item> </v-list-item>
</v-list>
</div>
</template>
<script>
const FORM_KEY = "notification-subscriptions";
export default {
beforeCreate() {
window.$gz.eventBus.$emit("menu-change", {
isMain: true,
icon: "fa-bell",
title: "Notifications",
helpUrl: "form-home-notifications"
});
async created() {
let vm = this;
try {
await initForm(vm);
window.$gz.eventBus.$on("menu-click", clickHandler);
generateMenu(vm, false);
await vm.getDataFromApi();
} catch (err) {
window.$gz.errorHandler.handleFormError(err, vm);
} finally {
vm.formState.ready = true;
}
},
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
data() {
return {
rights: window.$gz.role.defaultRightsObject()
};
},
methods: {
newNotificationCount() {
return this.$store.state.newNotificationCount;
async getDataFromApi() {
let vm = this;
let url = API_BASE_URL + recordId;
try {
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.get(url);
if (res.error) {
//Not found?
if (res.error.code == "2010") {
//notify not found error then navigate backwards
window.$gz.eventBus.$emit("notify-error", vm.$ay.t("ErrorAPI2010"));
// navigate backwards
window.$gz._.delay(function() {
vm.$router.go(-1);
}, 2000);
}
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
vm.obj = res.data;
//modify the menu as necessary
generateMenu(vm);
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
valid: true,
loading: false
});
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
window.$gz.form.setFormState({
vm: vm,
loading: false
});
}
}
}
};
/////////////////////////////
//
//
async function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
// case "new":
// m.vm.$router.push({
// name: "home-notify-subscription",
// params: { recordid: 0 }
// });
// break;
// case "extensions":
// let res = await m.vm.$refs.extensions.open();
// break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
FORM_KEY + "::context click: [" + m.key + "]"
);
}
}
}
//////////////////////
//
//
function generateMenu(vm) {
let menuOptions = {
isMain: true,
icon: "fa-bell",
title: "Notifications",
helpUrl: "form-home-notifications",
menuItems: []
};
// if (vm.rights.change) {
// menuOptions.menuItems.push({
// title: "New",
// icon: "fa-plus",
// surface: true,
// key: FORM_KEY + ":new",
// vm: vm
// });
// }
// //STUB REPORTS
// //Report not Print, print is a further option
// menuOptions.menuItems.push({
// title: "Report",
// icon: "fa-file-alt",
// key: FORM_KEY + ":report",
// vm: vm
// });
// menuOptions.menuItems.push({
// title: "stub: Last report used",
// icon: "fa-file-alt",
// key: FORM_KEY + ":report:STUBlastusedreportid",
// vm: vm
// });
// menuOptions.menuItems.push({
// title: "Extensions",
// icon: "fa-puzzle-piece",
// key: FORM_KEY + ":extensions",
// vm: vm
// });
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
</script>