瀏覽代碼

AMBARI-9899. Resource Manager Dashboard widget thresholds null after upgrade (alexantonenko)

Alex Antonenko 10 年之前
父節點
當前提交
81209311ef

+ 5 - 3
ambari-web/app/views/common/table_view.js

@@ -86,9 +86,11 @@ App.TableView = Em.View.extend(App.UserPref, {
           self.initFilters();
         });
       } else {
-        this.getUserPref(this.displayLengthKey()).complete(function () {
-          self.initFilters();
-        });
+        if (!$.mocho) {
+          this.getUserPref(this.displayLengthKey()).complete(function () {
+            self.initFilters();
+          });
+        }
       }
     }
   },

+ 9 - 0
ambari-web/app/views/main/dashboard/widgets.js

@@ -477,6 +477,15 @@ App.MainDashboardWidgetsView = Em.View.extend(App.UserPref, App.LocalStorage, {
   getUserPrefSuccessCallback: function (response, request, data) {
     if (response) {
       console.log('Got persist value from server with key ' + data.key + '. Value is: ' + response);
+      var initPrefObject = this.get('initPrefObject');
+      initPrefObject.get('threshold');
+      for(var k in response.threshold) {
+        if (response.threshold.hasOwnProperty(k)) {
+          if (response.threshold[k].length === 0 && initPrefObject.get('threshold')[k] && initPrefObject.get('threshold')[k].length) {
+            response.threshold[k] = initPrefObject.get('threshold')[k];
+          }
+        }
+      }
       this.set('currentPrefObject', response);
     }
   },

+ 2 - 2
ambari-web/test/views/main/dashboard/widget_test.js

@@ -23,7 +23,7 @@ describe('App.DashboardWidgetView', function () {
   var dashboardWidgetView = App.DashboardWidgetView.create({
     parentView: Em.Object.create({
       widgetsMapper: Em.K,
-      getUserPref: Em.K,
+      getUserPref: function () {return {complete: Em.K}},
       postUserPref: Em.K,
       translateToReal: Em.K,
       visibleWidgets: [],
@@ -404,4 +404,4 @@ describe('App.DashboardWidgetView', function () {
       });
     });
   });
-});
+});

+ 16 - 1
ambari-web/test/views/main/dashboard/widgets_test.js

@@ -414,16 +414,31 @@ describe('App.MainDashboardWidgetsView', function () {
   });
 
   describe("#getUserPrefSuccessCallback()", function () {
+
     it("response is null", function () {
       view.set('currentPrefObject', null);
       view.getUserPrefSuccessCallback(null, {}, {});
       expect(view.get('currentPrefObject')).to.be.null;
     });
+
     it("response is correct", function () {
       view.set('currentPrefObject', null);
       view.getUserPrefSuccessCallback({}, {}, {});
       expect(view.get('currentPrefObject')).to.eql({});
     });
+
+    it('should update missing thresholds', function () {
+
+      view.set('currentPrefObject', null);
+      view.getUserPrefSuccessCallback({
+        threshold: {
+          17: []
+        }
+      }, {}, {});
+      expect(view.get('currentPrefObject.threshold')['17']).to.eql([70, 90]);
+
+    });
+
   });
 
   describe("#resetAllWidgets()", function () {
@@ -499,4 +514,4 @@ describe('App.MainDashboardWidgetsView', function () {
     });
 
   });
-});
+});