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/06/06 17:54:54 UTC

[ambari] branch trunk updated: AMBARI-24044. Widget Browser add/hide functionality is not working correctly (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 269db6f  AMBARI-24044. Widget Browser add/hide functionality is not working correctly (akovalenko)
269db6f is described below

commit 269db6f5f44545225addd1a05fb7985378e4087c
Author: Aleksandr Kovalenko <ak...@apache.org>
AuthorDate: Wed Jun 6 18:49:12 2018 +0300

    AMBARI-24044. Widget Browser add/hide functionality is not working correctly (akovalenko)
---
 .../app/controllers/main/service/info/metric.js    | 104 ++++++++++++++-------
 .../common/modal_popups/widget_browser_popup.hbs   |   2 +-
 2 files changed, 71 insertions(+), 35 deletions(-)

diff --git a/ambari-web/app/controllers/main/service/info/metric.js b/ambari-web/app/controllers/main/service/info/metric.js
index 349f1ef..d5bff81 100644
--- a/ambari-web/app/controllers/main/service/info/metric.js
+++ b/ambari-web/app/controllers/main/service/info/metric.js
@@ -92,6 +92,7 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
    */
   loadAllSharedWidgetsSuccessCallback: function (data) {
     var widgetIds = this.get('widgets').mapProperty('id');
+    var activeNSWidgetLayouts = this.get('activeNSWidgetLayouts');
     if (data.items[0] && data.items.length) {
       this.set("allSharedWidgets",
         data.items.filter(function (widget) {
@@ -99,17 +100,23 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
         }).map(function (widget) {
           var widgetType = widget.WidgetInfo.widget_type;
           var widgetName = widget.WidgetInfo.widget_name;
-          var widgetId =  widget.WidgetInfo.id;
+          var widgetId = widget.WidgetInfo.id;
+          var widgetTag = widget.WidgetInfo.tag;
+          var inNSLayouts = false;
+          if (widgetTag) {
+            inNSLayouts = activeNSWidgetLayouts.findProperty('nameServiceId', widgetTag).get('widgets').someProperty('id', widgetId) &&
+              activeNSWidgetLayouts.findProperty('nameServiceId', 'all').get('widgets').someProperty('id', widgetId);
+          }
           return Em.Object.create({
             id: widgetId,
             widgetName: widgetName,
-            tag: widget.WidgetInfo.tag,
+            tag: widgetTag,
             metrics: widget.WidgetInfo.metrics,
             description: widget.WidgetInfo.description,
             widgetType: widgetType,
             iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
             serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
-            added: widgetIds.contains(widgetId),
+            added: widgetTag ? inNSLayouts : widgetIds.contains(widgetId),
             isShared: widget.WidgetInfo.scope == "CLUSTER"
           });
         })
@@ -143,6 +150,7 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
    */
   loadMineWidgetsSuccessCallback: function (data) {
     var widgetIds = this.get('widgets').mapProperty('id');
+    var activeNSWidgetLayouts = this.get('activeNSWidgetLayouts');
     if (data.items[0] && data.items.length) {
       this.set("mineWidgets",
         data.items.filter(function (widget) {
@@ -150,17 +158,23 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
         }).map(function (widget) {
           var widgetType = widget.WidgetInfo.widget_type;
           var widgetName = widget.WidgetInfo.widget_name;
-          var widgetId =  widget.WidgetInfo.id;
+          var widgetId = widget.WidgetInfo.id;
+          var widgetTag = widget.WidgetInfo.tag;
+          var inNSLayouts = false;
+          if (widgetTag) {
+            inNSLayouts = activeNSWidgetLayouts.findProperty('nameServiceId', widgetTag).get('widgets').someProperty('id', widgetId) &&
+              activeNSWidgetLayouts.findProperty('nameServiceId', 'all').get('widgets').someProperty('id', widgetId);
+          }
           return Em.Object.create({
             id: widget.WidgetInfo.id,
             widgetName: widgetName,
-            tag: widget.WidgetInfo.tag,
+            tag: widgetTag,
             metrics: widget.WidgetInfo.metrics,
             description: widget.WidgetInfo.description,
             widgetType: widgetType,
             iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
             serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
-            added: widgetIds.contains(widgetId),
+            added: widgetTag ? inNSLayouts : widgetIds.contains(widgetId),
             isShared: widget.WidgetInfo.scope == "CLUSTER"
           });
         })
@@ -175,37 +189,59 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
    * add widgets, on click handler for "Add"
    */
   addWidget: function (event) {
+    var self = this;
     var widgetToAdd = event.context;
-    var activeLayout = this.get('activeWidgetLayout');
-    var widgetIds = activeLayout.get('widgets').map(function(widget) {
-      return {
-        "id": widget.get("id")
+    var activeLayouts = widgetToAdd.tag ? this.get('activeNSWidgetLayouts').filter(function (l) {
+      return ['all', widgetToAdd.tag].contains(l.get('nameServiceId'));
+    }) : [this.get('activeWidgetLayout')];
+    activeLayouts.forEach(function (activeLayout) {
+      var widgetIds = activeLayout.get('widgets').map(function(widget) {
+        return {
+          "id": widget.get("id")
+        }
+      });
+      if (!widgetIds.mapProperty('id').contains(widgetToAdd.id)) {
+        widgetIds.pushObject({
+          "id": widgetToAdd.id
+        });
+        var data = {
+          "WidgetLayoutInfo": {
+            "display_name": activeLayout.get("displayName"),
+            "id": activeLayout.get("id"),
+            "layout_name": activeLayout.get("layoutName"),
+            "scope": activeLayout.get("scope"),
+            "section_name": activeLayout.get("sectionName"),
+            "widgets": widgetIds
+          }
+        };
+
+        return App.ajax.send({
+          name: 'widget.layout.edit',
+          sender: self,
+          data: {
+            layoutId: activeLayout.get("id"),
+            data: data
+          },
+          success: 'updateActiveLayout'
+        });
       }
     });
-    widgetIds.pushObject({
-      "id": widgetToAdd.id
-    });
-    var data = {
-      "WidgetLayoutInfo": {
-        "display_name": activeLayout.get("displayName"),
-        "id": activeLayout.get("id"),
-        "layout_name": activeLayout.get("layoutName"),
-        "scope": activeLayout.get("scope"),
-        "section_name": activeLayout.get("sectionName"),
-        "widgets": widgetIds
-      }
-    };
 
-    widgetToAdd.set('added', !widgetToAdd.added);
-    return App.ajax.send({
-      name: 'widget.layout.edit',
-      sender: this,
-      data: {
-        layoutId: activeLayout.get("id"),
-        data: data
-      },
-      success: 'updateActiveLayout'
-    });
+    widgetToAdd.set('added', true);
+  },
+
+  /**
+   * find and hide widgets from all layouts
+   * @param event
+   */
+  hideWidgetBrowser: function (event) {
+    var activeLayouts = event.context.tag ? this.get('activeNSWidgetLayouts').filter(function (l) {
+      return l.get('widgets').mapProperty('id').contains(event.context.id);
+    }) : [this.get('activeWidgetLayout')];
+    activeLayouts.forEach(function(layout) {
+      event.context.nsLayout = layout;
+      this.hideWidget(event)
+    }, this);
   },
 
   /**
@@ -233,7 +269,7 @@ App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMix
       }
     };
 
-    widgetToHide.set('added', !widgetToHide.added);
+    widgetToHide.set('added', false);
     return App.ajax.send({
       name: 'widget.layout.edit',
       sender: this,
diff --git a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
index 52de96b..824a116 100644
--- a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
+++ b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
@@ -66,7 +66,7 @@
                     {{! buttons }}
                     <div class="widget-section-actions align-right">
                       {{#if widget.added}}
-                        <button type="button" class="btn added-btn" {{action "hideWidget" widget target="controller"}} >
+                        <button type="button" class="btn added-btn" {{action "hideWidgetBrowser" widget target="controller"}} >
                           <i class="glyphicon glyphicon-ok"></i> &nbsp; {{t dashboard.widgets.browser.action.added}}
                         </button>
                       {{else}}

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