ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject git commit: AMBARI-5964 Integrate server-side filtering of selected hosts. (atkach)
Date Fri, 30 May 2014 15:53:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 954a9cbb8 -> 38e18b371


AMBARI-5964 Integrate server-side filtering of selected hosts. (atkach)


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

Branch: refs/heads/trunk
Commit: 38e18b371e40d4d967d5f3f1c68abe96c8aa1d90
Parents: 954a9cb
Author: atkach <atkach@hortonworks.com>
Authored: Fri May 30 18:50:40 2014 +0300
Committer: atkach <atkach@hortonworks.com>
Committed: Fri May 30 18:50:40 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/controllers/main/host.js         |   9 +-
 ambari-web/app/data/host/categories.js          |  13 --
 ambari-web/app/mappers/status_mapper.js         |   5 +
 .../app/mixins/common/tableServerProvider.js    |  22 ++-
 ambari-web/app/templates/main/host.hbs          |  12 +-
 ambari-web/app/views/main/host.js               | 154 +++++++++----------
 6 files changed, 102 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/controllers/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host.js b/ambari-web/app/controllers/main/host.js
index 4378256..07e7f10 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -115,6 +115,11 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, {
       key: 'componentsInPassiveStateCount',
       alias: 'host_components/HostRoles/maintenance_state',
       type: 'PLAIN'
+    },
+    {
+      key: 'selected',
+      alias: 'Hosts/host_name',
+      type: 'MULTIPLE'
     }
   ],
 
