瀏覽代碼

AMBARI-7861. Apps table contains two apps with equal names after app start. (onechiporenko)

Oleg Nechiporenko 10 年之前
父節點
當前提交
06f9816b7e

+ 2 - 3
contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js

@@ -230,7 +230,7 @@ App.SliderAppsMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
   parse: function (data) {
     var apps = [],
       self = this,
-      appsToDelete = App.SliderApp.store.all('sliderApp').get('content').mapProperty('id');
+      appsToDelete = App.SliderApp.store.all('sliderApp').mapBy('id');
 
     App.__container__.lookup('controller:application').set('hasConfigErrors', false);
 
@@ -277,9 +277,8 @@ App.SliderAppsMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
         })
       );
 
-      appsToDelete.splice(appsToDelete.indexOf(app.id), 1);
+      appsToDelete = appsToDelete.without(app.id);
     });
-
     appsToDelete.forEach(function (app) {
       var appRecord = App.SliderApp.store.getById('sliderApp', app);
       if (appRecord) {

+ 31 - 1
contrib/views/slider/src/main/resources/ui/test/unit/mappers/slider_apps_mapper_test.js

@@ -28,7 +28,7 @@ QUnit.module('App.SliderAppsMapper', {
 
 });
 
-test('App.SliderAppsMapper.parseQuickLinks', function () {
+test('parseQuickLinks', function () {
 
   var mapper = App.SliderAppsMapper;
 
@@ -53,3 +53,33 @@ test('App.SliderAppsMapper.parseQuickLinks', function () {
   equal(mapper.get('result')[0].get('id'), 'YARN application 1', 'model id set correctly');
 
 });
+
+test('parse | add/remove apps', function () {
+
+  Em.run(function () {
+
+    App.SliderAppsMapper.parse({
+      items: [
+        {id: '1', type: 't1'},
+        {id: '2', type: 't2'}
+      ]
+    });
+
+  });
+
+  deepEqual(App.SliderApp.store.all('sliderApp').mapBy('id'), ['1', '2'], 'Mapped all apps');
+
+  Em.run(function () {
+
+    App.SliderAppsMapper.parse({
+      items: [
+        {id: '2', type: 't2'},
+        {id: '3', type: 't3'}
+      ]
+    });
+
+  });
+
+  deepEqual(App.SliderApp.store.all('sliderApp').mapBy('id'), ['2', '3'], 'Delete not-existing app and add new');
+
+});