Skip to content

Commit f3aa147

Browse files
smlshnyadvr
authored andcommitted
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
1 parent 75e4882 commit f3aa147

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

ui/scripts/sharedFunctions.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,39 @@ function strOrFunc(arg, args) {
25572557
return arg;
25582558
}
25592559

2560+
function sortArrayByKey(arrayToSort, sortKey, reverse) {
2561+
2562+
if(!arrayToSort){
2563+
return;
2564+
}
2565+
// Move smaller items towards the front
2566+
// or back of the array depending on if
2567+
// we want to sort the array in reverse
2568+
// order or not.
2569+
var moveSmaller = reverse ? 1 : -1;
2570+
2571+
// Move larger items towards the front
2572+
// or back of the array depending on if
2573+
// we want to sort the array in reverse
2574+
// order or not.
2575+
var moveLarger = reverse ? -1 : 1;
2576+
2577+
/**
2578+
* @param {*} a
2579+
* @param {*} b
2580+
* @return {Number}
2581+
*/
2582+
arrayToSort.sort(function(a, b) {
2583+
if (a[sortKey] < b[sortKey]) {
2584+
return moveSmaller;
2585+
}
2586+
if (a[sortKey] > b[sortKey]) {
2587+
return moveLarger;
2588+
}
2589+
return 0;
2590+
});
2591+
}
2592+
25602593
$.validator.addMethod("netmask", function(value, element) {
25612594
if (this.optional(element) && value.length == 0)
25622595
return true;

ui/scripts/ui-custom/instanceWizard.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@
809809
$step.find('.main-desc, p.no-affinity-groups').remove();
810810

811811
if (args.data.affinityGroups && args.data.affinityGroups.length) {
812+
813+
sortArrayByKey(args.data.affinityGroups, 'name');
814+
812815
$step.prepend(
813816
$('<div>').addClass('main-desc').append(
814817
$('<p>').html(_l('message.select.affinity.groups'))
@@ -855,6 +858,9 @@
855858
$step.find('.main-desc, p.no-sshkey-pairs').remove();
856859

857860
if (args.data.sshkeyPairs && args.data.sshkeyPairs.length) {
861+
862+
sortArrayByKey(args.data.sshkeyPairs, 'name');
863+
858864
$step.prepend(
859865
$('<div>').addClass('main-desc').append(
860866
$('<p>').html(_l('message.please.select.ssh.key.pair.use.with.this.vm'))
@@ -1024,6 +1030,9 @@
10241030

10251031
// Populate VPC drop-down
10261032
$vpcSelect.html('');
1033+
1034+
sortArrayByKey(vpcs, 'name');
1035+
10271036
$(vpcs).map(function(index, vpc) {
10281037
var $option = $('<option>');
10291038
var id = vpc.id;

0 commit comments

Comments
 (0)