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 * ===================================================================
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) {
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) {
217 alertService.alertMessage("Action Failure:" + uiAction, 2);
218 //def alertService.alertMessage("Action Successful:"+uiAction,1);
219 def.reject(svcAction + " not successful");
224 this.manageAction = function(modelName, typeId, typeName) {
225 var def = $q.defer();
229 url: "/restservices/clds/v1/clds/getDispatcherInfo",
238 .success(function(data) {
242 .error(function(data) {
243 def.reject("manage action not successful");
249 this.checkPermittedActionCd = function(permittedActionCd, menuText, actionCd) {
250 if (permittedActionCd.indexOf(actionCd) > -1) {
251 document.getElementById(menuText).classList.remove('ThisLink');
253 document.getElementById(menuText).classList.add('ThisLink');
256 this.processActionResponse = function(modelName, pars) {
258 // populate control name (prefix and uuid here)
259 var controlNamePrefix = pars.controlNamePrefix;
260 var controlNameUuid = pars.controlNameUuid;
261 deploymentId = pars.deploymentId;
262 var modelEventService = pars.modelEventService;
263 typeID = pars.typeId;
265 var headerText = "Closed Loop Modeler - " + modelName;
266 if (controlNameUuid != null) {
267 var actionCd = pars.event.actionCd;
268 var actionStateCd = pars.event.actionStateCd;
269 //headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "] [" + actionCd + ":" + actionStateCd + "]";
270 headerText = headerText + " [" + controlNamePrefix + controlNameUuid + "]";
273 document.getElementById("modeler_name").textContent = headerText;
274 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
277 this.enableDisableMenuOptions(pars);
282 this.processRefresh = function(pars) {
283 typeID = pars.typeId;
284 deploymentId = pars.deploymentId;
286 this.enableDisableMenuOptions(pars);
289 function setStatus(pars) {
291 var status = pars.status;
292 // apply color to status
293 var statusColor = 'white';
294 if (status.trim() === "DESIGN") {
296 } else if (status.trim() === "DISTRIBUTED") {
298 } else if (status.trim() === "ACTIVE") {
299 statusColor = 'green'
300 } else if (status.trim() === "STOPPED") {
302 } else if (status.trim() === "DELETING") {
304 } else if (status.trim() === "ERROR") {
305 statusColor = 'orange'
306 } else if (status.trim() === "UNKNOWN") {
313 var statusMsg = '<span style="background-color:' + statusColor + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> ' + status + ' </span>';
315 if ($("#status_clds").length >= 1)
316 $("#status_clds").remove();
317 $("#activity_modeler").append('<span id="status_clds" style="position: absolute; left: 61%;top: 51px; font-size:20px;">Status: ' + statusMsg + '</span>');
322 function addSVG(pars) {
324 var svg = pars.imageText.substring(pars.imageText.indexOf("<svg"))
325 if ($("#svgContainer").length > 0)
326 $("#svgContainer").remove();
327 $("#js-canvas").append("<span id=\"svgContainer\">" + svg + "</span>");
328 /* added code for height width viewBox */
329 $("#svgContainer svg").removeAttr("height");
330 $("#svgContainer svg").removeAttr('viewBox');
331 $("#svgContainer svg").removeAttr('width');
333 $("#svgContainer svg").attr('width', '100%');
334 $("#svgContainer svg").attr('height', '100%');
336 $("#svgContainer").click(function(event) {
337 //console.log($(event.target).parent().html())
338 //console.log($($(event.target).parent()).attr("data-element-id"))
339 var name = $($(event.target).parent()).attr("data-element-id")
340 lastElementSelected = $($(event.target).parent()).attr("data-element-id")
341 checkIfElementType(name)
345 this.enableDisableMenuOptions = function(pars) {
347 var permittedActionCd = pars.permittedActionCd;
349 //dropdown options - always true
350 document.getElementById('Open CL').classList.remove('ThisLink');
353 //enable model options
354 document.getElementById('Properties CL').classList.remove('ThisLink');
355 document.getElementById('Close Model').classList.remove('ThisLink');
357 //disable models options
358 document.getElementById('Create CL').classList.add('ThisLink');
359 document.getElementById('Save CL').classList.add('ThisLink');
360 document.getElementById('Revert Model Changes').classList.add('ThisLink');
362 // enable menu options
363 document.getElementById('Create CL').classList.remove('ThisLink');
364 document.getElementById('Save CL').classList.remove('ThisLink');
365 document.getElementById('Properties CL').classList.remove('ThisLink');
366 document.getElementById('Revert Model Changes').classList.remove('ThisLink');
367 document.getElementById('Close Model').classList.remove('ThisLink');
370 document.getElementById('Validation Test').classList.remove('ThisLink');
371 document.getElementById('Refresh Status').classList.remove('ThisLink');
372 document.getElementById('Refresh ASDC').classList.remove('ThisLink');
375 // enable/disable menu options based on permittedActionCd list
376 this.checkPermittedActionCd(permittedActionCd, 'Validation Test', 'TEST');
377 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
378 this.checkPermittedActionCd(permittedActionCd, 'Resubmit', 'RESUBMIT');
379 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
380 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
381 this.checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
382 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
383 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
384 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy', 'UNDEPLOY');
389 this.getASDCServices().then(function(pars) {
391 var services = pars.service;
392 asdc_Services = services