2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 app.service('cldsModelService', ['alertService','$http', '$q', function (alertService,$http, $q) {
25 console.log("/////////////cldsModelService");
26 function checkIfElementType(name){
28 //This will open the methods located in the app.js
29 if(name.toLowerCase().indexOf("stringmatch")>=0)
31 else if(name.toLowerCase().indexOf("tca")>=0)
33 else if(name.toLowerCase().indexOf("collector")>=0)
35 else if(name.toLowerCase().indexOf("policy")>=0)
39 this.getASDCServices = function(){
41 console.log("getASDCServices");
45 var svcUrl = "/restservices/clds/v1/clds/asdc/services/";
48 .success(function(data){
53 .error(function(data){
54 def.reject("Asdc Services not found");
61 this.getRunningInstances=function(resouseInput){
62 console.log("getRunningInstances");
66 //Look in scripts/common_variables.html to get utmModel name
68 // var svcUrl = "/restservices/clds/v1/clds/model/roncl003";
69 var svcUrl = "/restservices/clds/v1/clds/model/" + resouseInput;
72 .success(function(data){
77 .error(function(data){
78 def.reject("Asdc Services not found");
84 // return [{"name":"asbg0003vm001","location":"SNANTXCA","status":"Running","view":"KPI"},{"name":"asbg0003vm002","location":"SNANTXCA","status":"Running","view":"KPI"},{"name":"asbg0003vm003","location":"SNANTXCA","status":"Running","view":"KPI"},{"name":"asbg0003vm004","location":"SNANTXCA","status":"Stopped","view":"KPI"}]
87 this.getASDCService = function(uuid){
88 console.log("getASDCService");
93 var svcUrl = "/restservices/clds/v1/clds/asdc/services/" + uuid;
96 .success(function(data){
100 .error(function(data){
101 def.reject("ASDC service not found");
106 this.getModel = function(modelName){
108 console.log("getModel");
109 var def = $q.defer();
112 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
115 .success(function(data){
119 .error(function(data){
120 def.reject("Open Model not successful");
125 this.getSavedModel=function(){
126 console.log("getSavedModel");
127 var def = $q.defer();
130 var svcUrl = "/restservices/clds/v1/clds/model-names";
133 .success(function(data){
137 .error(function(data){
138 def.reject("Open Model not successful");
143 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn, propTextIn){
145 console.log("setModel");
146 var def = $q.defer();
149 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
150 var svcRequest = {name: modelName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn};
153 $http.put(svcUrl, svcRequest)
154 .success(function(data){
158 .error(function(data){
159 def.reject("Save Model not successful");
164 this.processAction = function(uiAction, modelName, controlNamePrefixIn, bpmnTextIn, propTextIn,svgXmlIn,templateName){
166 console.log("processAction");
167 var def = $q.defer();
169 console.log("Generated SVG xml File...");
170 //console.log(svgXmlIn);
171 var svcUrl = "/restservices/clds/v1/clds/";
172 var svcAction = uiAction.toLowerCase();
173 if ( svcAction == "save" || svcAction == "refresh" ) {
174 svcUrl = svcUrl + "model/" + modelName;
175 } else if ( svcAction == "test" ) {
176 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
178 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
181 var svcRequest = {name: modelName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn, imageText:svgXmlIn, templateName:templateName};
182 console.log(svcRequest)
183 $http.put(svcUrl, svcRequest)
184 .success(function(data){
186 alertService.alertMessage("Action Successful:"+uiAction,1)
189 .error(function(data){
190 alertService.alertMessage("Action Failure:"+uiAction,2);
191 //def alertService.alertMessage("Action Successful:"+uiAction,1);
192 def.reject(svcAction + " not successful");
197 this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd){
198 console.log("checkPermittedActionCd");
199 if ( permittedActionCd.indexOf(actionCd) > -1 ) {
200 document.getElementById(menuText).classList.remove('ThisLink');
202 document.getElementById(menuText).classList.add('ThisLink');
205 this.processActionResponse = function(modelName, pars){
206 console.log("processActionResponse");
207 // populate control name (prefix and uuid here)
208 var controlNamePrefix = pars.controlNamePrefix;
209 var controlNameUuid = pars.controlNameUuid;
213 var headerText = "Closed Loop Modeler - " + modelName;
214 if ( controlNameUuid != null ) {
215 var actionCd = pars.event.actionCd;
216 var actionStateCd = pars.event.actionStateCd;
217 //headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
218 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
219 console.log("MINA PARS TEST " + headerText + " ----- " + controlNamePrefix + " ----- " + controlNameUuid + " ----- " + pars);
222 document.getElementById("modeler_name").textContent = headerText;
224 disableBPMNAddSVG(pars);
225 this.enableDisableMenuOptions(pars);
230 this.processRefresh=function(pars){
231 console.log("processRefresh");
234 function setStatus(pars){
235 console.log("setStatus");
236 var status = pars.status;
237 // apply color to status
238 var statusColor='white';
239 if(status.trim()==="DESIGN"){
241 } else if(status.trim()==="DISTRIBUTED"){
243 } else if(status.trim()==="ACTIVE"){
245 } else if(status.trim()==="STOPPED"){
247 } else if(status.trim()==="DELETING"){
249 } else if(status.trim()==="ERROR"){
251 } else if(status.trim()==="UNKNOWN"){
258 var statusMsg='<span style="background-color:' + statusColor + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '+status+' </span>';
260 if ($("#status_clds").length>=1)
261 $("#status_clds").remove();
262 $("#activity_modeler").append('<span id="status_clds" style="position: absolute; left: 61%;top: 51px; font-size:20px;">Status: '+statusMsg+'</span>');
266 function disableBPMNAddSVG(pars){
267 console.log("disableBPMNAddSVG");
268 var svg=pars.imageText.substring(pars.imageText.indexOf("<svg"))
269 if($("#svgContainer").length>0)
270 $("#svgContainer").remove();
271 $("#js-canvas").append("<span id=\"svgContainer\">"+svg+"</span>");
272 /* added code for height width viewBox */
273 $("#svgContainer svg").removeAttr("height");
274 $("#svgContainer svg").removeAttr('viewBox');
275 $("#svgContainer svg").removeAttr('width');
277 $("#svgContainer svg").attr('width','100%');
278 $("#svgContainer svg").attr('height','100%');
280 $("#svgContainer").click(function(event){
281 console.log($(event.target).parent().html())
282 console.log($($(event.target).parent()).attr("data-element-id"))
283 var name=$($(event.target).parent()).attr("data-element-id")
284 lastElementSelected=$($(event.target).parent()).attr("data-element-id")
285 checkIfElementType(name)
288 $(".bjs-container").attr("hidden","");
290 this.enableDisableMenuOptions=function(pars){
291 console.log("enableDisableMenuOptions");
292 var permittedActionCd = pars.permittedActionCd;
293 // enable menu options
294 document.getElementById('Save CL').classList.remove('ThisLink');
295 document.getElementById('Test').classList.remove('ThisLink');
296 document.getElementById('Properties CL').classList.remove('ThisLink');
297 document.getElementById('Refresh Status').classList.remove('ThisLink');
298 document.getElementById('Revert Model Changes').classList.remove('ThisLink');
299 document.getElementById('Close Model').classList.remove('ThisLink');
300 document.getElementById('Refresh ASDC').classList.remove('ThisLink');
301 document.getElementById('Running Instances').classList.remove('ThisLink');
303 //disable template options for save/properties
304 document.getElementById('Save Template').classList.add('ThisLink');
305 document.getElementById('Template Properties').classList.add('ThisLink');
306 document.getElementById('Revert Template Changes').classList.add('ThisLink');
307 document.getElementById('Close Template').classList.add('ThisLink');
310 // enable/disable menu options based on permittedActionCd list
311 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
312 this.checkPermittedActionCd(permittedActionCd, 'Resubmit', 'RESUBMIT');
313 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
314 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
315 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
316 this.checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
320 this.getASDCServices().then(function(pars){
321 console.log("getASDCServices");
322 var services=pars.service;
323 asdc_Services=services