Procházet zdrojové kódy

AMBARI-8538. Alerts UI: Implement binding to AlertGroups in Manage Alert Notifications dialog

Srimanth Gunturi před 10 roky
rodič
revize
3a8e1c5e12

+ 11 - 1
ambari-web/app/mappers/alert_groups_mapper.js

@@ -67,7 +67,8 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
          * </code>
          * @type {object}
          */
-        alertDefinitionsGroupsMap = {};
+        alertDefinitionsGroupsMap = {},
+        alertNotificationsGroupsMap = {};
 
       json.items.forEach(function(item) {
         var group = self.parseIt(item, self.get('config'));
@@ -87,6 +88,14 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
             alertDefinitionsGroupsMap[definition.id].push(group.id);
           });
         }
+        if (item.AlertGroup.targets) {
+          item.AlertGroup.targets.forEach(function(target) {
+            if (Em.isNone(alertNotificationsGroupsMap[target.id])) {
+              alertNotificationsGroupsMap[target.id] = [];
+            }
+            alertNotificationsGroupsMap[target.id].push(group.id);
+          });
+        }
         alertGroups.push(group);
       }, this);
 
@@ -95,6 +104,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
       });
 
       App.cache['previousAlertGroupsMap'] = alertDefinitionsGroupsMap;
+      App.cache['alertNotificationsGroupsMap'] = alertNotificationsGroupsMap;
       App.store.loadMany(this.get('model'), alertGroups);
       App.store.commit();
     }

+ 7 - 1
ambari-web/app/mappers/alert_notification_mapper.js

@@ -31,9 +31,15 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
       var result = [];
       var notificationsProperties = {};
       var notificationsAlertStates = {};
+      var groupsMap = App.cache['alertNotificationsGroupsMap'];
 
       json.items.forEach(function (item) {
-        result.push(this.parseIt(item, this.config));
+        var notification = this.parseIt(item, this.config);
+        var groups = groupsMap && groupsMap[notification.id];
+        if (groups) {
+          notification.groups = groups;
+        }
+        result.push(notification);
         notificationsProperties[item.AlertTarget.id] = item.AlertTarget.properties;
         notificationsAlertStates[item.AlertTarget.id] = item.AlertTarget.alert_states;
       }, this);

+ 1 - 0
ambari-web/app/models/alert_notification.js

@@ -23,6 +23,7 @@ App.AlertNotification = DS.Model.extend({
   name: DS.attr('string'),
   type: DS.attr('string'),
   description: DS.attr('string'),
+  groups: DS.hasMany('App.AlertGroup'),
 
   properties: {},
   alertStates: []

+ 1 - 2
ambari-web/app/views/main/alerts/manage_alert_notifications_view.js

@@ -28,8 +28,7 @@ App.ManageAlertNotificationsView = Em.View.extend({
   selectedAlertNotification: null,
 
   selectedAlertNotificationGroups: function () {
-    //TODO: Implement binding to AlertGroups
-    return ['Group1', 'Group2'].join(', ');
+    return this.get('controller.selectedAlertNotification.groups').toArray().mapProperty('name').join(', ');
   }.property('controller.selectedAlertNotification'),
 
   isEditButtonDisabled: true,