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) {
26 function checkIfElementType(name){
27 //This will open the methods located in the app.js
28 if (undefined == name) {
33 'stringmatch': StringMatchWindow,
35 'policy': PolicyWindow,
36 'collector': CollectorsWindow,
37 'vescollector': VesCollectorWindow,
38 'holmes': HolmesWindow,
41 key = name.split('_')[0].toLowerCase()
47 this.toggleDeploy = function (uiAction, modelName, controlNamePrefixIn,
48 bpmnTextIn, propTextIn, svgXmlIn, templateName, typeID, controlNameUuid, modelEventService, deploymentId) {
52 var action = uiAction.toLowerCase();
53 var deployUrl = "/restservices/clds/v1/clds/"+action+"/"+modelName;
54 var requestData = {name: modelName,
55 controlNamePrefix: controlNamePrefixIn,
59 templateName:templateName,
61 controlNameUuid: controlNameUuid,
62 event:modelEventService,
63 deploymentId:deploymentId};
65 $http.put(deployUrl,requestData)
66 .success(function(data){
67 deploymentId = data.deploymentId;
69 alertService.alertMessage("Action Successful:"+uiAction,1)
71 .error(function(data){
72 alertService.alertMessage("Action Failure:"+uiAction,2)
73 def.reject("Save Model not successful");
79 this.getASDCServices = function(){
85 var svcUrl = "/restservices/clds/v1/clds/sdc/services/";
88 .success(function(data){
93 .error(function(data){
94 def.reject("sdc Services not found");
102 this.getASDCService = function(uuid){
105 var def = $q.defer();
108 var svcUrl = "/restservices/clds/v1/clds/sdc/services/" + uuid;
111 .success(function(data){
115 .error(function(data){
116 def.reject("SDC service not found");
121 this.getModel = function(modelName){
124 var def = $q.defer();
126 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
129 .success(function(data){
133 .error(function(data){
134 def.reject("Open Model not successful");
139 this.getSavedModel=function(){
141 var def = $q.defer();
144 var svcUrl = "/restservices/clds/v1/clds/model-names";
147 .success(function(data){
151 .error(function(data){
152 def.reject("Open Model not successful");
157 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn, propTextIn){
160 var def = $q.defer();
162 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
163 var svcRequest = {name: modelName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn};
166 $http.put(svcUrl, svcRequest)
167 .success(function(data){
171 .error(function(data){
172 def.reject("Save Model not successful");
177 this.processAction = function(uiAction, modelName, controlNamePrefixIn, bpmnTextIn, propTextIn,svgXmlIn,templateName,typeID,deploymentId){
180 var def = $q.defer();
183 //console.log(svgXmlIn);
184 var svcUrl = "/restservices/clds/v1/clds/";
185 var svcAction = uiAction.toLowerCase();
186 if ( svcAction == "save" || svcAction == "refresh" ) {
187 svcUrl = svcUrl + "model/" + modelName;
188 } else if ( svcAction == "test" ) {
189 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
191 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
194 var svcRequest = {name: modelName, controlNamePrefix: controlNamePrefixIn, bpmnText: bpmnTextIn, propText: propTextIn, imageText:svgXmlIn, templateName:templateName, typeId:typeID, deploymentId:deploymentId};
196 $http.put(svcUrl, svcRequest)
197 .success(function(data){
199 alertService.alertMessage("Action Successful:"+uiAction,1)
202 .error(function(data){
203 alertService.alertMessage("Action Failure:"+uiAction,2);
204 //def alertService.alertMessage("Action Successful:"+uiAction,1);
205 def.reject(svcAction + " not successful");
210 this.manageAction = function(modelName,typeId,typeName){
211 var def = $q.defer();
215 url: "/restservices/clds/v1/clds/getDispatcherInfo",
217 params:{model:modelName,typeId:typeId,typeName:typeName}
220 .success(function(data){
224 .error(function(data){
225 def.reject("manage action not successful");
231 this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd){
232 if ( permittedActionCd.indexOf(actionCd) > -1 ) {
233 document.getElementById(menuText).classList.remove('ThisLink');
235 document.getElementById(menuText).classList.add('ThisLink');
238 this.processActionResponse = function(modelName, pars){
240 // populate control name (prefix and uuid here)
241 var controlNamePrefix = pars.controlNamePrefix;
242 var controlNameUuid = pars.controlNameUuid;
243 deploymentId = pars.deploymentId;
244 var modelEventService = pars.modelEventService;
245 typeID = pars.typeId;
247 var headerText = "Closed Loop Modeler - " + modelName;
248 if ( controlNameUuid != null ) {
249 var actionCd = pars.event.actionCd;
250 var actionStateCd = pars.event.actionStateCd;
251 //headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
252 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
255 document.getElementById("modeler_name").textContent = headerText;
256 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
258 disableBPMNAddSVG(pars);
259 this.enableDisableMenuOptions(pars);
264 this.processRefresh=function(pars){
265 typeID = pars.typeId;
266 deploymentId = pars.deploymentId;
268 this.enableDisableMenuOptions(pars);
270 function setStatus(pars){
272 var status = pars.status;
273 // apply color to status
274 var statusColor='white';
275 if(status.trim()==="DESIGN"){
277 } else if(status.trim()==="DISTRIBUTED"){
279 } else if(status.trim()==="ACTIVE"){
281 } else if(status.trim()==="STOPPED"){
283 } else if(status.trim()==="DELETING"){
285 } else if(status.trim()==="ERROR"){
287 } else if(status.trim()==="UNKNOWN"){
294 var statusMsg='<span style="background-color:' + statusColor + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '+status+' </span>';
296 if ($("#status_clds").length>=1)
297 $("#status_clds").remove();
298 $("#activity_modeler").append('<span id="status_clds" style="position: absolute; left: 61%;top: 51px; font-size:20px;">Status: '+statusMsg+'</span>');
302 function disableBPMNAddSVG(pars){
304 var svg=pars.imageText.substring(pars.imageText.indexOf("<svg"))
305 if($("#svgContainer").length>0)
306 $("#svgContainer").remove();
307 $("#js-canvas").append("<span id=\"svgContainer\">"+svg+"</span>");
308 /* added code for height width viewBox */
309 $("#svgContainer svg").removeAttr("height");
310 $("#svgContainer svg").removeAttr('viewBox');
311 $("#svgContainer svg").removeAttr('width');
313 $("#svgContainer svg").attr('width','100%');
314 $("#svgContainer svg").attr('height','100%');
316 $("#svgContainer").click(function(event){
317 //console.log($(event.target).parent().html())
318 //console.log($($(event.target).parent()).attr("data-element-id"))
319 var name=$($(event.target).parent()).attr("data-element-id")
320 lastElementSelected=$($(event.target).parent()).attr("data-element-id")
321 checkIfElementType(name)
324 $(".bjs-container").attr("hidden","");
326 this.enableDisableMenuOptions=function(pars){
328 var permittedActionCd = pars.permittedActionCd;
330 //dropdown options - always true
331 document.getElementById('Open Template').classList.remove('ThisLink');
332 document.getElementById('Open CL').classList.remove('ThisLink');
333 document.getElementById('Save Template').classList.add('ThisLink');
334 document.getElementById('Template Properties').classList.add('ThisLink');
335 document.getElementById('Revert Template Changes').classList.add('ThisLink');
336 document.getElementById('Close Template').classList.add('ThisLink');
338 if (readOnly||readMOnly){
339 //enable model options
340 document.getElementById('Properties CL').classList.remove('ThisLink');
341 document.getElementById('Close Model').classList.remove('ThisLink');
343 //disable models options
344 document.getElementById('Create CL').classList.add('ThisLink');
345 document.getElementById('Save CL').classList.add('ThisLink');
346 document.getElementById('Revert Model Changes').classList.add('ThisLink');
348 // enable menu options
349 document.getElementById('Create CL').classList.remove('ThisLink');
350 document.getElementById('Save CL').classList.remove('ThisLink');
351 document.getElementById('Properties CL').classList.remove('ThisLink');
352 document.getElementById('Revert Model Changes').classList.remove('ThisLink');
353 document.getElementById('Close Model').classList.remove('ThisLink');
356 document.getElementById('Validation Test').classList.remove('ThisLink');
357 document.getElementById('Refresh Status').classList.remove('ThisLink');
358 document.getElementById('Refresh ASDC').classList.remove('ThisLink');
361 document.getElementById('Create Template').classList.add('ThisLink');
363 document.getElementById('Create Template').classList.remove('ThisLink');
366 // enable/disable menu options based on permittedActionCd list
367 this.checkPermittedActionCd(permittedActionCd, 'Validation Test', 'TEST');
368 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
369 this.checkPermittedActionCd(permittedActionCd, 'Resubmit', 'RESUBMIT');
370 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
371 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
372 this.checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
373 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
374 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
375 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy', 'UNDEPLOY');
380 this.getASDCServices().then(function(pars){
382 var services=pars.service;
383 asdc_Services=services