This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new f3aa147  ui: sort list of templates, serviceOfferings, diskOfferings 
etc in the deploy VM wizard (#3336)
f3aa147 is described below

commit f3aa147806adf2b14b8999329652302844629dca
Author: smlshn <[email protected]>
AuthorDate: Thu Jul 4 11:59:17 2019 +0300

    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
---
 ui/scripts/sharedFunctions.js          | 33 +++++++++++++++++++++++++++++++++
 ui/scripts/ui-custom/instanceWizard.js |  9 +++++++++
 2 files changed, 42 insertions(+)

diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index a8049ee..d4a06e3 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -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;
diff --git a/ui/scripts/ui-custom/instanceWizard.js 
b/ui/scripts/ui-custom/instanceWizard.js
index 706c0bf..ef6d224 100644
--- a/ui/scripts/ui-custom/instanceWizard.js
+++ b/ui/scripts/ui-custom/instanceWizard.js
@@ -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;

Reply via email to