Browse Source

AMBARI-6187. Hosts table sorting doesn't work. (akovalenko)

Aleksandr Kovalenko 11 years ago
parent
commit
709444328d

+ 4 - 3
ambari-web/app/mappers/hosts_mapper.js

@@ -52,7 +52,8 @@ App.hostsMapper = App.QuickDataMapper.create({
     os_arch: 'Hosts.os_arch',
     os_type: 'Hosts.os_type',
     ip: 'Hosts.ip',
-    passive_state: 'Hosts.maintenance_state'
+    passive_state: 'Hosts.maintenance_state',
+    index: 'index'
   },
   hostComponentConfig: {
     component_name: 'HostRoles.component_name',
@@ -69,7 +70,7 @@ App.hostsMapper = App.QuickDataMapper.create({
       var hostIds = {};
       var components = [];
       App.cache['HostsList'] = [];
-      json.items.forEach(function (item) {
+      json.items.forEach(function (item, index) {
         App.cache['HostsList'].push(item.Hosts.host_name);
         item.host_components = item.host_components || [];
         item.host_components.forEach(function (host_component) {
@@ -82,7 +83,7 @@ App.hostsMapper = App.QuickDataMapper.create({
         }, this);
         item.critical_alerts_count = (item.alerts) ? item.alerts.summary.CRITICAL + item.alerts.summary.WARNING : 0;
         item.cluster_id = App.get('clusterName');
-
+        item.index = index;
 
 
         var parsedItem = this.parseIt(item, this.config);

+ 1 - 0
ambari-web/app/models/host.js

@@ -46,6 +46,7 @@ App.Host = DS.Model.extend({
   cpuUser:DS.attr('number'),
   criticalAlertsCount: DS.attr('number'),
   passiveState: DS.attr('string'),
+  index: DS.attr('number'),
 
   /**
    * Is host checked at the main Hosts page

+ 11 - 0
ambari-web/app/views/main/host.js

@@ -61,6 +61,17 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
     }
     return [];
   }.property('controller.content'),
+
+  /**
+   * Contains content to show on the current page of data page view
+   * @type {Array}
+   */
+  pageContent: function () {
+    return this.get('filteredContent').slice(this.get('startIndex') - 1, this.get('endIndex')).sort(function (a, b) {
+      return a.get('index') - b.get('index');
+    });
+  }.property('filteredCount', 'startIndex', 'endIndex'),
+
   /**
    * flag to toggle displaying selected hosts counter
    */