Repository: ambari
Updated Branches:
  refs/heads/trunk e35126fed -> d5d9a9dfb


AMBARI-8395. Alerts UI. AlertGroupsMapper doesn't delete not existing groups 
(onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d5d9a9df
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d5d9a9df
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d5d9a9df

Branch: refs/heads/trunk
Commit: d5d9a9dfb842c24f88f38e7c8a8469c741f9284e
Parents: e35126f
Author: Oleg Nechiporenko <onechipore...@apache.org>
Authored: Thu Nov 20 15:05:06 2014 +0200
Committer: Oleg Nechiporenko <onechipore...@apache.org>
Committed: Thu Nov 20 15:05:06 2014 +0200

----------------------------------------------------------------------
 ambari-web/app/mappers/alert_groups_mapper.js   |  6 +++
 .../app/views/main/alert_definitions_view.js    | 17 +--------
 .../test/mappers/alert_groups_mapper_test.js    | 40 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d5d9a9df/ambari-web/app/mappers/alert_groups_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_groups_mapper.js 
b/ambari-web/app/mappers/alert_groups_mapper.js
index d88fa52..e5eebef 100644
--- a/ambari-web/app/mappers/alert_groups_mapper.js
+++ b/ambari-web/app/mappers/alert_groups_mapper.js
@@ -53,6 +53,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
 
       var alertGroups = [],
         self = this,
+        groupsToDelete = App.AlertGroup.find().mapProperty('id'),
         typesMap = this.get('typesMap'),
         /**
          * AlertGroups-map for <code>App.AlertDefinitionsMappers</code>
@@ -70,6 +71,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
 
       json.items.forEach(function(item) {
         var group = self.parseIt(item, self.get('config'));
+        groupsToDelete = groupsToDelete.without(group.id);
         Em.keys(typesMap).forEach(function(k) {
           group[typesMap[k]] = [];
         });
@@ -88,6 +90,10 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
         alertGroups.push(group);
       }, this);
 
+      groupsToDelete.forEach(function(groupId) {
+        self.deleteRecord(App.AlertGroup.find(groupId));
+      });
+
       App.cache['previousAlertGroupsMap'] = alertDefinitionsGroupsMap;
       App.store.loadMany(this.get('model'), alertGroups);
       App.store.commit();

http://git-wip-us.apache.org/repos/asf/ambari/blob/d5d9a9df/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js 
b/ambari-web/app/views/main/alert_definitions_view.js
index ec9e75b..6957caf 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -220,8 +220,7 @@ App.MainAlertDefinitionsView = App.TableView.extend({
      * @method updateContent
      */
     updateContent: function() {
-      var content = this.get('content');
-      var newContent = [
+      this.set('content', [
         {
           value: '',
           label: Em.I18n.t('common.all') + ' (' + 
this.get('parentView.controller.content.length') + ')'
@@ -231,19 +230,7 @@ App.MainAlertDefinitionsView = App.TableView.extend({
           value: group.get('id'),
           label: group.get('displayNameDefinitions')
         };
-      }));
-      newContent.forEach(function(contentItem) {
-        var c = content.findProperty('value', contentItem.value);
-        if (!c) {
-          content.pushObject(contentItem);
-        }
-      });
-      content.mapProperty('value').forEach(function(v) {
-        if (!newContent.someProperty('value', v)) {
-          content = content.without(content.findProperty('value', v));
-        }
-      });
-      this.propertyDidChange('content');
+      })));
     }.observes('App.router.clusterController.isLoaded', 
'controller.mapperTimestamp'),
 
     onChangeValue: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/d5d9a9df/ambari-web/test/mappers/alert_groups_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/alert_groups_mapper_test.js 
b/ambari-web/test/mappers/alert_groups_mapper_test.js
index b30747d..09b169f 100644
--- a/ambari-web/test/mappers/alert_groups_mapper_test.js
+++ b/ambari-web/test/mappers/alert_groups_mapper_test.js
@@ -157,6 +157,46 @@ describe('App.alertGroupsMapper', function () {
 
     });
 
+    describe('should delete not existing groups', function () {
+
+      var groups = [
+        {id: 1},
+        {id: 2},
+        {id: 3},
+        {id: 4}
+      ];
+
+      beforeEach(function () {
+
+        sinon.stub(App.AlertGroup, 'find', function() {
+          if (arguments.length) {
+            return groups.findProperty('id', arguments[0]);
+          }
+          return groups;
+        });
+
+        sinon.stub(App.alertGroupsMapper, 'deleteRecord', Em.K);
+
+      });
+
+      afterEach(function () {
+        App.AlertGroup.find.restore();
+        App.alertGroupsMapper.deleteRecord.restore();
+      });
+
+      it('should call deleteRecord with not existing groups', function () {
+
+        App.alertGroupsMapper.map(json);
+        expect(App.alertGroupsMapper.deleteRecord.calledTwice).to.be.true;
+        // first call
+        expect(App.alertGroupsMapper.deleteRecord.args[0][0].id).to.equal(1);
+        // second call
+        expect(App.alertGroupsMapper.deleteRecord.args[1][0].id).to.equal(4);
+
+      });
+
+    });
+
   });
 
 });
\ No newline at end of file

Reply via email to