Source
/*
** 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/>.
**/
/**
* Represents DOM node for notification list. Stores the collection of ZBX_Notification objects.
*/
function ZBX_NotificationCollection() {
this._dangling_nodes = [];
this._list_sequence = [];
this._list_obj = {};
this.makeNodes();
this.node.style.right = '10px';
this.node.style.top = '0px';
}
/**
* @return {array}
*/
ZBX_NotificationCollection.prototype.getIds = function() {
return this._list_sequence;
};
/**
* @param {callable} callback
*/
ZBX_NotificationCollection.prototype.map = function(callback) {
var len = this._list_sequence.length;
while (--len > -1) {
callback(this.getById(this._list_sequence[len]), len);
}
};
/**
* @param {callable} callback
*
* @return {array}
*/
ZBX_NotificationCollection.prototype.filterList = function(callback) {
var list = [],
len = this._list_sequence.length;
while (--len > -1) {
var ret = callback(this.getById(this._list_sequence[len]));
(ret !== false) && list.push(ret);
}
return list;
};
/**
* @return {array} List of raw notification objects.
*/
ZBX_NotificationCollection.prototype.getRawList = function() {
return this.filterList(function(notif) {
return notif.getRaw();
});
};
/**
* Merges current with new list. Updates changes for ZBX_Notification if possible, or creates new ZBX_Notification.
* Recoverable notification is just partial of raw with one mandatory field - `eventid`. New iterator sequence reflects
* the order of list given to this method. During merge, nodes that are not present in list will be removed.
*
* @param {array} list List of raw/recoverable notification objects.
*/
ZBX_NotificationCollection.prototype.consumeList = function(list) {
var new_list_sequence = [];
while (raw = list.pop()) {
/*
* Case if server returns with "recovered" notification type, that cannot be recovered by client.
* This should never happen.
*/
if (!raw.body && !this._list_obj[raw.eventid]) {
continue;