浏览代码

AMBARI-12968. Hosts page 'clear filters' link does not work (rzang)

Richard Zang 9 年之前
父节点
当前提交
b838dcfb0d

+ 1 - 1
ambari-web/app/views/common/table_view.js

@@ -384,7 +384,7 @@ App.TableView = Em.View.extend(App.UserPref, {
     });
   },
 
-  clearFilterCondition: function() {
+  clearFilterConditionsFromLocalStorage: function() {
     var result = false;
     var currentFCs = App.db.getFilterConditions(this.get('controller.name'));
     if (currentFCs != null) {

+ 1 - 1
ambari-web/app/views/main/alert_definitions_view.js

@@ -38,7 +38,7 @@ App.MainAlertDefinitionsView = App.TableView.extend({
 
   willInsertElement: function () {
     if (!this.get('controller.showFilterConditionsFirstLoad')) {
-      this.clearFilterCondition();
+      this.clearFilterConditionsFromLocalStorage();
     }
     this._super();
   },

+ 19 - 2
ambari-web/app/views/main/host.js

@@ -181,7 +181,7 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, {
    */
   willInsertElement: function () {
     if (!this.get('controller.showFilterConditionsFirstLoad')) {
-      var didClearedSomething = this.clearFilterCondition();
+      var didClearedSomething = this.clearFilterConditionsFromLocalStorage();
       this.set('controller.filterChangeHappened', didClearedSomething);
     }
     this._super();
@@ -1174,5 +1174,22 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, {
    */
   colPropAssoc: function () {
     return this.get('controller.colPropAssoc');
-  }.property('controller.colPropAssoc')
+  }.property('controller.colPropAssoc'),
+
+  /**
+   * Run <code>clearFilter</code> in the each child filterView
+   */
+  clearFilters: function() {
+    // clean filters stored in-memory and local storage
+    this.set('filterConditions', []);
+    this.clearFilterConditionsFromLocalStorage();
+    // clean UI
+    this.get('_childViews').forEach(function(childView) {
+      if (childView['clearFilter']) {
+        childView.clearFilter();
+      }
+    });
+    // force refresh
+    this.refresh();
+  }
 });

+ 4 - 4
ambari-web/test/views/main/alert_definitions_view_test.js

@@ -40,23 +40,23 @@ describe('App.MainAlertDefinitionsView', function () {
   describe('#willInsertElement', function () {
 
     beforeEach(function(){
-      sinon.stub(view, 'clearFilterCondition', Em.K);
+      sinon.stub(view, 'clearFilterConditionsFromLocalStorage', Em.K);
     });
 
     afterEach(function(){
-      view.clearFilterCondition.restore();
+      view.clearFilterConditionsFromLocalStorage.restore();
     });
 
     it('should call clearFilterCondition if controller.showFilterConditionsFirstLoad is false', function () {
       view.set('controller', {showFilterConditionsFirstLoad: false, content: []});
       view.willInsertElement();
-      expect(view.clearFilterCondition.calledOnce).to.be.true;
+      expect(view.clearFilterConditionsFromLocalStorage.calledOnce).to.be.true;
     });
 
     it('should not call clearFilterCondition if controller.showFilterConditionsFirstLoad is true', function () {
       view.set('controller', {showFilterConditionsFirstLoad: true, content: []});
       view.willInsertElement();
-      expect(view.clearFilterCondition.calledOnce).to.be.false;
+      expect(view.clearFilterConditionsFromLocalStorage.calledOnce).to.be.false;
     });
   });