This commit is contained in:
2020-07-07 23:12:34 +00:00
parent 783cc19502
commit ca3fb50058
3 changed files with 22 additions and 9 deletions

View File

@@ -151,9 +151,9 @@
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn text icon :data-cy="!!$ay.dev ? 'notification' : false"> <v-btn text icon :data-cy="!!$ay.dev ? 'notification' : false">
<!-- :value="unreadMsgs.length > 1" --> <!-- :value="unreadMsgs.length > 1" -->
<v-badge color="red" overlap left :value="true"> <v-badge color="red" overlap left :value="newNotificationCount() > 0">
<template v-slot:badge> <template v-slot:badge>
4 {{ newNotificationCount() }}
</template> </template>
<v-icon>fa-bell</v-icon> <v-icon>fa-bell</v-icon>
</v-badge> </v-badge>
@@ -376,6 +376,9 @@ export default {
}, },
clickMenuItem(item) { clickMenuItem(item) {
window.$gz.eventBus.$emit("menu-click", item); window.$gz.eventBus.$emit("menu-click", item);
},
newNotificationCount() {
return this.$store.state.newNotificationCount;
} }
} }
}; };

View File

@@ -1,23 +1,29 @@
/* xeslint-disable */ /* xeslint-disable */
let keepPolling = false; let keepPolling = false;
const DEFAULT_POLLING_INTERVAL = 10000;
const MAX_POLLING_INTERVAL = 15 * 60 * 1000; //15 minutes maximum wait time
export default { export default {
async startPolling() { async startPolling() {
console.log("notifypoll::starting polling");
keepPolling = true; keepPolling = true;
let pollingInterval = DEFAULT_POLLING_INTERVAL;
try { try {
while (keepPolling == true) { while (keepPolling == true) {
let status = await window.$gz.api.get("notify/new-count"); let status = await window.$gz.api.get("notify/new-count");
if (status.error) { if (status.error) {
throw status.error; throw status.error;
} }
console.log("notifypoll::new count ", status); window.$gz.store.commit("setNewNotificationCount", status.data);
// window.$gz.store.commit("setNotifyNewCount", status.data); //success so go to default in case it was changed by an error
await window.$gz.util.sleepAsync(10000); pollingInterval = DEFAULT_POLLING_INTERVAL;
await window.$gz.util.sleepAsync(pollingInterval);
} }
} catch (error) { } catch (error) {
keepPolling = false; pollingInterval *= 1.5;
if (pollingInterval > MAX_POLLING_INTERVAL) {
pollingInterval = MAX_POLLING_INTERVAL;
}
window.$gz.errorHandler.handleGeneralError( window.$gz.errorHandler.handleGeneralError(
"Error checking for notifications", "Error checking for notifications",
"notifypoll", "notifypoll",
@@ -33,6 +39,5 @@ export default {
}, },
stopPolling() { stopPolling() {
keepPolling = false; keepPolling = false;
console.log("notifypoll::stopping polling");
} }
}; };

View File

@@ -45,7 +45,8 @@ export default new Vuex.Store({
formSettings: {}, //this is the settings on forms that survive a refresh like grid number of items to show etc formSettings: {}, //this is the settings on forms that survive a refresh like grid number of items to show etc
formCustomTemplate: {}, //this is the custom fields settings for forms, formCustomTemplate: {}, //this is the custom fields settings for forms,
darkMode: false, darkMode: false,
knownPassword: false knownPassword: false,
newNotificationCount: 0
}, },
mutations: { mutations: {
setLastClientVersion(state, data) { setLastClientVersion(state, data) {
@@ -82,6 +83,7 @@ export default new Vuex.Store({
state.locale.hour12 = true; state.locale.hour12 = true;
state.globalSettings = {}; state.globalSettings = {};
state.knownPassword = false; state.knownPassword = false;
state.newNotificationCount = 0;
}, },
addNavItem(state, data) { addNavItem(state, data) {
state.navItems.push(data); state.navItems.push(data);
@@ -149,6 +151,9 @@ export default new Vuex.Store({
}, },
setKnownPassword(state, data) { setKnownPassword(state, data) {
state.knownPassword = data; state.knownPassword = data;
},
setNewNotificationCount(state, data) {
state.newNotificationCount = data;
} }
}, },
actions: {} actions: {}