[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / CldsTemplateService.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 app.service('cldsTemplateService', ['alertService', '$http', '$q', function (alertService, $http, $q) {
25     this.getTemplate = function(templateName){
26         
27         console.log("///////////////cldsTemplateService");
28         var def = $q.defer();
29         var sets = [];
30         
31         var svcUrl = "/restservices/clds/v1/cldsTempate/template/" + templateName;                
32         
33         $http.get(svcUrl)
34         .success(function(data){ 
35         console.log("success");         
36                 def.resolve(data);              
37                 
38         })
39         .error(function(data){  
40         console.log("error");                         
41                 def.reject("Open Model not successful");
42         });
43         
44         return def.promise;
45     };
46     this.getSavedTemplate=function(){
47         console.log("getSavedTemplate");
48         var def = $q.defer();
49         var sets = [];
50         
51         var svcUrl = "/restservices/clds/v1/cldsTempate/template-names";                
52         
53         $http.get(svcUrl)
54         .success(function(data){
55         console.log("success");         
56                 def.resolve(data);              
57                 
58         })
59         .error(function(data){
60         console.log("error");                         
61                 def.reject("Open Model not successful");
62         });
63         
64         return def.promise;
65     };
66     this.setTemplate = function(templateName, controlNamePrefixIn, bpmnTextIn, propTextIn){
67         
68         console.log("setTemplate");
69         var def = $q.defer();
70         var sets = [];
71
72         var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;        
73         var svcRequest = {name: templateName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn};
74         
75         
76         $http.put(svcUrl, svcRequest)
77         .success(function(data){ 
78         console.log("success");         
79                 def.resolve(data);              
80                 
81         })
82         .error(function(data){ 
83         console.log("error");                         
84                 def.reject("Save Model not successful");
85         });
86         
87         return def.promise;
88     };
89     this.processAction = function(uiAction, templateName, controlNamePrefixIn, bpmnTextIn, propTextIn,svgXmlIn){
90         
91         console.log("processAction");
92         var def = $q.defer();
93         var sets = [];
94         console.log("Generated SVG xml File...");
95         console.log(propTextIn);
96         var svcUrl = "/restservices/clds/v1/cldsTempate/template/"+templateName;        
97                 
98         var svcRequest = {name: templateName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn, imageText:svgXmlIn};      
99         $http.put(svcUrl, svcRequest)
100         .success(function(data){
101         console.log("success");         
102                 def.resolve(data);              
103                 alertService.alertMessage("Action Successful:"+uiAction,1)
104
105         })
106         .error(function(data){
107         console.log("error");                         
108                 def.reject(" not successful");
109                 alertService.alertMessage("Action Failure:"+uiAction,2)
110
111         });
112         
113         return def.promise;
114     };
115     this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd){
116         console.log("checkPermittedActionCd");
117         if ( permittedActionCd.indexOf(actionCd) > -1 ) {
118                 document.getElementById(menuText).classList.remove('ThisLink');
119         } else {
120                 document.getElementById(menuText).classList.add('ThisLink');
121         }
122     };        
123     this.processActionResponse = function(templateName, pars){
124         console.log("processActionResponse");
125         // populate control name (prefix and uuid here)
126         var controlNamePrefix = pars.controlNamePrefix;
127         var controlNameUuid = pars.controlNameUuid;
128         
129         var headerText = "Closed Loop Modeler - " + templateName;
130         if ( controlNameUuid != null ) {
131                 var actionCd = pars.event.actionCd;
132                 var actionStateCd = pars.event.actionStateCd;
133 //              headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
134                 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
135         }
136                 
137         document.getElementById("modeler_name").textContent = headerText;
138
139         
140         // enable menu options
141         document.getElementById('Save Template').classList.remove('ThisLink');
142         document.getElementById('Template Properties').classList.remove('ThisLink');
143         document.getElementById('Test').classList.remove('ThisLink');
144         if(!pars.newTemplate){
145             document.getElementById('Revert Template Changes').classList.remove('ThisLink');    
146         }       
147         document.getElementById('Close Template').classList.remove('ThisLink');
148         
149         document.getElementById('Refresh Status').classList.remove('ThisLink');
150         //disable save/properties for model
151         document.getElementById('Save CL').classList.add('ThisLink');
152         document.getElementById('Properties CL').classList.add('ThisLink');
153         document.getElementById('Revert Model Changes').classList.add('ThisLink');
154         document.getElementById('Close Model').classList.add('ThisLink');
155         document.getElementById('Refresh ASDC').classList.add('ThisLink');
156         document.getElementById('Running Instances').classList.add('ThisLink');
157
158         
159     };        
160  }]);