2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ===================================================================
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) {
34 'policy': PolicyWindow,
35 'vescollector': VesCollectorWindow,
36 'holmes': HolmesWindow,
39 key = name.split('_')[0].toLowerCase()
45 this.toggleDeploy = function(uiAction, modelName, controlNamePrefixIn,
46 bpmnTextIn, propTextIn, svgXmlIn, templateName, typeID, controlNameUuid, modelEventService, deploymentId) {
50 var action = uiAction.toLowerCase();
51 var deployUrl = "/restservices/clds/v1/clds/" + action + "/" + modelName;
54 controlNamePrefix: controlNamePrefixIn,
58 templateName: templateName,
60 controlNameUuid: controlNameUuid,
61 event: modelEventService,
62 deploymentId: deploymentId
65 $http.put(deployUrl, requestData)
66 .success(function(data) {
68 if (typeof data.body !== 'undefined') {
71 deploymentId = newData.deploymentId;
73 alertService.alertMessage("Action Successful:" + uiAction, 1)
75 .error(function(data) {
76 alertService.alertMessage("Action Failure:" + uiAction, 2)
77 def.reject("Save Model not successful");
83 this.getASDCServices = function() {
89 var svcUrl = "/restservices/clds/v1/clds/sdc/services/";
92 .success(function(data) {
97 .error(function(data) {
98 def.reject("sdc Services not found");
106 this.getASDCService = function(uuid) {
109 var def = $q.defer();
112 var svcUrl = "/restservices/clds/v1/clds/sdc/services/" + uuid;
115 .success(function(data) {
119 .error(function(data) {
120 def.reject("SDC service not found");
125 this.getModel = function(modelName) {
128 var def = $q.defer();
130 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
133 .success(function(data) {
137 .error(function(data) {
138 def.reject("Open Model not successful");
143 this.getSavedModel = function() {
145 var def = $q.defer();
148 var svcUrl = "/restservices/clds/v1/clds/model-names";
151 .success(function(data) {
155 .error(function(data) {
156 def.reject("Open Model not successful");
161 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn, propTextIn) {
164 var def = $q.defer();
166 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
169 controlNamePrefix: controlNamePrefixIn,
170 bpmnText: bpmnTextIn,
175 $http.put(svcUrl, svcRequest)
176 .success(function(data) {
180 .error(function(data) {
181 def.reject("Save Model not successful");
186 this.processAction = function(uiAction, modelName, controlNamePrefixIn, bpmnTextIn, propTextIn, svgXmlIn, templateName, typeID, deploymentId) {
189 var def = $q.defer();
192 //console.log(svgXmlIn);
193 var svcUrl = "/restservices/clds/v1/clds/";
194 var svcAction = uiAction.toLowerCase();
195 if (svcAction == "save" || svcAction == "refresh") {
196 svcUrl = svcUrl + "model/" + modelName;
197 } else if (svcAction == "test") {
198 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
200 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
205 controlNamePrefix: controlNamePrefixIn,
206 bpmnText: bpmnTextIn,
207 propText: propTextIn,
209 templateName: templateName,
211 deploymentId: deploymentId
214 $http.put(svcUrl, svcRequest)
215 .success(function(data) {
217 alertService.alertMessage("Action Successful:" + uiAction, 1)
220 .error(function(data) {
222 alertService.alertMessage("Action Failure:" + uiAction, 2);
223 //def alertService.alertMessage("Action Successful:"+uiAction,1);
224 def.reject(svcAction + " not successful");
229 this.manageAction = function(modelName, typeId, typeName) {
230 var def = $q.defer();
234 url: "/restservices/clds/v1/clds/getDispatcherInfo",
243 .success(function(data) {
247 .error(function(data) {
248 def.reject("manage action not successful");
254 this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd) {
255 if (permittedActionCd.indexOf(actionCd) > -1) {
256 document.getElementById(menuText).classList.remove('ThisLink');
258 document.getElementById(menuText).classList.add('ThisLink');
261 this.processActionResponse = function(modelName, pars) {
263 // populate control name (prefix and uuid here)
264 var controlNamePrefix = pars.controlNamePrefix;
265 var controlNameUuid = pars.controlNameUuid;
266 deploymentId = pars.deploymentId;
267 var modelEventService = pars.modelEventService;
268 typeID = pars.typeId;
270 var headerText = "Closed Loop Modeler - " + modelName;
271 if (controlNameUuid != null) {
272 var actionCd = pars.event.actionCd;
273 var actionStateCd = pars.event.actionStateCd;
274 //headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
275 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
278 document.getElementById("modeler_name").textContent = headerText;
279 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
282 this.enableDisableMenuOptions(pars);
287 this.processRefresh = function(pars) {
289 if (typeof pars.body !== 'undefined') {
292 typeID = newPars.typeId;
293 deploymentId = newPars.deploymentId;
295 this.enableDisableMenuOptions(newPars);
296 elementMap = JSON.parse(newPars.propText);
299 function setStatus(pars) {
301 var status = pars.status;
302 // apply color to status
303 var statusColor = 'white';
304 if (status.trim() === "DESIGN") {
306 } else if (status.trim() === "DISTRIBUTED") {
308 } else if (status.trim() === "ACTIVE") {
309 statusColor = 'green'
310 } else if (status.trim() === "STOPPED") {
312 } else if (status.trim() === "DELETING") {
314 } else if (status.trim() === "ERROR") {
315 statusColor = 'orange'
316 } else if (status.trim() === "UNKNOWN") {
323 var statusMsg = '<span style="background-color:' + statusColor + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> ' + status + ' </span>';
325 if ($("#status_clds").length >= 1)
326 $("#status_clds").remove();
327 $("#activity_modeler").append('<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: ' + statusMsg + '</span>');
332 function addSVG(pars) {
334 var svg = pars.imageText.substring(pars.imageText.indexOf("<svg"))
335 if ($("#svgContainer").length > 0)
336 $("#svgContainer").remove();
337 $("#js-canvas").append("<span id=\"svgContainer\">" + svg + "</span>");
338 /* added code for height width viewBox */
339 $("#svgContainer svg").removeAttr("height");
340 $("#svgContainer svg").removeAttr('viewBox');
341 $("#svgContainer svg").removeAttr('width');
343 $("#svgContainer svg").attr('width', '100%');
344 $("#svgContainer svg").attr('height', '100%');
346 $("#svgContainer").click(function(event) {
347 //console.log($(event.target).parent().html())
348 //console.log($($(event.target).parent()).attr("data-element-id"))
349 var name = $($(event.target).parent()).attr("data-element-id")
350 lastElementSelected = $($(event.target).parent()).attr("data-element-id")
351 checkIfElementType(name)
355 this.enableDisableMenuOptions = function(pars) {
357 var permittedActionCd = pars.permittedActionCd;
359 //dropdown options - always true
360 document.getElementById('Open CL').classList.remove('ThisLink');
363 //enable model options
364 document.getElementById('Properties CL').classList.remove('ThisLink');
365 document.getElementById('Close Model').classList.remove('ThisLink');
367 //disable models options
368 document.getElementById('Create CL').classList.add('ThisLink');
369 document.getElementById('Save CL').classList.add('ThisLink');
370 document.getElementById('Revert Model Changes').classList.add('ThisLink');
372 // enable menu options
373 document.getElementById('Create CL').classList.remove('ThisLink');
374 document.getElementById('Save CL').classList.remove('ThisLink');
375 document.getElementById('Properties CL').classList.remove('ThisLink');
376 document.getElementById('Revert Model Changes').classList.remove('ThisLink');
377 document.getElementById('Close Model').classList.remove('ThisLink');
380 document.getElementById('Validation Test').classList.remove('ThisLink');
381 document.getElementById('Refresh Status').classList.remove('ThisLink');
382 document.getElementById('Refresh ASDC').classList.remove('ThisLink');
385 // enable/disable menu options based on permittedActionCd list
386 this.checkPermittedActionCd(permittedActionCd, 'Validation Test', 'TEST');
387 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
388 this.checkPermittedActionCd(permittedActionCd, 'Resubmit', 'RESUBMIT');
389 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
390 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
391 this.checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
392 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
393 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
394 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy', 'UNDEPLOY');
399 this.getASDCServices().then(function(pars) {
400 var obj = JSON.parse(pars);
401 var services = obj.service;
402 asdc_Services = services