|
@@ -107,7 +107,35 @@ App.ManageAlertGroupsController = Em.Controller.extend({
|
|
|
* observes if any group changed including: group name, newly created group, deleted group, group with definitions/notifications changed
|
|
|
* @type {{toDelete: App.AlertGroup[], toSet: App.AlertGroup[], toCreate: App.AlertGroup[]}}
|
|
|
*/
|
|
|
- defsModifiedAlertGroups: function () {
|
|
|
+ defsModifiedAlertGroups: {},
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Determines if some group was edited/created/deleted
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
+ isDefsModified: function () {
|
|
|
+ var modifiedGroups = this.get('defsModifiedAlertGroups');
|
|
|
+ if (!this.get('isLoaded')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return !!(modifiedGroups.toSet.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length);
|
|
|
+ }.property('defsModifiedAlertGroups'),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Check when some config group was changed and updates <code>defsModifiedAlertGroups</code> once
|
|
|
+ * @method defsModifiedAlertGroupsObs
|
|
|
+ */
|
|
|
+ defsModifiedAlertGroupsObs: function() {
|
|
|
+ Em.run.once(this, this.defsModifiedAlertGroupsObsOnce);
|
|
|
+ }.observes('selectedAlertGroup.definitions.@each', 'selectedAlertGroup.definitions.length', 'selectedAlertGroup.notifications.@each', 'selectedAlertGroup.notifications.length', 'alertGroups', 'isLoaded'),
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update <code>defsModifiedAlertGroups</code>-value
|
|
|
+ * Called once in the <code>defsModifiedAlertGroupsObs</code>
|
|
|
+ * @method defsModifiedAlertGroupsObsOnce
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ defsModifiedAlertGroupsObsOnce: function() {
|
|
|
if (!this.get('isLoaded')) {
|
|
|
return false;
|
|
|
}
|
|
@@ -116,20 +144,28 @@ App.ManageAlertGroupsController = Em.Controller.extend({
|
|
|
var groupsToCreate = [];
|
|
|
var groups = this.get('alertGroups'); //current alert groups
|
|
|
var originalGroups = this.get('originalAlertGroups'); // original alert groups
|
|
|
+ var mappedOriginalGroups = {}; // map is faster than `originalGroups.findProperty('id', ...)`
|
|
|
+ originalGroups.forEach(function(group) {
|
|
|
+ mappedOriginalGroups[group.get('id')] = group;
|
|
|
+ });
|
|
|
var originalGroupsIds = originalGroups.mapProperty('id');
|
|
|
+
|
|
|
groups.forEach(function (group) {
|
|
|
- var originalGroup = originalGroups.findProperty('id', group.get('id'));
|
|
|
+ var originalGroup = mappedOriginalGroups[group.get('id')];
|
|
|
if (originalGroup) {
|
|
|
// should update definitions or notifications
|
|
|
- if (!(JSON.stringify(group.get('definitions').slice().sort()) === JSON.stringify(originalGroup.get('definitions').slice().sort()))
|
|
|
- || !(JSON.stringify(group.get('notifications').slice().sort()) === JSON.stringify(originalGroup.get('notifications').slice().sort()))) {
|
|
|
+ if (JSON.stringify(group.get('definitions').slice().sort()) !== JSON.stringify(originalGroup.get('definitions').slice().sort())
|
|
|
+ || JSON.stringify(group.get('notifications').slice().sort()) !== JSON.stringify(originalGroup.get('notifications').slice().sort())) {
|
|
|
groupsToSet.push(group.set('id', originalGroup.get('id')));
|
|
|
- } else if (group.get('name') !== originalGroup.get('name')) {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if (group.get('name') !== originalGroup.get('name')) {
|
|
|
// should update name
|
|
|
groupsToSet.push(group.set('id', originalGroup.get('id')));
|
|
|
}
|
|
|
originalGroupsIds = originalGroupsIds.without(group.get('id'));
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
// should add new group
|
|
|
groupsToCreate.push(group);
|
|
|
}
|
|
@@ -137,25 +173,14 @@ App.ManageAlertGroupsController = Em.Controller.extend({
|
|
|
// should delete groups
|
|
|
originalGroupsIds.forEach(function (id) {
|
|
|
groupsToDelete.push(originalGroups.findProperty('id', id));
|
|
|
- }, this);
|
|
|
- return {
|
|
|
+ });
|
|
|
+
|
|
|
+ this.set('defsModifiedAlertGroups', {
|
|
|
toDelete: groupsToDelete,
|
|
|
toSet: groupsToSet,
|
|
|
toCreate: groupsToCreate
|
|
|
- };
|
|
|
- }.property('selectedAlertGroup.definitions.@each', 'selectedAlertGroup.definitions.length', 'selectedAlertGroup.notifications.@each', 'selectedAlertGroup.notifications.length', 'alertGroups', 'isLoaded'),
|
|
|
-
|
|
|
- /**
|
|
|
- * Determines if some group was edited/created/deleted
|
|
|
- * @type {boolean}
|
|
|
- */
|
|
|
- isDefsModified: function () {
|
|
|
- var modifiedGroups = this.get('defsModifiedAlertGroups');
|
|
|
- if (!this.get('isLoaded')) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return !!(modifiedGroups.toSet.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length);
|
|
|
- }.property('defsModifiedAlertGroups'),
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* Load all Alert Notifications from server
|