aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/resources/META-INF/resources/designer/scripts/CldsTemplateService.js
blob: 3d43138644a97137ca462e4c08ef20d98164b77a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*-
 * ============LICENSE_START=======================================================
 * ONAP CLAMP
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 *                             reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * ============LICENSE_END============================================
 * ===================================================================
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 */

app.service('cldsTemplateService', ['alertService', '$http', '$q', function (alertService, $http, $q) {
    this.getTemplate = function(templateName){
    	
    	console.log("///////////////cldsTemplateService");
    	var def = $q.defer();
    	var sets = [];
    	
    	var svcUrl = "/restservices/clds/v1/cldsTempate/template/" + templateName;                
    	
        $http.get(svcUrl)
        .success(function(data){ 
        console.log("success");       	
        	def.resolve(data);         	
        	
        })
        .error(function(data){  
        console.log("error");     	 	      
       	 	def.reject("Open Model not successful");
        });
        
        return def.promise;
    };
    this.getSavedTemplate=function(){
        console.log("getSavedTemplate");
    	var def = $q.defer();
    	var sets = [];
    	
    	var svcUrl = "/restservices/clds/v1/cldsTempate/template-names";                
    	
        $http.get(svcUrl)
        .success(function(data){
        console.log("success");        	
        	def.resolve(data);         	
        	
        })
        .error(function(data){
        console.log("error");       	 	      
       	 	def.reject("Open Model not successful");
        });
        
        return def.promise;
    };
    this.setTemplate = function(templateName, controlNamePrefixIn, bpmnTextIn, propTextIn){
    	
    	console.log("setTemplate");
    	var def = $q.defer();
    	var sets = [];

    	var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;        
        var svcRequest = {name: templateName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn};
        
    	
        $http.put(svcUrl, svcRequest)
        .success(function(data){ 
        console.log("success");       	
        	def.resolve(data);         	
        	
        })
        .error(function(data){ 
        console.log("error");      	 	      
       	 	def.reject("Save Model not successful");
        });
        
        return def.promise;
    };
    this.processAction = function(uiAction, templateName, controlNamePrefixIn, bpmnTextIn, propTextIn,svgXmlIn){
    	
    	console.log("processAction");
    	var def = $q.defer();
    	var sets = [];
    	console.log("Generated SVG xml File...");
    	console.log(propTextIn);
    	var svcUrl = "/restservices/clds/v1/cldsTempate/template/"+templateName;        
    		
        var svcRequest = {name: templateName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn, imageText:svgXmlIn};      
        $http.put(svcUrl, svcRequest)
        .success(function(data){
        console.log("success");        	
        	def.resolve(data);         	
        	alertService.alertMessage("Action Successful:"+uiAction,1)

        })
        .error(function(data){
        console.log("error");       	 	      
       	 	def.reject(" not successful");
        	alertService.alertMessage("Action Failure:"+uiAction,2)

        });
        
        return def.promise;
    };
    this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd){
        console.log("checkPermittedActionCd");
       	if ( permittedActionCd.indexOf(actionCd) > -1 ) {
       		document.getElementById(menuText).classList.remove('ThisLink');
       	} else {
       		document.getElementById(menuText).classList.add('ThisLink');
       	}
    };        
    this.processActionResponse = function(templateName, pars){
        console.log("processActionResponse");
    	// populate control name (prefix and uuid here)
       	var controlNamePrefix = pars.controlNamePrefix;
       	var controlNameUuid = pars.controlNameUuid;
        
        var headerText = "Closed Loop Modeler - " + templateName;
        if ( controlNameUuid != null ) {
        	var actionCd = pars.event.actionCd;
        	var actionStateCd = pars.event.actionStateCd;
//        	headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
        	headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
        }
        	
    	document.getElementById("modeler_name").textContent = headerText;

       	
       	// enable menu options
       	document.getElementById('Save Template').classList.remove('ThisLink');
    	document.getElementById('Template Properties').classList.remove('ThisLink');
    	document.getElementById('Test').classList.remove('ThisLink');
        if(!pars.newTemplate){
            document.getElementById('Revert Template Changes').classList.remove('ThisLink');    
        }    	
    	document.getElementById('Close Template').classList.remove('ThisLink');
    	
    	document.getElementById('Refresh Status').classList.remove('ThisLink');
    	//disable save/properties for model
    	document.getElementById('Save CL').classList.add('ThisLink');
    	document.getElementById('Properties CL').classList.add('ThisLink');
    	document.getElementById('Revert Model Changes').classList.add('ThisLink');
    	document.getElementById('Close Model').classList.add('ThisLink');
    	document.getElementById('Refresh ASDC').classList.add('ThisLink');
    	document.getElementById('Running Instances').classList.add('ThisLink');

       	
    };        
 }]);