refactor application detail retrive logic

Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/bcc4b2d7
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/bcc4b2d7
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/bcc4b2d7

Branch: refs/heads/master
Commit: bcc4b2d7dea8a904b607819bc003c588377ca080
Parents: f5e92d1
Author: Dakshika Jayathilaka <[email protected]>
Authored: Sun Mar 8 09:39:36 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Sun Mar 8 12:02:55 2015 +0530

----------------------------------------------------------------------
 .../console/applications_form.jag               | 65 +++++++++-----------
 .../console/controllers/rest/rest_calls.jag     |  4 ++
 2 files changed, 32 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/bcc4b2d7/components/org.apache.stratos.manager.console/console/applications_form.jag
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/applications_form.jag 
b/components/org.apache.stratos.manager.console/console/applications_form.jag
index 0dbaecb..d56742e 100644
--- 
a/components/org.apache.stratos.manager.console/console/applications_form.jag
+++ 
b/components/org.apache.stratos.manager.console/console/applications_form.jag
@@ -43,35 +43,6 @@ var leftMenu = menuGenerator(context, menuJson.menu, 
userPermissions);
 
 if (!elements) {
     elements = 
uriMatcher.match('/{context}/applications/{formtype}/{action}/');
-    isForm = true;
-
-    if (elements.action != 'new') {
-        isEdit = true;
-    }
-
-    try {
-        var formData = require('controllers/forms/schema/applications/' + 
elements.formtype + '.json'),
-                formDataRaw = 
require('controllers/forms/default/applications/' + elements.formtype + 
'.json'),
-                formTitle = formData.title,
-                buttonText = formData.name;
-    } catch (e) {
-        log.error(e.message);
-        error.push({"errorMessage": e.message});
-    }
-
-    //get the detail view for each listing
-    if (elements.action != 'new' && isEdit) {
-        formTitle = formData.title + ' Details - ' + elements.action;
-
-        var formtype = elements.formtype,
-                id = escape(elements.action);
-
-        switch (formtype) {
-            case "applicationpolicies":
-                formDataEdit = util.RESTCalls.getPolicyApplication(id);
-                break;
-        }
-    }
 
     if(!elements){
         elements = 
uriMatcher.match('/{context}/applications/{formtype}/{applicationId}/{action}');
@@ -88,6 +59,17 @@ if (!elements) {
         }
 
     }else{
+
+        try {
+            var formData = require('controllers/forms/schema/applications/' + 
elements.formtype + '.json'),
+                    formDataRaw = 
require('controllers/forms/default/applications/' + elements.formtype + 
'.json'),
+                    formTitle = formData.title,
+                    buttonText = formData.name;
+        } catch (e) {
+            log.error(e.message);
+            error.push({"errorMessage": e.message});
+        }
+
         isForm = true;
         if (elements.formtype == 'applications' && elements.action != 'new') {
 
@@ -102,9 +84,25 @@ if (!elements) {
         }else  if(elements.formtype == 'groups' && elements.action == 'new'){
             applicationHbs = 'applicationsGroupEditor';
             editorCartridges = util.RESTCalls.getCartridges();
-        }else  if(elements.formtype == 'groups' && elements.action != 'new'){
+        }else  if( (elements.formtype == 'groups' || elements.formtype == 
'applicationpolicies') && elements.action != 'new'){
             isEdit = true;
 
+            //get the detail view for each listing
+            if (elements.action != 'new' && isEdit) {
+                formTitle = formData.title + ' Details - ' + elements.action;
+
+                var formtype = elements.formtype,
+                        id = escape(elements.action);
+
+                switch (formtype) {
+                    case "applicationpolicies":
+                        formDataEdit = util.RESTCalls.getPolicyApplication(id);
+                        break;
+                    case "groups":
+                        formDataEdit = 
util.RESTCalls.getPolicyCartridgeGroup(id);
+                        break;
+                }
+            }
         }
 
     }
@@ -121,13 +119,6 @@ switch (formtype) {
         list_data = util.RESTCalls.getGroups();
         if (list_data && list_data.length === 0) {
             list_data = null;
-        }else{
-            formDataEdit = list_data;
-            for (specNumber in list_data) {
-                if (list_data[specNumber].name == elements.action) {
-                    formDataEdit = list_data[specNumber];
-                }
-            }
         }
         break;
     case "applications":

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcc4b2d7/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag
 
b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag
index fe05283..f14e49e 100644
--- 
a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag
+++ 
b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag
@@ -173,6 +173,10 @@ RESTCalls = new function(){
         return 
this.sendReceive("GET","/applicationPolicies/"+applicationPolicyId,{});
     };
 
+    this.getPolicyCartridgeGroup = function(cartridgeGroupId){
+        return this.sendReceive("GET","/cartridgeGroups/"+cartridgeGroupId,{});
+    };
+
     this.getPolicyAutoScale = function(autoscalePolicyId){
         return 
this.sendReceive("GET","/autoscalingPolicies/"+autoscalePolicyId,{});
     };

Reply via email to