|
@@ -18,7 +18,9 @@
|
|
|
var App = require('app');
|
|
|
|
|
|
App.alertNotificationMapper = App.QuickDataMapper.create({
|
|
|
+
|
|
|
model: App.AlertNotification,
|
|
|
+
|
|
|
config: {
|
|
|
id: 'AlertTarget.id',
|
|
|
name: 'AlertTarget.name',
|
|
@@ -28,11 +30,17 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
|
|
|
},
|
|
|
|
|
|
map: function (json) {
|
|
|
+ if(Em.isNone(App.cache['previousAlertNotificationsFullMap'])) {
|
|
|
+ App.cache['previousAlertNotificationsFullMap'] = {};
|
|
|
+ }
|
|
|
+ console.time('App.alertNotificationMapper execution time');
|
|
|
if (json.items) {
|
|
|
var result = [];
|
|
|
var notificationsProperties = {};
|
|
|
var notificationsAlertStates = {};
|
|
|
var groupsMap = App.cache['alertNotificationsGroupsMap'];
|
|
|
+ var notifications = {};
|
|
|
+ var self = this;
|
|
|
|
|
|
json.items.forEach(function (item) {
|
|
|
var notification = this.parseIt(item, this.config);
|
|
@@ -40,27 +48,38 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
|
|
|
if (groups) {
|
|
|
notification.groups = groups;
|
|
|
}
|
|
|
- result.push(notification);
|
|
|
+
|
|
|
+ var previousNotification = App.cache['previousAlertNotificationsFullMap'][notification.id] ? App.cache['previousAlertNotificationsFullMap'][notification.id] : {};
|
|
|
+ var changedFields = self.getDiscrepancies(notification, previousNotification, ['name', 'type', 'description', 'global', 'groups']);
|
|
|
+ if (Object.keys(changedFields).length) {
|
|
|
+ result.push(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ notifications[notification.id] = notification;
|
|
|
notificationsProperties[item.AlertTarget.id] = item.AlertTarget.properties;
|
|
|
notificationsAlertStates[item.AlertTarget.id] = item.AlertTarget.alert_states;
|
|
|
}, this);
|
|
|
|
|
|
App.store.loadMany(this.get('model'), result);
|
|
|
- this.setProperties('properties', notificationsProperties);
|
|
|
- this.setProperties('alertStates', notificationsAlertStates);
|
|
|
+ App.cache['previousAlertNotificationsFullMap'] = notifications;
|
|
|
+ this._setPropertiesToEachModel('properties', notificationsProperties);
|
|
|
+ this._setPropertiesToEachModel('alertStates', notificationsAlertStates);
|
|
|
}
|
|
|
+ console.timeEnd('App.alertNotificationMapper execution time');
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* Set values from <code>propertyMap</code> for <code>propertyName</code> for each record in model
|
|
|
- * @param propertyName
|
|
|
- * @param propertiesMap record_id to value map
|
|
|
+ * @param {string} propertyName
|
|
|
+ * @param {object} propertiesMap record_id to value map
|
|
|
+ * @method setPropertiesToEachModel
|
|
|
+ * @private
|
|
|
*/
|
|
|
- setProperties: function (propertyName, propertiesMap) {
|
|
|
- var modelRecords = this.get('model').find();
|
|
|
+ _setPropertiesToEachModel: function (propertyName, propertiesMap) {
|
|
|
+ var modelsMap = this.get('modelsMap');
|
|
|
for (var recordId in propertiesMap) {
|
|
|
if (propertiesMap.hasOwnProperty(recordId)) {
|
|
|
- modelRecords.findProperty('id', +recordId).set(propertyName, propertiesMap[recordId]);
|
|
|
+ App.AlertNotification.find(recordId).set(propertyName, propertiesMap[recordId]);
|
|
|
}
|
|
|
}
|
|
|
}
|