@@ -211,10 +216,10 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, {
     savedFilterConditions.forEach(function (filter) {
       var property = filterProperties.findProperty('key', colPropAssoc[filter.iColumn]);
 
-      if (property && filter.value.length > 0) {
+      if (property && filter.value.length > 0 && !filter.skipFilter) {
         queryParams.push({
           key: property.alias,
-          value: (filter.type === 'multiple') ? filter.value.split(',') : filter.value,
+          value: filter.value,
           type: property.type
         });
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/data/host/categories.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/data/host/categories.js b/ambari-web/app/data/host/categories.js
index 05f586f..cfdc092 100644
--- a/ambari-web/app/data/host/categories.js
+++ b/ambari-web/app/data/host/categories.js
@@ -76,19 +76,6 @@ module.exports = [
     filterValue: 'true'
   },
   {
-    value: Em.I18n.t('common.selected'),
-    hostProperty: 'selected',
-    class: '',
-    isHealthStatus: false,
-    healthClass: 'health-status-SELECTED',
-    healthStatus: 'health-status-SELECTED',
-    selected: true,
-    column: 10,
-    type: 'boolean',
-    filterValue: true,
-    isVisible: false
-  },
-  {
     value: Em.I18n.t('common.passive_state'),
     hostProperty: 'componentsInPassiveStateCount',
     class: 'passive-state icon-medkit',

http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/mappers/status_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/status_mapper.js b/ambari-web/app/mappers/status_mapper.js
index 0f1e284..67f3dac 100644
--- a/ambari-web/app/mappers/status_mapper.js
+++ b/ambari-web/app/mappers/status_mapper.js
@@ -106,6 +106,11 @@ App.statusMapper = App.QuickDataMapper.create({
         }
       }, this);
 
+      //TODO remove when App.Host model dependencies will be replaced with server request
+      if (!App.router.get('clusterController.isLoaded')) {
+        App.hostsMapper.map(json);
+      }
+
       App.cache['previousComponentStatuses'] = currentComponentStatuses;
       App.cache['previousComponentPassiveStates'] = currentComponentPassiveStates;
       App.cache['hostComponentsOnService'] = hostComponentsOnService;

http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/mixins/common/tableServerProvider.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/tableServerProvider.js b/ambari-web/app/mixins/common/tableServerProvider.js
index f1cade7..b01ddaa 100644
--- a/ambari-web/app/mixins/common/tableServerProvider.js
+++ b/ambari-web/app/mixins/common/tableServerProvider.js
@@ -85,26 +85,32 @@ App.TableServerProvider = Em.Mixin.create({
    * @param type {String}
    */
   updateFilter: function (iColumn, value, type) {
+    this.saveFilterConditions(iColumn, value, type, false);
+    this.refresh();
+  },
+
+  /**
+   * save filter conditions to local storage
+   * @param iColumn {Number}
+   * @param value {String|Array}
+   * @param type {String}
+   * @param skipFilter {Boolean}
+   */
+  saveFilterConditions: function (iColumn, value, type, skipFilter) {
     var filterCondition = this.get('filterConditions').findProperty('iColumn', iColumn);
 
     if (filterCondition) {
       filterCondition.value = value;
+      filterCondition.skipFilter = skipFilter;
     } else {
       filterCondition = {
+        skipFilter: skipFilter,
         iColumn: iColumn,
         value: value,
         type: type
       };
       this.get('filterConditions').push(filterCondition);
     }
-    this.saveFilterConditions();
-    this.refresh();
-  },
-
-  /**
-   * save filter conditions to local storage
-   */
-  saveFilterConditions: function () {
     App.db.setFilterConditions(this.get('controller.name'), this.get('filterConditions'));
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/templates/main/host.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host.hbs b/ambari-web/app/templates/main/host.hbs
index 35d862f..731e76e 100644
--- a/ambari-web/app/templates/main/host.hbs
+++ b/ambari-web/app/templates/main/host.hbs
@@ -147,13 +147,13 @@
       <label>{{view.filteredContentInfo}} - <a {{action clearFilters target="view"}}
href="#">{{t tableView.filters.clearAllFilters}}</a></label>
     </div>
     <div class="selected-hosts-info span4">
-      {{#if view.selectedCategory.hostsCount}}
-        {{#view view.statusFilter categoriesBinding="view.categories"}}
-          <a {{action selectCategory view.parentView.selectedCategory target="view"}}
href="#">
-            {{view.parentView.selectedCategory.hostsCount}}
-            {{pluralize view.parentView.selectedCategory.hostsCount singular="t:hosts.filters.selectedHostInfo"
plural="t:hosts.filters.selectedHostsInfo"}}
+      {{#if view.showSelectedFilter}}
+        <div>
+          <a {{action filterSelected target="view"}} href="#">
+            {{view.selectedHosts.length}}
+            {{pluralize view.selectedHostsCount singular="t:hosts.filters.selectedHostInfo"
plural="t:hosts.filters.selectedHostsInfo"}}
           </a>
-        {{/view}} - <a {{action clearSelection target="view"}} href="#">{{t hosts.filters.clearSelection}}</a>
+        </div> - <a {{action clearSelection target="view"}} href="#">{{t hosts.filters.clearSelection}}</a>
       {{/if}}
     </div>
     <div class="items-on-page">

http://git-wip-us.apache.org/repos/asf/ambari/blob/38e18b37/ambari-web/app/views/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host.js b/ambari-web/app/views/main/host.js
index 50e7684..f8b5c0c 100644
--- a/ambari-web/app/views/main/host.js
+++ b/ambari-web/app/views/main/host.js
@@ -36,14 +36,32 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
    * flag responsible for updating status counters of hosts
    */
   isCountersUpdating: false,
+  /**
+   * Contains all selected hosts on cluster
+   */
+  selectedHosts: [],
 
   /**
    * List of hosts in cluster
    * @type {Array}
    */
-  content:function () {
-    return this.get('controller.content');
-  }.property('controller.content.length'),
+  content: function () {
+    var selectedHosts = this.getSelectedFilter();
+    if (this.get('controller')) {
+      return this.get('controller.content').filter(function (host) {
+        host.set('selected', selectedHosts.contains(host.get('hostName')));
+        return true;
+      });
+    }
+    return [];
+  }.property('controller.content'),
+  /**
+   * flag to toggle displaying selected hosts counter
+   */
+  showSelectedFilter: function () {
+    return this.get('selectedHosts.length') > 0;
+  }.property('selectedHosts'),
+
   /**
    * return filtered number of all content number information displayed on the page footer
bar
    * @returns {String}
@@ -156,8 +174,54 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
     else {
       this.set('selectAllHosts', false);
     }
+    this.combineSelectedFilter();
+    //10 is an index of selected column
+    this.saveFilterConditions(10, this.get('selectedHosts'), 'multiple', true);
+
     this.addObserver('selectAllHosts', this, this.toggleAllHosts);
   },
+  /**
+   * combine selected hosts on page with selected hosts which are filtered out but added
to cluster
+   */
+  combineSelectedFilter: function () {
+    var previouslySelectedHosts = this.getSelectedFilter();
+    var selectedHosts = [];
+    var hostsOnPage = this.get('pageContent').mapProperty('hostName');
+    selectedHosts = this.get('pageContent').filterProperty('selected').mapProperty('hostName');
+
+    previouslySelectedHosts.forEach(function (hostName) {
+      if (!hostsOnPage.contains(hostName)) {
+        selectedHosts.push(hostName);
+      }
+    }, this);
+    this.set('selectedHosts', selectedHosts);
+  },
+
+  /**
+   * filter selected hosts
+   */
+  filterSelected: function() {
+    //10 is an index of selected column
+    this.updateFilter(10, this.get('selectedHosts'), 'multiple');
+  },
+
+  /**
+   * get selected filter previous value
+   * @return {Array}
+   */
+  getSelectedFilter: function() {
+    var filterCondition = this.get('filterConditions').findProperty('iColumn', 10);
+    var dbFilterConditions = App.db.getFilterConditions(this.get('controller.name'));
+    var selectedFilter = [];
+
+    if (filterCondition) {
+      selectedFilter = filterCondition.value;
+    }
+    else if (dbFilterConditions && dbFilterConditions.findProperty('iColumn', 10))
{
+        selectedFilter = dbFilterConditions.findProperty('iColumn', 10).value;
+    }
+    return selectedFilter;
+  },
 
   /**
    * Clear selectedFilter
@@ -166,7 +230,8 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
   clearSelection: function() {
     this.get('pageContent').setEach('selected', false);
     this.set('selectAllHosts', false);
-    this.clearFilters();
+    this.get('selectedHosts').clear();
+    this.filterSelected();
   },
 
   /**
@@ -340,17 +405,6 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
   }),
 
   /**
-   * update hosts count of selected hosts category
-   */
-  updateSelectedCategory: function () {
-    var hostsCountMap = {
-      'health-status-SELECTED': this.get('content').filterProperty('selected').length
-    };
-
-    this.updateHostsCount(hostsCountMap);
-  }.observes('content.@each.selected'),
-
-  /**
    * update status counters of hosts
    */
   updateStatusCounters: function () {
@@ -577,74 +631,6 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
   }),
 
   /**
-   * view of the alert filter implemented as a category of host statuses
-   */
-  alertFilter: Em.View.extend({
-    column: 7,
-    value: null,
-    classNames: ['noDisplay'],
-    showClearFilter: function(){
-      var mockEvent = {
-        context: this.get('parentView.categories').findProperty('healthStatus', 'health-status-WITH-ALERTS')
-      };
-      if(this.get('value')) {
-        this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
-      }
-    }
-  }),
-
-  /**
-   * view of the staleConfigs filter implemented as a category of host statuses
-   */
-  restartFilter: Em.View.extend({
-    column: 8,
-    value: null,
-    classNames: ['noDisplay'],
-    showClearFilter: function(){
-      var mockEvent = {
-        context: this.get('parentView.categories').findProperty('healthStatus', 'health-status-RESTART')
-      };
-      if(this.get('value')) {
-        this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
-      }
-    }
-  }),
-
-  /**
-   * view of the maintenance filter implemented as a category of host statuses
-   */
-  passiveStateFilter: Em.View.extend({
-    column: 9,
-    value: null,
-    classNames: ['noDisplay'],
-    showClearFilter: function(){
-      var mockEvent = {
-        context: this.get('parentView.categories').findProperty('healthStatus', 'health-status-PASSIVE_STATE')
-      };
-      if(this.get('value')) {
-        this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
-      }
-    }
-  }),
-
-  /**
-   * view of the "selected" filter implemented as a category of host statuses
-   */
-  selectedFilter: Em.View.extend({
-    column: 10,
-    value: null,
-    class: ['noDisplay'],
-    showClearFilter: function(){
-      var mockEvent = {
-        context: this.get('parentView.categories').findProperty('healthStatus', 'health-status-SELECTED')
-      };
-      if(this.get('value')) {
-        this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
-      }
-    }
-  }),
-
-  /**
    * Filter view for name column
    * Based on <code>filters</code> library
    */
@@ -787,7 +773,7 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
           chosenComponents.push(item.get('id'));
         });
         Em.run.next(function() {
-          self.set('value', chosenComponents.toString());
+          self.set('value', chosenComponents);
         });
       },
 


Mime
View raw message