Selaa lähdekoodia

AMBARI-9057. Alerts UI: need to preserve filtering, sorting and paging results (onechiporenko)

Oleg Nechiporenko 10 vuotta sitten
vanhempi
commit
0e8b717b24

+ 1 - 3
ambari-web/app/views/common/filter_view.js

@@ -142,9 +142,7 @@ var wrapperView = Ember.View.extend({
   /**
    * Callback for value changes
    */
-  onChangeValue: function () {
-
-  },
+  onChangeValue: Em.K,
 
   /**
    * Filter components is located here. Should be redefined

+ 31 - 0
ambari-web/app/views/main/alert_definitions_view.js

@@ -32,7 +32,22 @@ App.MainAlertDefinitionsView = App.TableView.extend({
   willInsertElement: function () {
     if (!this.get('controller.showFilterConditionsFirstLoad')) {
       this.clearFilterCondition();
+      this.clearStartIndex();
     }
+    this.removeObserver('filteredCount', this, 'updatePaging');
+    this.removeObserver('displayLength', this, 'updatePaging');
+    var startIndex = App.db.getStartIndex(this.get('controller.name'));
+    this._super();
+    this.set('startIndex', startIndex ? startIndex : 1);
+    this.addObserver('filteredCount', this, 'updatePaging');
+    this.addObserver('displayLength', this, 'updatePaging');
+  },
+
+  /**
+   * Method is same as in the parentView, but observes are set in the <code>willInsertElement</code>
+   * and not in the declaration
+   */
+  updatePaging: function () {
     this._super();
   },
 
@@ -44,6 +59,22 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     });
   },
 
+  /**
+   * Save <code>startIndex</code> to the localStorage
+   * @method saveStartIndex
+   */
+  saveStartIndex: function() {
+    App.db.setStartIndex(this.get('controller.name'), this.get('startIndex'));
+  }.observes('startIndex'),
+
+  /**
+   * Clear <code>startIndex</code> from the localStorage
+   * @method clearStartIndex
+   */
+  clearStartIndex: function () {
+    App.db.setStartIndex(this.get('controller.name'), null);
+  },
+
   /**
    * @type {number}
    */

+ 7 - 3
ambari-web/test/views/main/alert_definitions_view_test.js

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