Browse Source

AMBARI-8892. Alert / Host Navigation: Back doesn't work as expected. (akovalenko)

Aleksandr Kovalenko 10 years ago
parent
commit
c5cb5a16bd

+ 6 - 0
ambari-web/app/controllers/main/alert_definitions_controller.js

@@ -29,6 +29,12 @@ App.MainAlertDefinitionsController = Em.ArrayController.extend({
    */
    */
   mapperTimestamp: null,
   mapperTimestamp: null,
 
 
+  /**
+   * Define whether restore filter conditions from local db
+   * @type {Boolean}
+   */
+  showFilterConditionsFirstLoad: false,
+
   /**
   /**
    * List of all <code>App.AlertDefinition</code>
    * List of all <code>App.AlertDefinition</code>
    * Consists of:
    * Consists of:

+ 1 - 0
ambari-web/app/controllers/main/alerts/definition_details_controller.js

@@ -264,6 +264,7 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({
    */
    */
   goToHostAlerts: function (event) {
   goToHostAlerts: function (event) {
     if (event && event.context) {
     if (event && event.context) {
+      App.router.get('mainHostDetailsController').set('referer', App.router.location.lastSetURL);
       App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
       App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
     }
     }
   }
   }

+ 1 - 0
ambari-web/app/routes/main.js

@@ -332,6 +332,7 @@ module.exports = Em.Route.extend({
       route: '/:alert_definition_id',
       route: '/:alert_definition_id',
 
 
       connectOutlets: function (router, alertDefinition) {
       connectOutlets: function (router, alertDefinition) {
+        App.router.set('mainAlertDefinitionsController.showFilterConditionsFirstLoad', true);
         router.get('mainController').connectOutlet('mainAlertDefinitionDetails', alertDefinition);
         router.get('mainController').connectOutlet('mainAlertDefinitionDetails', alertDefinition);
       },
       },
 
 

+ 7 - 0
ambari-web/app/views/common/filter_view.js

@@ -106,6 +106,10 @@ var wrapperView = Ember.View.extend({
     return this.get('value').toString() === this.get('emptyValue').toString();
     return this.get('value').toString() === this.get('emptyValue').toString();
   },
   },
 
 
+  setValue: function (value) {
+    this.set('value', value);
+  },
+
   /**
   /**
    * Show/Hide <code>Clear filter</code> button.
    * Show/Hide <code>Clear filter</code> button.
    * Also this method updates computed field related to <code>fieldId</code> if it exists.
    * Also this method updates computed field related to <code>fieldId</code> if it exists.
@@ -357,6 +361,9 @@ module.exports = {
     config.clearFilter = function () {
     config.clearFilter = function () {
       this.set('selected', this.get('content').findProperty('value', this.get('emptyValue')));
       this.set('selected', this.get('content').findProperty('value', this.get('emptyValue')));
     };
     };
+    config.setValue = function (value) {
+      this.set('selected', this.get('content').findProperty('value', value));
+    };
     return wrapperView.extend(config);
     return wrapperView.extend(config);
   },
   },
   /**
   /**

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

@@ -114,7 +114,7 @@ App.TableView = Em.View.extend(App.UserPref, {
             view.clearFilter();
             view.clearFilter();
             self.saveFilterConditions(condition.iColumn, view.get('appliedEmptyValue'), condition.type, false);
             self.saveFilterConditions(condition.iColumn, view.get('appliedEmptyValue'), condition.type, false);
           } else {
           } else {
-            view.set('value', condition.value);
+            view.setValue(condition.value);
           }
           }
           Em.run.next(function () {
           Em.run.next(function () {
             view.showClearFilter();
             view.showClearFilter();

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

@@ -29,8 +29,19 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     return this.get('controller.content');
     return this.get('controller.content');
   }.property('controller.content.@each'),
   }.property('controller.content.@each'),
 
 
+  willInsertElement: function () {
+    if (!this.get('controller.showFilterConditionsFirstLoad')) {
+      this.clearFilterCondition();
+    }
+    this._super();
+  },
+
   didInsertElement: function () {
   didInsertElement: function () {
+    var self = this;
     this.tooltipsUpdater();
     this.tooltipsUpdater();
+    Em.run.next(function () {
+      self.set('isInitialRendering', false);
+    });
   },
   },
 
 
   /**
   /**
@@ -64,6 +75,12 @@ App.MainAlertDefinitionsView = App.TableView.extend({
 
 
   sortView: sort.wrapperView,
   sortView: sort.wrapperView,
 
 
+  /**
+   * Define whether initial view rendering has finished
+   * @type {Boolean}
+   */
+  isInitialRendering: true,
+
   /**
   /**
    * Sorting header for <label>alertDefinition.label</label>
    * Sorting header for <label>alertDefinition.label</label>
    * @type {Em.View}
    * @type {Em.View}
@@ -455,6 +472,12 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     Em.run.next(this, function () {
     Em.run.next(this, function () {
       App.tooltip($(".enable-disable-button, .timeago"));
       App.tooltip($(".enable-disable-button, .timeago"));
     });
     });
-  }.observes('pageContent.@each')
+  }.observes('pageContent.@each'),
+
+  updateFilter: function (iColumn, value, type) {
+    if (!this.get('isInitialRendering')) {
+      this._super(iColumn, value, type);
+    }
+  }
 
 
 });
 });

+ 2 - 0
ambari-web/app/views/main/menu.js

@@ -105,6 +105,8 @@ App.MainMenuView = Em.CollectionView.extend({
       } else if (event.context === 'views') {
       } else if (event.context === 'views') {
         App.router.route('views');
         App.router.route('views');
         return;
         return;
+      } else if (event.context === 'alerts') {
+        App.router.set('mainAlertDefinitionsController.showFilterConditionsFirstLoad', false);
       }
       }
       App.router.route('main/' + event.context);
       App.router.route('main/' + event.context);
     },
     },

+ 23 - 0
ambari-web/test/views/main/alert_definitions_view_test.js

@@ -37,4 +37,27 @@ describe('App.MainAlertDefinitionsView', function () {
     });
     });
   });
   });
 
 
+  describe('#willInsertElement', function () {
+
+    beforeEach(function(){
+      sinon.stub(view, 'clearFilterCondition', Em.K);
+    });
+
+    afterEach(function(){
+      view.clearFilterCondition.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;
+    });
+
+    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;
+    });
+  });
+
 });
 });