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) {
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;
165 controlNamePrefix: controlNamePrefixIn,
166 bpmnText: bpmnTextIn,
171 $http.put(svcUrl, svcRequest)
172 .success(function(data) {
176 .error(function(data) {
177 def.reject("Save Model not successful");
182 this.processAction = function(uiAction, modelName, controlNamePrefixIn, bpmnTextIn, propTextIn, svgXmlIn, templateName, typeID, deploymentId) {
185 var def = $q.defer();
188 //console.log(svgXmlIn);
189 var svcUrl = "/restservices/clds/v1/clds/";
190 var svcAction = uiAction.toLowerCase();
191 if (svcAction == "save" || svcAction == "refresh") {
192 svcUrl = svcUrl + "model/" + modelName;
193 } else if (svcAction == "test") {
194 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
196 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
201 controlNamePrefix: controlNamePrefixIn,
202 bpmnText: bpmnTextIn,
203 propText: propTextIn,
205 templateName: templateName,
207 deploymentId: deploymentId
210 $http.put(svcUrl, svcRequest)
211 .success(function(data) {
213 alertService.alertMessage("Action Successful:" + uiAction, 1)
216 .error(function(data) {
218 alertService.alertMessage("Action Failure:" + uiAction, 2);
219 //def alertService.alertMessage("Action Successful:"+uiAction,1);
220 def.reject(svcAction + " not successful");
225 this.manageAction = function(modelName, typeId, typeName) {
226 var def = $q.defer();
230 url: "/restservices/clds/v1/clds/getDispatcherInfo",
239 .success(function(data) {
243 .error(function(data) {
244 def.reject("manage action not successful");
250 this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd) {
251 if (permittedActionCd.indexOf(actionCd) > -1) {
252 document.getElementById(menuText).classList.remove('ThisLink');
254 document.getElementById(menuText).classList.add('ThisLink');
257 this.processActionResponse = function(modelName, pars) {
259 // populate control name (prefix and uuid here)
260 var controlNamePrefix = pars.controlNamePrefix;
261 var controlNameUuid = pars.controlNameUuid;
262 deploymentId = pars.deploymentId;
263 var modelEventService = pars.modelEventService;
264 typeID = pars.typeId;
266 var headerText = "Closed Loop Modeler - " + modelName;
267 if (controlNameUuid != null) {
268 var actionCd = pars.event.actionCd;
269 var actionStateCd = pars.event.actionStateCd;
270 //headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
271 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
274 document.getElementById("modeler_name").textContent = headerText;
275 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
278 this.enableDisableMenuOptions(pars);
283 this.processRefresh = function(pars) {
284 typeID = pars.typeId;
285 deploymentId = pars.deploymentId;
287 this.enableDisableMenuOptions(pars);
288 elementMap = JSON.parse(pars.propText);
291 function setStatus(pars) {
293 var status = pars.status;
294 // apply color to status
295 var statusColor = 'white';
296 if (status.trim() === "DESIGN") {
298 } else if (status.trim() === "DISTRIBUTED") {
300 } else if (status.trim() === "ACTIVE") {
301 statusColor = 'green'
302 } else if (status.trim() === "STOPPED") {
304 } else if (status.trim() === "DELETING") {
306 } else if (status.trim() === "ERROR") {
307 statusColor = 'orange'
308 } else if (status.trim() === "UNKNOWN") {
315 var statusMsg = '<span style="background-color:' + statusColor + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> ' + status + ' </span>';
317 if ($("#status_clds").length >= 1)
318 $("#status_clds").remove();
319 $("#activity_modeler").append('<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: ' + statusMsg + '</span>');
324 function addSVG(pars) {
326 var svg = pars.imageText.substring(pars.imageText.indexOf("<svg"))
327 if ($("#svgContainer").length > 0)
328 $("#svgContainer").remove();
329 $("#js-canvas").append("<span id=\"svgContainer\">" + svg + "</span>");
330 /* added code for height width viewBox */
331 $("#svgContainer svg").removeAttr("height");
332 $("#svgContainer svg").removeAttr('viewBox');
333 $("#svgContainer svg").removeAttr('width');
335 $("#svgContainer svg").attr('width', '100%');
336 $("#svgContainer svg").attr('height', '100%');
338 $("#svgContainer").click(function(event) {
339 //console.log($(event.target).parent().html())
340 //console.log($($(event.target).parent()).attr("data-element-id"))
341 var name = $($(event.target).parent()).attr("data-element-id")
342 lastElementSelected = $($(event.target).parent()).attr("data-element-id")
343 checkIfElementType(name)
347 this.enableDisableMenuOptions = function(pars) {
349 var permittedActionCd = pars.permittedActionCd;
351 //dropdown options - always true
352 document.getElementById('Open CL').classList.remove('ThisLink');
355 //enable model options
356 document.getElementById('Properties CL').classList.remove('ThisLink');
357 document.getElementById('Close Model').classList.remove('ThisLink');
359 //disable models options
360 document.getElementById('Create CL').classList.add('ThisLink');
361 document.getElementById('Save CL').classList.add('ThisLink');
362 document.getElementById('Revert Model Changes').classList.add('ThisLink');
364 // enable menu options
365 document.getElementById('Create CL').classList.remove('ThisLink');
366 document.getElementById('Save CL').classList.remove('ThisLink');
367 document.getElementById('Properties CL').classList.remove('ThisLink');
368 document.getElementById('Revert Model Changes').classList.remove('ThisLink');
369 document.getElementById('Close Model').classList.remove('ThisLink');
372 document.getElementById('Validation Test').classList.remove('ThisLink');
373 document.getElementById('Refresh Status').classList.remove('ThisLink');
374 document.getElementById('Refresh ASDC').classList.remove('ThisLink');
377 // enable/disable menu options based on permittedActionCd list
378 this.checkPermittedActionCd(permittedActionCd, 'Validation Test', 'TEST');
379 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
380 this.checkPermittedActionCd(permittedActionCd, 'Resubmit', 'RESUBMIT');
381 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
382 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
383 this.checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
384 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
385 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
386 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy', 'UNDEPLOY');
391 this.getASDCServices().then(function(pars) {
393 var services = pars.service;
394 asdc_Services = services