Repository: ambari
Updated Branches:
  refs/heads/trunk 5df4636fb -> c5cb5a16b


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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c5cb5a16
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c5cb5a16
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c5cb5a16

Branch: refs/heads/trunk
Commit: c5cb5a16bd0cf6abb0a335c86d2987f2e7a99398
Parents: 5df4636
Author: Aleksandr Kovalenko <[email protected]>
Authored: Tue Dec 23 19:56:58 2014 +0200
Committer: Aleksandr Kovalenko <[email protected]>
Committed: Tue Dec 23 19:56:58 2014 +0200

----------------------------------------------------------------------
 .../main/alert_definitions_controller.js        |  6 +++++
 .../alerts/definition_details_controller.js     |  1 +
 ambari-web/app/routes/main.js                   |  1 +
 ambari-web/app/views/common/filter_view.js      |  7 ++++++
 ambari-web/app/views/common/table_view.js       |  2 +-
 .../app/views/main/alert_definitions_view.js    | 25 +++++++++++++++++++-
 ambari-web/app/views/main/menu.js               |  2 ++
 .../views/main/alert_definitions_view_test.js   | 23 ++++++++++++++++++
 8 files changed, 65 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/controllers/main/alert_definitions_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alert_definitions_controller.js 
b/ambari-web/app/controllers/main/alert_definitions_controller.js
index 2a07dcc..ad1f6c6 100644
--- a/ambari-web/app/controllers/main/alert_definitions_controller.js
+++ b/ambari-web/app/controllers/main/alert_definitions_controller.js
@@ -30,6 +30,12 @@ App.MainAlertDefinitionsController = 
Em.ArrayController.extend({
   mapperTimestamp: null,
 
   /**
+   * Define whether restore filter conditions from local db
+   * @type {Boolean}
+   */
+  showFilterConditionsFirstLoad: false,
+
+  /**
    * List of all <code>App.AlertDefinition</code>
    * Consists of:
    * <ul>

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/controllers/main/alerts/definition_details_controller.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/app/controllers/main/alerts/definition_details_controller.js 
b/ambari-web/app/controllers/main/alerts/definition_details_controller.js
index 606c1f7..95be572 100644
--- a/ambari-web/app/controllers/main/alerts/definition_details_controller.js
+++ b/ambari-web/app/controllers/main/alerts/definition_details_controller.js
@@ -264,6 +264,7 @@ App.MainAlertDefinitionDetailsController = 
Em.Controller.extend({
    */
   goToHostAlerts: function (event) {
     if (event && event.context) {
+      App.router.get('mainHostDetailsController').set('referer', 
App.router.location.lastSetURL);
       App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 87fcf53..49060e4 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -332,6 +332,7 @@ module.exports = Em.Route.extend({
       route: '/:alert_definition_id',
 
       connectOutlets: function (router, alertDefinition) {
+        
App.router.set('mainAlertDefinitionsController.showFilterConditionsFirstLoad', 
true);
         
router.get('mainController').connectOutlet('mainAlertDefinitionDetails', 
alertDefinition);
       },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/views/common/filter_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/filter_view.js 
b/ambari-web/app/views/common/filter_view.js
index e3503bc..fac4b7c 100644
--- a/ambari-web/app/views/common/filter_view.js
+++ b/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();
   },
 
+  setValue: function (value) {
+    this.set('value', value);
+  },
+
   /**
    * Show/Hide <code>Clear filter</code> button.
    * Also this method updates computed field related to <code>fieldId</code> 
if it exists.
@@ -357,6 +361,9 @@ module.exports = {
     config.clearFilter = function () {
       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);
   },
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/views/common/table_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/table_view.js 
b/ambari-web/app/views/common/table_view.js
index 972ac5b..b17c011 100644
--- a/ambari-web/app/views/common/table_view.js
+++ b/ambari-web/app/views/common/table_view.js
@@ -114,7 +114,7 @@ App.TableView = Em.View.extend(App.UserPref, {
             view.clearFilter();
             self.saveFilterConditions(condition.iColumn, 
view.get('appliedEmptyValue'), condition.type, false);
           } else {
-            view.set('value', condition.value);
+            view.setValue(condition.value);
           }
           Em.run.next(function () {
             view.showClearFilter();

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js 
b/ambari-web/app/views/main/alert_definitions_view.js
index 4b655d1..8786c66 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -29,8 +29,19 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     return this.get('controller.content');
   }.property('controller.content.@each'),
 
+  willInsertElement: function () {
+    if (!this.get('controller.showFilterConditionsFirstLoad')) {
+      this.clearFilterCondition();
+    }
+    this._super();
+  },
+
   didInsertElement: function () {
+    var self = this;
     this.tooltipsUpdater();
+    Em.run.next(function () {
+      self.set('isInitialRendering', false);
+    });
   },
 
   /**
@@ -65,6 +76,12 @@ App.MainAlertDefinitionsView = App.TableView.extend({
   sortView: sort.wrapperView,
 
   /**
+   * Define whether initial view rendering has finished
+   * @type {Boolean}
+   */
+  isInitialRendering: true,
+
+  /**
    * Sorting header for <label>alertDefinition.label</label>
    * @type {Em.View}
    */
@@ -455,6 +472,12 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     Em.run.next(this, function () {
       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);
+    }
+  }
 
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/app/views/main/menu.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/menu.js 
b/ambari-web/app/views/main/menu.js
index 13a068d..4030f5e 100644
--- a/ambari-web/app/views/main/menu.js
+++ b/ambari-web/app/views/main/menu.js
@@ -105,6 +105,8 @@ App.MainMenuView = Em.CollectionView.extend({
       } else if (event.context === 'views') {
         App.router.route('views');
         return;
+      } else if (event.context === 'alerts') {
+        
App.router.set('mainAlertDefinitionsController.showFilterConditionsFirstLoad', 
false);
       }
       App.router.route('main/' + event.context);
     },

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5cb5a16/ambari-web/test/views/main/alert_definitions_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alert_definitions_view_test.js 
b/ambari-web/test/views/main/alert_definitions_view_test.js
index 47aee7f..0e8773c 100644
--- a/ambari-web/test/views/main/alert_definitions_view_test.js
+++ b/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;
+    });
+  });
+
 });

Reply via email to