You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2018/05/30 16:32:18 UTC

[ambari] branch trunk updated: AMBARI-23981. HDFS Summary widgets disappear after changing widgets order (akovalenko)

This is an automated email from the ASF dual-hosted git repository.

akovalenko pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1909c7b  AMBARI-23981. HDFS Summary widgets disappear after changing widgets order (akovalenko)
1909c7b is described below

commit 1909c7b55d859200589c94d6f26d090d0c7deed5
Author: Aleksandr Kovalenko <ak...@apache.org>
AuthorDate: Wed May 30 18:30:54 2018 +0300

    AMBARI-23981. HDFS Summary widgets disappear after changing widgets order (akovalenko)
---
 .../app/views/main/service/info/metrics_view.js    | 38 ++++++----------------
 .../views/main/service/info/metrics_view_test.js   |  6 ++--
 2 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/ambari-web/app/views/main/service/info/metrics_view.js b/ambari-web/app/views/main/service/info/metrics_view.js
index 2d13747..450410e 100644
--- a/ambari-web/app/views/main/service/info/metrics_view.js
+++ b/ambari-web/app/views/main/service/info/metrics_view.js
@@ -97,7 +97,8 @@ App.MainServiceInfoMetricsView = Em.View.extend(App.Persist, App.TimeRangeMixin,
       var allServices = require('data/service_graph_config');
       this.constructGraphObjects(allServices[svcName.toLowerCase()]);
     }
-    this.makeSortable();
+    this.makeSortable('#widget_layout');
+    this.makeSortable('#ns_widget_layout', true);
     this.addWidgetTooltip();
   },
 
@@ -275,19 +276,21 @@ App.MainServiceInfoMetricsView = Em.View.extend(App.Persist, App.TimeRangeMixin,
   /**
    * Make widgets' list sortable on New Dashboard style
    */
-  makeSortable: function () {
+  makeSortable: function (selector, isNSLayout) {
     var self = this;
-    $('html').on('DOMNodeInserted', '#widget_layout', function () {
+    var controller = this.get('controller');
+    $('html').on('DOMNodeInserted', selector, function () {
       $(this).sortable({
         items: "> div",
         cursor: "move",
         tolerance: "pointer",
         scroll: false,
         update: function () {
-          var widgets = misc.sortByOrder($("#widget_layout .widget").map(function () {
+          var layout = isNSLayout ? controller.get('selectedNSWidgetLayout') : controller.get('activeWidgetLayout');
+          var widgets = misc.sortByOrder($(selector + " .widget").map(function () {
             return this.id;
-          }), self.get('controller.widgets'));
-          self.get('controller').saveWidgetLayout(widgets);
+          }), layout.get('widgets').toArray());
+          controller.saveWidgetLayout(widgets, layout);
         },
         activate: function () {
           self.set('isMoving', true);
@@ -296,28 +299,7 @@ App.MainServiceInfoMetricsView = Em.View.extend(App.Persist, App.TimeRangeMixin,
           self.set('isMoving', false);
         }
       }).disableSelection();
-      $('html').off('DOMNodeInserted', '#widget_layout');
-    });
-    $('html').on('DOMNodeInserted', '#ns_widget_layout', function () {
-      $(this).sortable({
-        items: "> div",
-        cursor: "move",
-        tolerance: "pointer",
-        scroll: false,
-        update: function () {
-          var widgets = misc.sortByOrder($("#ns_widget_layout .widget").map(function () {
-            return this.id;
-          }), self.get('controller.widgets'));
-          self.get('controller').saveWidgetLayout(widgets);
-        },
-        activate: function () {
-          self.set('isMoving', true);
-        },
-        deactivate: function () {
-          self.set('isMoving', false);
-        }
-      }).disableSelection();
-      $('html').off('DOMNodeInserted', '#ns_widget_layout');
+      $('html').off('DOMNodeInserted', selector);
     });
   }
 });
diff --git a/ambari-web/test/views/main/service/info/metrics_view_test.js b/ambari-web/test/views/main/service/info/metrics_view_test.js
index 8e0024d..99442f1 100644
--- a/ambari-web/test/views/main/service/info/metrics_view_test.js
+++ b/ambari-web/test/views/main/service/info/metrics_view_test.js
@@ -206,7 +206,6 @@ describe('App.MainServiceInfoMetricsView', function() {
       sinon.spy(mock, 'on');
       sinon.spy(mock, 'off');
       sinon.spy(mock, 'sortable');
-      view.makeSortable();
     });
     afterEach(function() {
       window.$.restore();
@@ -216,14 +215,17 @@ describe('App.MainServiceInfoMetricsView', function() {
     });
 
     it("on() should be called", function() {
+      view.makeSortable('#widget_layout');
       expect(mock.on.calledWith('DOMNodeInserted', '#widget_layout')).to.be.true;
     });
 
     it("sortable() should be called", function() {
+      view.makeSortable('#widget_layout');
       expect(mock.sortable.called).to.be.true;
     });
 
     it("off() should be called", function() {
+      view.makeSortable('#widget_layout');
       expect(mock.off.calledWith('DOMNodeInserted', '#widget_layout')).to.be.true;
     });
   });
@@ -261,7 +263,7 @@ describe('App.MainServiceInfoMetricsView', function() {
     });
     it("makeSortable should be called", function() {
       view.didInsertElement();
-      expect(view.makeSortable.calledOnce).to.be.true;
+      expect(view.makeSortable.called).to.be.true;
     });
     it("loadActiveWidgetLayout should be called", function() {
       view.didInsertElement();

-- 
To stop receiving notification emails like this one, please contact
akovalenko@apache.org.