From 68cdb4aa51a2f08458ff284af3295dbb3a76961a Mon Sep 17 00:00:00 2001 From: smlshn Date: Sat, 18 May 2019 01:46:39 +0300 Subject: [PATCH 1/3] Sort list of templates, serviceOfferings, diskOfferings, affinityGroups, sshkeyPairs, vpcs, networkOfferings in the deploy VM wizard --- ui/scripts/sharedFunctions.js | 33 ++++++++++++++++++++++++++ ui/scripts/ui-custom/instanceWizard.js | 19 +++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js index e2ad3baf6da0..514d7e0bb261 100644 --- a/ui/scripts/sharedFunctions.js +++ b/ui/scripts/sharedFunctions.js @@ -2531,6 +2531,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; diff --git a/ui/scripts/ui-custom/instanceWizard.js b/ui/scripts/ui-custom/instanceWizard.js index e9517055ee34..04f6d0f5409d 100644 --- a/ui/scripts/ui-custom/instanceWizard.js +++ b/ui/scripts/ui-custom/instanceWizard.js @@ -332,6 +332,9 @@ $step.find('.select-iso').show(); } var makeIsos = function(type, append) { + + sortArrayByKey(args.data.templates[type], 'name'); + var $selects = makeSelects('templateid', args.data.templates[type], { name: 'name', desc: 'displaytext', @@ -491,6 +494,9 @@ return { response: { success: function(args) { + + sortArrayByKey(args.data.serviceOfferings, 'cpuspeed'); + $step.find('.content .select-container').append( makeSelects('serviceofferingid', args.data.serviceOfferings, { name: 'name', @@ -557,6 +563,8 @@ $step.removeClass('custom-disk-size'); $step.find('.main-desc, p.no-datadisk').remove(); + sortArrayByKey(args.data.diskOfferings, 'disksize'); + if (!multiDisk){ if (args.required) { $step.find('.section.no-thanks') @@ -749,6 +757,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( $('
').addClass('main-desc').append( $('

').html(_l('message.select.affinity.groups')) @@ -795,6 +806,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( $('

').addClass('main-desc').append( $('

').html(_l('message.please.select.ssh.key.pair.use.with.this.vm')) @@ -964,6 +978,9 @@ // Populate VPC drop-down $vpcSelect.html(''); + + sortArrayByKey(vpcs, 'name'); + $(vpcs).map(function(index, vpc) { var $option = $('