Fix for values sorting
* utils.natsort is used to compare strings * numeric sorting for numbers * undefined or null values go last Closes-Bug: #1474377 Change-Id: I9070b2d818670e0566b5ca6da1663070717254d8
This commit is contained in:
parent
d55bd2ffce
commit
11c76d3010
@ -22,6 +22,7 @@
|
|||||||
"retry_button": "Retry Update",
|
"retry_button": "Retry Update",
|
||||||
"apply_changes_button": "Apply Changes",
|
"apply_changes_button": "Apply Changes",
|
||||||
"not_available": "N/A",
|
"not_available": "N/A",
|
||||||
|
"not_specified" : "Not specified",
|
||||||
"size": {
|
"size": {
|
||||||
"byte": "byte",
|
"byte": "byte",
|
||||||
"byte_plural": "bytes",
|
"byte_plural": "bytes",
|
||||||
|
@ -339,8 +339,15 @@ define([
|
|||||||
};
|
};
|
||||||
var model1Value = getValue(model1),
|
var model1Value = getValue(model1),
|
||||||
model2Value = getValue(model2);
|
model2Value = getValue(model2);
|
||||||
if (_.isString(model1Value)) return utils.natsort(model1Value, model2Value, options);
|
if (_.isString(model1Value) && _.isString(model1Value)) {
|
||||||
var result = model1Value - model2Value;
|
return utils.natsort(model1Value, model2Value, options);
|
||||||
|
}
|
||||||
|
var result;
|
||||||
|
if (_.isNumber(model1Value) && _.isNumber(model1Value)) {
|
||||||
|
result = model1Value - model2Value;
|
||||||
|
} else {
|
||||||
|
result = !model1Value && !model2Value ? 0 : !model1Value ? 1 : -1;
|
||||||
|
}
|
||||||
return options.desc ? -result : result;
|
return options.desc ? -result : result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -264,7 +264,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
};
|
};
|
||||||
nodePanelClasses[status] = status;
|
nodePanelClasses[status] = status;
|
||||||
|
|
||||||
var manufacturer = node.get('manufacturer'),
|
var manufacturer = node.get('manufacturer') || '',
|
||||||
logoClasses = {
|
logoClasses = {
|
||||||
'manufacturer-logo': true
|
'manufacturer-logo': true
|
||||||
};
|
};
|
||||||
|
@ -145,7 +145,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
changeSearch: _.debounce(function(value) {
|
changeSearch: _.debounce(function(value) {
|
||||||
this.updateSearch(value);
|
this.updateSearch(_.trim(value));
|
||||||
}, 200, {leading: true}),
|
}, 200, {leading: true}),
|
||||||
clearSearchField: function() {
|
clearSearchField: function() {
|
||||||
this.updateSearch('');
|
this.updateSearch('');
|
||||||
@ -236,7 +236,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
if (this.state.search) {
|
if (this.state.search) {
|
||||||
var search = this.state.search.toLowerCase();
|
var search = this.state.search.toLowerCase();
|
||||||
if (!_.any(node.pick('name', 'mac', 'ip'), function(attribute) {
|
if (!_.any(node.pick('name', 'mac', 'ip'), function(attribute) {
|
||||||
return _.contains(attribute.toLowerCase(), search);
|
return _.contains((attribute || '').toLowerCase(), search);
|
||||||
})) {
|
})) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -382,9 +382,11 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
}
|
}
|
||||||
{_.map(this.props.options, function(option, index) {
|
{_.map(this.props.options, function(option, index) {
|
||||||
return (
|
return (
|
||||||
<controls.Input {...option}
|
<controls.Input
|
||||||
key={index}
|
key={index}
|
||||||
type='checkbox'
|
type='checkbox'
|
||||||
|
name={option.name}
|
||||||
|
label={option.label || i18n('common.not_specified')}
|
||||||
checked={_.contains(this.props.values, option.name)}
|
checked={_.contains(this.props.values, option.name)}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
/>
|
/>
|
||||||
@ -504,6 +506,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
break;
|
break;
|
||||||
case 'manufacturer':
|
case 'manufacturer':
|
||||||
options = _.uniq(this.props.screenNodes.pluck('manufacturer')).map(function(manufacturer) {
|
options = _.uniq(this.props.screenNodes.pluck('manufacturer')).map(function(manufacturer) {
|
||||||
|
manufacturer = manufacturer || '';
|
||||||
return {
|
return {
|
||||||
name: manufacturer.replace(/\s/g, '_'),
|
name: manufacturer.replace(/\s/g, '_'),
|
||||||
label: manufacturer
|
label: manufacturer
|
||||||
@ -1085,6 +1088,16 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
var uniqValueSorters = ['name', 'mac', 'ip'],
|
var uniqValueSorters = ['name', 'mac', 'ip'],
|
||||||
activeSorters = _.uniq(_.flatten(_.map(this.props.activeSorters, _.keys)));
|
activeSorters = _.uniq(_.flatten(_.map(this.props.activeSorters, _.keys)));
|
||||||
|
|
||||||
|
var composeNodeDiskSizesLabel = function(node) {
|
||||||
|
var diskSizes = node.resource('disks');
|
||||||
|
return i18n('node_details.disks_amount', {
|
||||||
|
count: diskSizes.length,
|
||||||
|
size: diskSizes.map(function(size) {
|
||||||
|
return utils.showDiskSize(size) + ' ' + i18n('node_details.hdd');
|
||||||
|
}).join(', ')
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var groupingMethod = _.bind(function(node) {
|
var groupingMethod = _.bind(function(node) {
|
||||||
return (_.map(_.difference(activeSorters, uniqValueSorters), function(sorter) {
|
return (_.map(_.difference(activeSorters, uniqValueSorters), function(sorter) {
|
||||||
if (sorter == 'roles') {
|
if (sorter == 'roles') {
|
||||||
@ -1096,7 +1109,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (sorter == 'manufacturer') {
|
if (sorter == 'manufacturer') {
|
||||||
return node.get('manufacturer');
|
return node.get('manufacturer') || i18n('common.not_specified');
|
||||||
}
|
}
|
||||||
if (sorter == 'hdd') {
|
if (sorter == 'hdd') {
|
||||||
return i18n('node_details.total_hdd', {
|
return i18n('node_details.total_hdd', {
|
||||||
@ -1104,13 +1117,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (sorter == 'disks') {
|
if (sorter == 'disks') {
|
||||||
var diskSizes = node.resource('disks');
|
return composeNodeDiskSizesLabel(node);
|
||||||
return i18n('node_details.disks_amount', {
|
|
||||||
count: diskSizes.length,
|
|
||||||
size: diskSizes.map(function(size) {
|
|
||||||
return utils.showDiskSize(size) + ' ' + i18n('node_details.hdd');
|
|
||||||
}).join(', ')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (sorter == 'ram') {
|
if (sorter == 'ram') {
|
||||||
return i18n('node_details.total_ram', {
|
return i18n('node_details.total_ram', {
|
||||||
@ -1132,7 +1139,7 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
}));
|
}));
|
||||||
_.each(groups, function(group) {
|
_.each(groups, function(group) {
|
||||||
group[1].sort(function(node1, node2) {
|
group[1].sort(function(node1, node2) {
|
||||||
return utils.multiSort(node1, node2, formattedSorters);
|
return utils.compare(node1, node2, formattedSorters);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1158,10 +1165,10 @@ function($, _, i18n, Backbone, React, utils, models, dispatcher, controls, dialo
|
|||||||
result = _.indexOf(this.props.statusesToFilter, node1.getStatusSummary()) - _.indexOf(this.props.statusesToFilter, node2.getStatusSummary());
|
result = _.indexOf(this.props.statusesToFilter, node1.getStatusSummary()) - _.indexOf(this.props.statusesToFilter, node2.getStatusSummary());
|
||||||
break;
|
break;
|
||||||
case 'manufacturer':
|
case 'manufacturer':
|
||||||
result = utils.natsort(node1.get('manufacturer'), node2.get('manufacturer'));
|
result = utils.compare(node1, node2, {attr: 'manufacturer'});
|
||||||
break;
|
break;
|
||||||
case 'disks':
|
case 'disks':
|
||||||
result = utils.natsort(node1.resource('disks'), node2.resource('disks'));
|
result = utils.natsort(composeNodeDiskSizesLabel(node1), composeNodeDiskSizesLabel(node2));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result = node1.resource(sorterName) - node2.resource(sorterName);
|
result = node1.resource(sorterName) - node2.resource(sorterName);
|
||||||
|
Loading…
Reference in New Issue
Block a user