mirror of https://github.com/apache/cloudstack.git
ui: sort list of templates, serviceOfferings, diskOfferings etc in the deploy VM wizard (#3336)
Adds functionality to sort the data that is available on each in the deploy VM wizard's step by their suitable fields: affinityGroups by name sshkeyPairs by name vpcs by name Fixes: #3050
This commit is contained in:
parent
75e4882f32
commit
f3aa147806
|
|
@ -2557,6 +2557,39 @@ function strOrFunc(arg, args) {
|
|||
return arg;
|
||||
}
|
||||
|
||||
function sortArrayByKey(arrayToSort, sortKey, reverse) {
|
||||
|
||||
if(!arrayToSort){
|
||||
return;
|
||||
}
|
||||
// Move smaller items towards the front
|
||||
// or back of the array depending on if
|
||||
// we want to sort the array in reverse
|
||||
// order or not.
|
||||
var moveSmaller = reverse ? 1 : -1;
|
||||
|
||||
// Move larger items towards the front
|
||||
// or back of the array depending on if
|
||||
// we want to sort the array in reverse
|
||||
// order or not.
|
||||
var moveLarger = reverse ? -1 : 1;
|
||||
|
||||
/**
|
||||
* @param {*} a
|
||||
* @param {*} b
|
||||
* @return {Number}
|
||||
*/
|
||||
arrayToSort.sort(function(a, b) {
|
||||
if (a[sortKey] < b[sortKey]) {
|
||||
return moveSmaller;
|
||||
}
|
||||
if (a[sortKey] > b[sortKey]) {
|
||||
return moveLarger;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
$.validator.addMethod("netmask", function(value, element) {
|
||||
if (this.optional(element) && value.length == 0)
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -809,6 +809,9 @@
|
|||
$step.find('.main-desc, p.no-affinity-groups').remove();
|
||||
|
||||
if (args.data.affinityGroups && args.data.affinityGroups.length) {
|
||||
|
||||
sortArrayByKey(args.data.affinityGroups, 'name');
|
||||
|
||||
$step.prepend(
|
||||
$('<div>').addClass('main-desc').append(
|
||||
$('<p>').html(_l('message.select.affinity.groups'))
|
||||
|
|
@ -855,6 +858,9 @@
|
|||
$step.find('.main-desc, p.no-sshkey-pairs').remove();
|
||||
|
||||
if (args.data.sshkeyPairs && args.data.sshkeyPairs.length) {
|
||||
|
||||
sortArrayByKey(args.data.sshkeyPairs, 'name');
|
||||
|
||||
$step.prepend(
|
||||
$('<div>').addClass('main-desc').append(
|
||||
$('<p>').html(_l('message.please.select.ssh.key.pair.use.with.this.vm'))
|
||||
|
|
@ -1024,6 +1030,9 @@
|
|||
|
||||
// Populate VPC drop-down
|
||||
$vpcSelect.html('');
|
||||
|
||||
sortArrayByKey(vpcs, 'name');
|
||||
|
||||
$(vpcs).map(function(index, vpc) {
|
||||
var $option = $('<option>');
|
||||
var id = vpc.id;
|
||||
|
|
|
|||
Loading…
Reference in New Issue