AMBARI-23721 Adding and deleting widgets of NameNode section on dashboard isn't persi...
authorababiichuk <ababiichuk@hortonworks.com>
Fri, 27 Apr 2018 18:20:09 +0000 (21:20 +0300)
committeraBabiichuk <ababiichuk@hortonworks.com>
Sat, 28 Apr 2018 07:24:20 +0000 (10:24 +0300)
ambari-web/app/views/main/dashboard/widgets.js
ambari-web/test/views/main/dashboard/widget_test.js

index 64412f3..3fcee73 100644 (file)
@@ -209,11 +209,51 @@ App.MainDashboardWidgetsView = Em.View.extend(App.Persist, App.LocalStorage, App
     }
     else {
       newSettings.threshold = userPreferences.threshold;
-      newSettings.groups = userPreferences.groups;
       this.get('allWidgets').forEach(widget => {
-        let key = widget.get('isVisible') ? 'visible' : 'hidden';
+        const key = widget.get('isVisible') ? 'visible' : 'hidden';
         newSettings[key].push(widget.get('id'));
       });
+      this.get('widgetGroups').forEach(group => {
+        const groupName = group.get('name');
+        if (!newSettings.groups[groupName]) {
+          newSettings.groups[groupName] = {};
+        }
+        group.get('allWidgets').forEach(widgetsSubGroup => {
+          const subGroupName = widgetsSubGroup.get('subGroupName'),
+            widgets = widgetsSubGroup.get('widgets'),
+            subGroupSettings = {
+              visible: [],
+              hidden: [],
+              threshold: {}
+            };
+          newSettings.groups[groupName][subGroupName] = subGroupSettings;
+          widgets.forEach(widget => {
+            const key = widget.get('isVisible') ? 'visible' : 'hidden',
+              threshold = widget.get('threshold'),
+              widgetId = widget.get('id'),
+              id = parseInt(widgetId);
+            if (subGroupName === '*') {
+              const regExp = new RegExp(`\\d+\\-${groupName}\\-([\\W\\w]+)\\-\\*`),
+                regExpMatch = widgetId.match(regExp),
+                subGroup = regExpMatch && regExpMatch[1];
+              if (subGroup) {
+                subGroupSettings[key].push({
+                  id,
+                  subGroup
+                });
+                $.extend(true, subGroupSettings.threshold, {
+                  [subGroup]: {
+                    [id]: threshold
+                  }
+                });
+              }
+            } else {
+              subGroupSettings[key].push(id);
+              subGroupSettings.threshold[id] = threshold;
+            }
+          });
+        });
+      });
     }
     this.set('userPreferences', newSettings);
     this.setDBProperty(this.get('persistKey'), newSettings);
index 8a28d19..f63ec00 100644 (file)
@@ -136,14 +136,22 @@ describe('App.DashboardWidgetView', function () {
   describe('#deleteWidget()', function() {
 
     beforeEach(function() {
-      view.get('parentView').set('allWidgets', [Em.Object.create({id: 1, isVisible: true})]);
-      view.set('widget.id', 1);
-      view.set('parentView.userPreferences', {
-        visible: [1],
-        hidden: [],
-        threshold: [],
-        groups: {}
+      view.get('parentView').setProperties({
+        allWidgets: [
+          Em.Object.create({
+            id: 1,
+            isVisible: true
+          })
+        ],
+        userPreferences: {
+          visible: [1],
+          hidden: [],
+          threshold: [],
+          groups: {}
+        },
+        widgetGroups: []
       });
+      view.set('widget.id', 1);
       view.deleteWidget();
     });