You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/02/14 23:00:35 UTC
svn commit: r1446354 - in /incubator/ambari/trunk: ./
ambari-web/app/templates/main/ ambari-web/app/templates/main/apps/item/
ambari-web/app/utils/ ambari-web/app/views/common/
ambari-web/app/views/main/ ambari-web/app/views/main/apps/item/
Author: yusaku
Date: Thu Feb 14 22:00:35 2013
New Revision: 1446354
URL: http://svn.apache.org/r1446354
Log:
AMBARI-1431. Hosts table no longer allows sorting. (yusaku)
Added:
incubator/ambari/trunk/ambari-web/app/views/common/sort_view.js
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-web/app/templates/main/apps/item/dag.hbs
incubator/ambari/trunk/ambari-web/app/templates/main/host.hbs
incubator/ambari/trunk/ambari-web/app/utils/misc.js
incubator/ambari/trunk/ambari-web/app/views/main/apps/item/dag_view.js
incubator/ambari/trunk/ambari-web/app/views/main/host.js
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Feb 14 22:00:35 2013
@@ -278,6 +278,8 @@ Trunk (unreleased changes):
BUG FIXES
+ AMBARI-1431. Hosts table no longer allows sorting. (yusaku)
+
AMBARI-1376. Wrong calculation of duration filter on apps page. (jaimin via
yusaku)
Modified: incubator/ambari/trunk/ambari-web/app/templates/main/apps/item/dag.hbs
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/templates/main/apps/item/dag.hbs?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/templates/main/apps/item/dag.hbs (original)
+++ incubator/ambari/trunk/ambari-web/app/templates/main/apps/item/dag.hbs Thu Feb 14 22:00:35 2013
@@ -20,20 +20,22 @@
<table class="table table-bordered table-striped" id="innerTable">
<thead>
<tr>
- <th>{{t apps.item.dag.job}} #</th>
- <th>{{t apps.item.dag.jobId}}</th>
- <th>{{t apps.item.dag.status}}</th>
- <th>{{t apps.item.dag.maps}}</th>
- <th>{{t apps.item.dag.reduces}}</th>
- <th>{{t apps.item.dag.input}}</th>
- <th>{{t apps.item.dag.output}}</th>
- <th>{{t apps.item.dag.duration}}</th>
+ {{#view view.sortView contentBinding="controller.content.jobs"}}
+ {{#if view.parentView.hasManyJobs}}{{view view.parentView.nameSort}}{{/if}}
+ {{view view.parentView.idSort}}
+ {{view view.parentView.statusSort}}
+ {{view view.parentView.mapsSort}}
+ {{view view.parentView.reducesSort}}
+ {{view view.parentView.inputSort}}
+ {{view view.parentView.outputSort}}
+ {{view view.parentView.durationSort}}
+ {{/view}}
</tr>
</thead>
<tbody>
{{#each job in controller.content.jobs}}
<tr>
- <td>{{job.workflow_entity_name}}</td>
+ {{#if view.hasManyJobs}}<td>{{job.workflow_entity_name}}</td>{{/if}}
<td>{{job.id}}</td>
<td>{{job.status}}</td>
<td>{{job.maps}}</td>
Modified: incubator/ambari/trunk/ambari-web/app/templates/main/host.hbs
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/templates/main/host.hbs?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/templates/main/host.hbs (original)
+++ incubator/ambari/trunk/ambari-web/app/templates/main/host.hbs Thu Feb 14 22:00:35 2013
@@ -35,14 +35,16 @@
<table class="datatable table table-bordered table-striped" id="hosts-table">
<thead>
<tr>
- <th class="first"> </th>
- <th>{{t common.name}}</th>
- <th>{{t common.ipAddress}}</th>
- <th>{{t common.cpu}}</th>
- <th>{{t common.ram}}</th>
- <th>{{t common.diskUsage}}</th>
- <th>{{t common.loadAvg}}</th>
- <th>{{t common.components}}</th>
+ {{#view view.sortView contentBinding="view.filteredContent"}}
+ <th class="first"></th>
+ {{view view.parentView.nameSort}}
+ {{view view.parentView.ipSort}}
+ {{view view.parentView.cpuSort}}
+ {{view view.parentView.memorySort}}
+ {{view view.parentView.diskUsageSort}}
+ {{view view.parentView.loadAvgSort}}
+ <th>{{t common.components}}</th>
+ {{/view}}
</tr>
<tr>
<th class="first"> </th>
@@ -59,7 +61,6 @@
{{#if view.filteredContent.length}}
{{#each host in view.filteredContent}}
{{#view view.HostView contentBinding="host"}}
- <tr>
<td class="first">
<span {{bindAttr class="host.healthClass"}} {{bindAttr title="host.healthToolTip" }}></span>
</td>
@@ -81,7 +82,6 @@
<td>
<span title="{{unbound view.labels}}">{{view.shortLabels}}</span>
</td>
- </tr>
{{/view}}
{{/each}}
{{else}}
Modified: incubator/ambari/trunk/ambari-web/app/utils/misc.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/utils/misc.js?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/utils/misc.js (original)
+++ incubator/ambari/trunk/ambari-web/app/utils/misc.js Thu Feb 14 22:00:35 2013
@@ -34,5 +34,23 @@ module.exports = {
}
}
return value;
+ },
+ /**
+ * Convert ip address to integer
+ * @param ip
+ * @return integer
+ */
+ ipToInt: function(ip){
+ // * example 1: ipToInt('192.0.34.166');
+ // * returns 1: 3221234342
+ // * example 2: ipToInt('255.255.255.256');
+ // * returns 2: false
+ // Verify IP format.
+ if (!/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip)) {
+ return false; // Invalid format.
+ }
+ // Reuse ip variable for component counter.
+ var d = ip.split('.');
+ return ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]);
}
};
Added: incubator/ambari/trunk/ambari-web/app/views/common/sort_view.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/views/common/sort_view.js?rev=1446354&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/views/common/sort_view.js (added)
+++ incubator/ambari/trunk/ambari-web/app/views/common/sort_view.js Thu Feb 14 22:00:35 2013
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var misc = require('utils/misc');
+
+/**
+ * Wrapper View for all sort components. Layout template and common actions are located inside of it.
+ * Logic specific for sort fields
+ * located in inner view - <code>fieldView</code>.
+ *
+ * @type {*}
+ */
+var wrapperView = Em.View.extend({
+ tagName: 'tr',
+ /**
+ * sort content by property
+ * @param property
+ * @param order: true - DESC, false - ASC
+ */
+ sort: function(property, order){
+ var content = this.get('content').toArray();
+ var sortFunc = this.getSortFunc(property, order);
+ this.resetSort();
+ content.sort(sortFunc);
+ this.set('content', content);
+ },
+ /**
+ * reset all sorts fields
+ */
+ resetSort: function(){
+ this.get('childViews').setEach('status', 'sorting');
+ },
+ /**
+ * determines sort function depending on the type of sort field
+ * @param property
+ * @param order
+ * @return {*}
+ */
+ getSortFunc: function(property, order){
+ var func;
+ switch (property.get('type')){
+ case 'ip':
+ func = function (a, b) {
+ var a = misc.ipToInt(a.get(property.get('name')));
+ var b = misc.ipToInt(b.get(property.get('name')));
+ if(order){
+ return b - a;
+ } else {
+ return a - b;
+ }
+ };
+ break;
+ default:
+ func = function(a,b){
+ if(order){
+ if (a.get(property.get('name')) > b.get(property.get('name')))
+ return -1;
+ if (a.get(property.get('name')) < b.get(property.get('name')))
+ return 1;
+ return 0;
+ } else {
+ if (a.get(property.get('name')) < b.get(property.get('name')))
+ return -1;
+ if (a.get(property.get('name')) > b.get(property.get('name')))
+ return 1;
+ return 0;
+ }
+ }
+ }
+ return func;
+ }
+});
+/**
+ * particular view that contain sort field properties:
+ * name - name of property in content table
+ * type(optional) - specific type to sort
+ * displayName - label to display
+ * @type {*}
+ */
+var fieldView = Em.View.extend({
+ template:Em.Handlebars.compile('{{view.displayName}}'),
+ classNameBindings: ['status'],
+ tagName: 'th',
+ name: null,
+ displayName: null,
+ status: 'sorting',
+ type: null,
+ /**
+ * callback that run sorting and define order of sorting
+ * @param event
+ */
+ click: function(event){
+ if(this.get('status') === 'sorting_desc'){
+ this.get('parentView').sort(this, true);
+ this.set('status', 'sorting_asc');
+ } else {
+ this.get('parentView').sort(this, false);
+ this.set('status', 'sorting_desc');
+ }
+ }
+});
+
+/**
+ * Result object, which will be accessible outside
+ * @type {Object}
+ */
+module.exports = {
+ wrapperView: wrapperView,
+ fieldView: fieldView
+};
\ No newline at end of file
Modified: incubator/ambari/trunk/ambari-web/app/views/main/apps/item/dag_view.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/views/main/apps/item/dag_view.js?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/views/main/apps/item/dag_view.js (original)
+++ incubator/ambari/trunk/ambari-web/app/views/main/apps/item/dag_view.js Thu Feb 14 22:00:35 2013
@@ -17,6 +17,7 @@
*/
var App = require('app');
+var sort = require('views/common/sort_view');
App.MainAppsItemDagView = Em.View.extend({
templateName: require('templates/main/apps/item/dag'),
@@ -54,6 +55,10 @@ App.MainAppsItemDagView = Em.View.extend
loaded : false,
+ hasManyJobs: function(){
+ return (this.get('content') && this.get('content').length > 1);
+ }.property('content'),
+
onLoad:function (){
if(!this.get('controller.content.loadAllJobs') || this.get('loaded')){
return;
@@ -65,9 +70,6 @@ App.MainAppsItemDagView = Em.View.extend
Ember.run.next(function(){
self.draw();
- if (self.get('jobs').length === 1) {
- self.$().find('table tr td:first-child, table tr th:first-child').remove();
- }
});
}.observes('controller.content.loadAllJobs'),
@@ -106,5 +108,38 @@ App.MainAppsItemDagView = Em.View.extend
var graph = new DagViewer('dag_viewer')
.setData(dagSchema, jobs)
.drawDag(this.$().width(), 300, 20);
- }
+ },
+ sortView: sort.wrapperView,
+ nameSort: sort.fieldView.extend({
+ name:'workflow_entity_name',
+ displayName: Em.I18n.t('apps.item.dag.job')
+ }),
+ idSort: sort.fieldView.extend({
+ name:'id',
+ displayName: Em.I18n.t('apps.item.dag.jobId')
+ }),
+ statusSort: sort.fieldView.extend({
+ name:'status',
+ displayName: Em.I18n.t('apps.item.dag.status')
+ }),
+ mapsSort: sort.fieldView.extend({
+ name:'maps',
+ displayName: Em.I18n.t('apps.item.dag.maps')
+ }),
+ reducesSort: sort.fieldView.extend({
+ name:'reduces',
+ displayName: Em.I18n.t('apps.item.dag.reduces')
+ }),
+ inputSort: sort.fieldView.extend({
+ name:'input',
+ displayName: Em.I18n.t('apps.item.dag.input')
+ }),
+ outputSort: sort.fieldView.extend({
+ name:'output',
+ displayName: Em.I18n.t('apps.item.dag.output')
+ }),
+ durationSort: sort.fieldView.extend({
+ name:'elapsed_time',
+ displayName: Em.I18n.t('apps.item.dag.duration')
+ })
});
Modified: incubator/ambari/trunk/ambari-web/app/views/main/host.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/views/main/host.js?rev=1446354&r1=1446353&r2=1446354&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/views/main/host.js (original)
+++ incubator/ambari/trunk/ambari-web/app/views/main/host.js Thu Feb 14 22:00:35 2013
@@ -18,6 +18,7 @@
var App = require('app');
var filters = require('views/common/filter_view');
+var sort = require('views/common/sort_view');
var date = require('utils/date');
App.MainHostView = Em.View.extend({
@@ -36,10 +37,35 @@ App.MainHostView = Em.View.extend({
this.set('controller.filteredByAlerts', false);
}
},
-
+ sortView: sort.wrapperView,
+ nameSort: sort.fieldView.extend({
+ name:'publicHostName',
+ displayName: Em.I18n.t('common.name')
+ }),
+ ipSort: sort.fieldView.extend({
+ name:'ip',
+ displayName: Em.I18n.t('common.ipAddress'),
+ type: 'ip'
+ }),
+ cpuSort: sort.fieldView.extend({
+ name:'cpu',
+ displayName: Em.I18n.t('common.cpu')
+ }),
+ memorySort: sort.fieldView.extend({
+ name:'memory',
+ displayName: Em.I18n.t('common.ram')
+ }),
+ diskUsageSort: sort.fieldView.extend({
+ name:'diskUsage',
+ displayName: Em.I18n.t('common.diskUsage')
+ }),
+ loadAvgSort: sort.fieldView.extend({
+ name:'loadAvg',
+ displayName: Em.I18n.t('common.loadAvg')
+ }),
HostView:Em.View.extend({
content:null,
-
+ tagName: 'tr',
shortLabels: function() {
var labels = this.get('content.hostComponents').getEach('displayName');
var shortLabels = '';