Source
xxxxxxxxxx
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Default value in seconds, for poller interval.
*/
ZBX_Notifications.POLL_INTERVAL = 5;
ZBX_Notifications.ALARM_SEVERITY_RESOLVED = -1;
ZBX_Notifications.ALARM_INFINITE_SERVER = -1;
ZBX_Notifications.ALARM_ONCE_PLAYER = -1;
ZBX_Notifications.ALARM_ONCE_SERVER = 1;
/**
* Fetches and renders notifications. Server always returns full list of actual notifications that this class will
* render into DOM. Last focused ZBX_BrowserTab instance is the active one. Active ZBX_BrowserTab instance is the only
* one that polls server, meanwhile other instances are inactive. This is achieved by synchronizing state of active tab
* via ZBX_LocalStorage and responding to it's change event.
*
* Only methods prefixed with <push> are the "action dispatchers", methods prefixed with <handlePushed> responds to
* these "actions" by passing the new received state value through a method prefixed with <consume> that will adjust
* instance's internal state, that in turn can be dispatched as "action". Other methods prefixed with <handle> responds
* to other events than localStorage change event - (poll, focus, timeout..) and still they would reuse <consume>
* domain methods and issue an action via <push> if needed and call to render method explicitly. The <handlePushed> is
* not reused on the instance that produces the action. This is so to reduce complexity and increase maintainability,
* because when an action produces an action, logic diverges deep, instead <consume> various domain within logic
* and call `render` once, then <push> into localStorage once.
*
* Methods prefixed with <render> uses only consumed internal state and should not <push> any changes.
*
* @param {ZBX_LocalStorage} store
* @param {ZBX_BrowserTab} tab
*/
function ZBX_Notifications(store, tab) {
if (!(store instanceof ZBX_LocalStorage) || !(tab instanceof ZBX_BrowserTab)) {
throw 'Unmatched signature!';
}
this.active = false;
this.poll_interval = ZBX_Notifications.POLL_INTERVAL;
this.store = store;
this.tab = tab;
this.collection = new ZBX_NotificationCollection();
this.alarm = new ZBX_NotificationsAlarm(new ZBX_NotificationsAudio());
this.fetchUpdates();
this.consumeList(this._cached_list);