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-btn text icon :data-cy="!!$ay.dev ? 'notification' : false">
<!-- :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>
4
{{ newNotificationCount() }}
</template>
<v-icon>fa-bell</v-icon>
</v-badge>
@@ -376,6 +376,9 @@ export default {
},
clickMenuItem(item) {
window.$gz.eventBus.$emit("menu-click", item);
},
newNotificationCount() {
return this.$store.state.newNotificationCount;
}
}
};

View File

@@ -1,23 +1,29 @@
/* xeslint-disable */
let keepPolling = false;
const DEFAULT_POLLING_INTERVAL = 10000;
const MAX_POLLING_INTERVAL = 15 * 60 * 1000; //15 minutes maximum wait time
export default {
async startPolling() {
console.log("notifypoll::starting polling");
keepPolling = true;
let pollingInterval = DEFAULT_POLLING_INTERVAL;
try {
while (keepPolling == true) {
let status = await window.$gz.api.get("notify/new-count");
if (status.error) {
throw status.error;
}
console.log("notifypoll::new count ", status);
// window.$gz.store.commit("setNotifyNewCount", status.data);
await window.$gz.util.sleepAsync(10000);
window.$gz.store.commit("setNewNotificationCount", status.data);
//success so go to default in case it was changed by an error
pollingInterval = DEFAULT_POLLING_INTERVAL;
await window.$gz.util.sleepAsync(pollingInterval);
}
} catch (error) {
keepPolling = false;
pollingInterval *= 1.5;
if (pollingInterval > MAX_POLLING_INTERVAL) {
pollingInterval = MAX_POLLING_INTERVAL;
}
window.$gz.errorHandler.handleGeneralError(
"Error checking for notifications",
"notifypoll",
@@ -33,6 +39,5 @@ export default {
},
stopPolling() {
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
formCustomTemplate: {}, //this is the custom fields settings for forms,
darkMode: false,
knownPassword: false
knownPassword: false,
newNotificationCount: 0
},
mutations: {
setLastClientVersion(state, data) {
@@ -82,6 +83,7 @@ export default new Vuex.Store({
state.locale.hour12 = true;
state.globalSettings = {};
state.knownPassword = false;
state.newNotificationCount = 0;
},
addNavItem(state, data) {
state.navItems.push(data);
@@ -149,6 +151,9 @@ export default new Vuex.Store({
},
setKnownPassword(state, data) {
state.knownPassword = data;
},
setNewNotificationCount(state, data) {
state.newNotificationCount = data;
}
},
actions: {}