소스 검색

AMBARI-12621 FE: Going to a service heatmap makes a call to old heatmap first. (atkach)

Andrii Tkach 10 년 전
부모
커밋
a471f3391a

+ 1 - 0
ambari-web/app/assets/test/tests.js

@@ -231,6 +231,7 @@ var files = ['test/init_model_test',
   'test/views/main/host/details/host_component_views/nodemanager_view_test',
   'test/views/main/host/details/host_component_views/regionserver_view_test',
   'test/views/main/host/details/host_component_views/tasktracker_view_test',
+  'test/views/main/charts/heatmap_test',
   'test/views/main/charts/heatmap/heatmap_host_test',
   'test/views/main/service/item_test',
   'test/views/main/service/info/config_test',

+ 7 - 6
ambari-web/app/controllers/main/charts/heatmap.js

@@ -68,15 +68,15 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin, {
 
 
   /**
-   * This function is called from the binded view of the controller
+   * This function is called from the bound view of the controller
    */
   loadPageData: function () {
     var self = this;
-    this.loadRacks().done(function (data) {
-      self.set('isLoaded', true);
-      self.loadRacksSuccessCallback(data);
+
+    this.loadRacks().always(function () {
       self.resetPageData();
       self.getAllHeatMaps().done(function (allHeatmapData) {
+        self.set('isLoaded', true);
         allHeatmapData.items.forEach(function (_allHeatmapData) {
           self.get('allHeatmaps').pushObject(_allHeatmapData.WidgetInfo);
         });
@@ -93,7 +93,7 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin, {
    * @return {Array}
    */
   categorizeByServiceName: function(allHeatmaps) {
-  var categories = [];
+    var categories = [];
     allHeatmaps.forEach(function(_heatmap){
     var serviceNames = JSON.parse(_heatmap.metrics).mapProperty('service_name').uniq();
       serviceNames.forEach(function(_serviceName){
@@ -150,7 +150,8 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin, {
       sender: this,
       data: {
         urlParams: urlParams
-      }
+      },
+      success: 'loadRacksSuccessCallback'
     });
   },
 

+ 7 - 0
ambari-web/app/mixins/common/widgets/widget_section.js

@@ -263,5 +263,12 @@ App.WidgetSectionMixin = Ember.Mixin.create({
         data: data
       }
     });
+  },
+
+  /**
+   * After closing widget section, layout should be reset
+   */
+  clearActiveWidgetLayout: function () {
+    this.set('activeWidgetLayout', {});
   }
 });

+ 1 - 4
ambari-web/app/routes/main.js

@@ -663,10 +663,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
           router.get('mainController').dataLoading().done(function () {
             var item = router.get('mainServiceItemController.content');
             if (item.get('isLoaded')) {
-              router.get('mainServiceInfoHeatmapController').loadRacks().done(function (data) {
-                router.get('mainServiceInfoHeatmapController').loadRacksSuccessCallback(data);
-                router.get('mainServiceItemController').connectOutlet('mainServiceInfoHeatmap', item);
-              });
+              router.get('mainServiceItemController').connectOutlet('mainServiceInfoHeatmap', item);
             } else {
               item.set('routeToHeatmaps', true);
               router.transitionTo('services.index');

+ 6 - 1
ambari-web/app/views/main/charts/heatmap.js

@@ -26,5 +26,10 @@ App.MainChartsHeatmapView = Em.View.extend({
   },
   dropdownView: Em.View.extend({
     templateName: require('templates/main/charts/heatmap_dropdown')
-  })
+  }),
+
+  willDestroyElement: function () {
+    this._super();
+    this.get('controller').clearActiveWidgetLayout();
+  }
 });

+ 63 - 0
ambari-web/test/views/main/charts/heatmap_test.js

@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+var App = require('app');
+require('views/main/charts/heatmap');
+
+describe('App.MainChartsHeatmapView', function () {
+
+  var view;
+
+  beforeEach(function () {
+    view = App.MainChartsHeatmapView.create({
+      controller: Em.Object.create({
+        clearActiveWidgetLayout: Em.K,
+        loadPageData: Em.K
+      })
+    });
+  });
+
+
+  describe("#didInsertElement()", function () {
+    beforeEach(function () {
+      sinon.spy(view.get('controller'), 'loadPageData');
+    });
+    afterEach(function () {
+      view.get('controller').loadPageData.restore();
+    });
+    it("", function () {
+      view.didInsertElement();
+      expect(view.get('controller').loadPageData.calledOnce).to.be.true;
+    });
+  });
+
+  describe("#willDestroyElement()", function () {
+    beforeEach(function () {
+      sinon.spy(view.get('controller'), 'clearActiveWidgetLayout');
+    });
+    afterEach(function () {
+      view.get('controller').clearActiveWidgetLayout.restore();
+    });
+    it("", function () {
+      view.willDestroyElement();
+      expect(view.get('controller').clearActiveWidgetLayout.calledOnce).to.be.true;
+    });
+  });
+
+});