From f231418c4ae5cf2e9553f42872caefd649694466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 18 Jun 2015 13:25:08 +0200 Subject: [PATCH] Feature #3748: User and group list use the cache --- src/sunstone/public/app/opennebula/action.js | 10 +++- src/sunstone/public/app/opennebula/group.js | 51 +++++++------------- src/sunstone/public/app/opennebula/user.js | 51 +++++++------------- 3 files changed, 42 insertions(+), 70 deletions(-) diff --git a/src/sunstone/public/app/opennebula/action.js b/src/sunstone/public/app/opennebula/action.js index 072e74301c..4b197b6fda 100644 --- a/src/sunstone/public/app/opennebula/action.js +++ b/src/sunstone/public/app/opennebula/action.js @@ -97,7 +97,7 @@ define(function(require) { }); }, - "list": function(params, resource, path) { + "list": function(params, resource, path, process) { var callback = params.success; var callbackError = params.error; var timeout = params.timeout || false; @@ -153,7 +153,13 @@ define(function(require) { data: {timeout: timeout}, dataType: "json", success: function(response) { - var list = OpenNebulaHelper.pool(resource, response) + var list; + + if (process){ + list = process(response); + } else { + list = OpenNebulaHelper.pool(resource, response); + } listCache[cache_name] = { timestamp : new Date().getTime(), diff --git a/src/sunstone/public/app/opennebula/group.js b/src/sunstone/public/app/opennebula/group.js index 2f2074f882..4eba319953 100644 --- a/src/sunstone/public/app/opennebula/group.js +++ b/src/sunstone/public/app/opennebula/group.js @@ -16,45 +16,28 @@ define(function(require) { OpenNebulaAction.del(params, RESOURCE); }, "list": function(params) { - var req_path = RESOURCE.toLowerCase(); - var callback = params.success; - var callback_error = params.error; - var timeout = params.timeout || false; - var request = OpenNebulaHelper.request(RESOURCE, "list"); + OpenNebulaAction.list(params, RESOURCE, null, function(response) { + var list = OpenNebulaHelper.pool(RESOURCE, response); - $.ajax({ - url: req_path, - type: "GET", - data: {timeout: timeout}, - dataType: "json", - success: function(response) { - var list = OpenNebulaHelper.pool(RESOURCE, response); + QuotaDefaults.setDefaultGroupQuotas( + QuotaDefaults.default_quotas(response.GROUP_POOL.DEFAULT_GROUP_QUOTAS) + ); - QuotaDefaults.setDefaultGroupQuotas( - QuotaDefaults.default_quotas(response.GROUP_POOL.DEFAULT_GROUP_QUOTAS) - ); + // Inject the VM quota. This info is returned separately in the + // pool info call, but the elementArray expects it inside the GROUP, + // as it is returned by the individual info call + var quotas_hash = OpenNebulaHelper.pool_hash_processing( + 'GROUP_POOL', 'QUOTAS', response); - // Inject the VM quota. This info is returned separately in the - // pool info call, but the elementArray expects it inside the GROUP, - // as it is returned by the individual info call - var quotas_hash = OpenNebulaHelper.pool_hash_processing( - 'GROUP_POOL', 'QUOTAS', response); + $.each(list,function(){ + var q = quotas_hash[this[RESOURCE].ID]; - $.each(list,function(){ - var q = quotas_hash[this[RESOURCE].ID]; + if (q != undefined) { + this[RESOURCE].VM_QUOTA = q.QUOTAS.VM_QUOTA; + } + }); - if (q != undefined) { - this[RESOURCE].VM_QUOTA = q.QUOTAS.VM_QUOTA; - } - }); - - return callback ? - callback(request, list, quotas_hash) : null; - }, - error: function(response) { - return callback_error ? - callback_error(request, OpenNebulaError(response)) : null; - } + return list; }); }, "update": function(params) { diff --git a/src/sunstone/public/app/opennebula/user.js b/src/sunstone/public/app/opennebula/user.js index 701edc5beb..246ab7a271 100644 --- a/src/sunstone/public/app/opennebula/user.js +++ b/src/sunstone/public/app/opennebula/user.js @@ -17,45 +17,28 @@ define(function(require) { OpenNebulaAction.del(params, RESOURCE); }, "list": function(params) { - var req_path = RESOURCE.toLowerCase(); - var callback = params.success; - var callback_error = params.error; - var timeout = params.timeout || false; - var request = OpenNebulaHelper.request(RESOURCE, "list"); + OpenNebulaAction.list(params, RESOURCE, null, function(response) { + var list = OpenNebulaHelper.pool(RESOURCE, response); - $.ajax({ - url: req_path, - type: "GET", - data: {timeout: timeout}, - dataType: "json", - success: function(response) { - var list = OpenNebulaHelper.pool(RESOURCE, response); + QuotaDefaults.setDefaultUserQuotas( + QuotaDefaults.default_quotas(response.USER_POOL.DEFAULT_USER_QUOTAS) + ); - QuotaDefaults.setDefaultUserQuotas( - QuotaDefaults.default_quotas(response.USER_POOL.DEFAULT_USER_QUOTAS) - ); + // Inject the VM user quota. This info is returned separately in the + // pool info call, but the userElementArray expects it inside the USER, + // as it is returned by the individual info call + var quotas_hash = OpenNebulaHelper.pool_hash_processing( + 'USER_POOL', 'QUOTAS', response); - // Inject the VM user quota. This info is returned separately in the - // pool info call, but the userElementArray expects it inside the USER, - // as it is returned by the individual info call - var quotas_hash = OpenNebulaHelper.pool_hash_processing( - 'USER_POOL', 'QUOTAS', response); + $.each(list,function(){ + var q = quotas_hash[this[RESOURCE].ID]; - $.each(list,function(){ - var q = quotas_hash[this[RESOURCE].ID]; + if (q != undefined) { + this[RESOURCE].VM_QUOTA = q.QUOTAS.VM_QUOTA; + } + }); - if (q != undefined) { - this[RESOURCE].VM_QUOTA = q.QUOTAS.VM_QUOTA; - } - }); - - return callback ? - callback(request, list, quotas_hash) : null; - }, - error: function(response) { - return callback_error ? - callback_error(request, OpenNebulaError(response)) : null; - } + return list; }); }, "show" : function(params) {