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 * ===================================================================
31 function(alertService, $http, $q, $rootScope) {
33 function checkIfElementType(name, isSimple) {
35 //This will open the methods located in the app.js
37 if (undefined == name) {
39 }else if (name.toLowerCase().indexOf("policy") >= 0){
42 $rootScope.selectedBoxName = name.toLowerCase();
46 if (undefined == name) {
51 'policy' : PolicyWindow,
52 'vescollector' : VesCollectorWindow,
53 'holmes' : HolmesWindow,
55 key = name.split('_')[0].toLowerCase()
61 function handleQueryToBackend(def, svcAction, svcUrl, svcPayload) {
63 $http.put(svcUrl, svcPayload).success(
67 if (typeof data.statusCodeValue === 'undefined'
68 || data.statusCodeValue === 200) {
69 alertService.alertMessage(
70 "Action Successful: " + svcAction, 1)
72 if (typeof data.body !== 'undefined') {
73 alertService.alertMessage("Action Failure: "
74 + svcAction + ", " + data.body.errorMessageForUi, 2);
76 alertService.alertMessage("Action Failure: "
79 def.reject(svcAction + " not successful");
85 if (typeof data.body !== 'undefined') {
86 alertService.alertMessage("Action Failure: " + svcAction
87 + ", " + data.body.errorMessageForUi, 2);
90 .alertMessage("Action Failure: " + svcAction, 2);
92 def.reject(svcAction + " not successful");
95 this.toggleDeploy = function(uiAction, modelName, controlNamePrefixIn,
96 bpmnTextIn, propTextIn, svgXmlIn,
97 templateName, typeID, controlNameUuid,
98 modelEventService, deploymentId) {
100 var def = $q.defer();
102 var action = uiAction.toLowerCase();
103 var deployUrl = "/restservices/clds/v1/clds/" + action + "/"
107 controlNamePrefix : controlNamePrefixIn,
108 bpmnText : bpmnTextIn,
109 propText : propTextIn,
110 imageText : svgXmlIn,
111 templateName : templateName,
113 controlNameUuid : controlNameUuid,
114 event : modelEventService,
115 deploymentId : deploymentId
117 handleQueryToBackend(def, action, deployUrl, requestData);
120 this.getModel = function(modelName) {
122 var def = $q.defer();
124 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
125 $http.get(svcUrl).success(function(data) {
128 }).error(function(data) {
130 def.reject("Open Model not successful");
134 this.getSavedModel = function() {
136 var def = $q.defer();
138 var svcUrl = "/restservices/clds/v1/clds/model-names";
139 $http.get(svcUrl).success(function(data) {
142 }).error(function(data) {
144 def.reject("Open Model not successful");
148 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn,
151 var def = $q.defer();
153 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
156 controlNamePrefix : controlNamePrefixIn,
157 bpmnText : bpmnTextIn,
158 propText : propTextIn
160 $http.put(svcUrl, svcRequest).success(function(data) {
163 }).error(function(data) {
165 def.reject("Save Model not successful");
169 this.processAction = function(uiAction, modelName, controlNamePrefixIn,
170 bpmnTextIn, propTextIn, svgXmlIn,
171 templateName, typeID, deploymentId) {
173 var def = $q.defer();
175 // console.log(svgXmlIn);
176 var svcUrl = "/restservices/clds/v1/clds/";
177 var svcAction = uiAction.toLowerCase();
178 if (svcAction == "save" || svcAction == "refresh") {
179 svcUrl = svcUrl + "model/" + modelName;
180 } else if (svcAction == "test") {
181 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
183 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
187 controlNamePrefix : controlNamePrefixIn,
188 bpmnText : bpmnTextIn,
189 propText : propTextIn,
190 imageText : svgXmlIn,
191 templateName : templateName,
193 deploymentId : deploymentId
195 handleQueryToBackend(def, svcAction, svcUrl, svcRequest);
198 this.manageAction = function(modelName, typeId, typeName) {
200 var def = $q.defer();
203 url : "/restservices/clds/v1/clds/getDispatcherInfo",
211 $http(config).success(function(data) {
214 }).error(function(data) {
216 def.reject("manage action not successful");
220 this.checkPermittedActionCd = function(permittedActionCd, menuText,
223 if (permittedActionCd.indexOf(actionCd) > -1) {
224 document.getElementById(menuText).classList.remove('ThisLink');
226 document.getElementById(menuText).classList.add('ThisLink');
229 this.processActionResponse = function(modelName, pars, simple) {
231 // populate control name (prefix and uuid here)
232 var controlNamePrefix = pars.controlNamePrefix;
233 var controlNameUuid = pars.controlNameUuid;
234 deploymentId = pars.deploymentId;
235 var modelEventService = pars.modelEventService;
236 typeID = pars.typeId;
237 var headerText = "Closed Loop Modeler - " + modelName;
238 if (controlNameUuid != null) {
239 var actionCd = pars.event.actionCd;
240 var actionStateCd = pars.event.actionStateCd;
241 headerText = headerText + " [" + controlNamePrefix
242 + controlNameUuid + "]";
244 document.getElementById("modeler_name").textContent = headerText;
245 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
247 disableBPMNAddSVG(pars, simple);
248 this.enableDisableMenuOptions(pars);
250 this.processRefresh = function(pars) {
253 if (typeof pars.body !== 'undefined') {
256 typeID = newPars.typeId;
257 deploymentId = newPars.deploymentId;
259 this.enableDisableMenuOptions(newPars);
260 elementMap = JSON.parse(newPars.propText);
262 function setStatus(pars) {
264 var status = pars.status;
265 // apply color to status
266 var statusColor = 'white';
267 if (status.trim() === "DESIGN") {
269 } else if (status.trim() === "DISTRIBUTED") {
271 } else if (status.trim() === "ACTIVE") {
272 statusColor = 'green'
273 } else if (status.trim() === "STOPPED") {
275 } else if (status.trim() === "DELETING") {
277 } else if (status.trim() === "ERROR") {
278 statusColor = 'orange'
279 } else if (status.trim() === "UNKNOWN") {
284 var statusMsg = '<span style="background-color:'
286 + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '
287 + status + ' </span>';
289 if ($("#status_clds").length >= 1)
290 $("#status_clds").remove();
291 $("#activity_modeler")
293 '<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: '
294 + statusMsg + '</span>');
296 function disableBPMNAddSVG(pars, simple) {
298 var svg = pars.imageText.substring(pars.imageText.indexOf("<svg"))
299 if ($("#svgContainer").length > 0)
300 $("#svgContainer").remove();
301 $("#js-canvas").append(
302 "<span id=\"svgContainer\">" + svg + "</span>");
303 /* added code for height width viewBox */
304 $("#svgContainer svg").removeAttr("height");
305 $("#svgContainer svg").removeAttr('viewBox');
306 $("#svgContainer svg").removeAttr('width');
307 $("#svgContainer svg").attr('width', '100%');
308 $("#svgContainer svg").attr('height', '100%');
309 $("#svgContainer").click(
312 // console.log($(event.target).parent().html())
313 // console.log($($(event.target).parent()).attr("data-element-id"))
314 var name = $($(event.target).parent()).attr("data-element-id")
315 lastElementSelected = $($(event.target).parent()).attr(
317 checkIfElementType(name, simple)
320 this.enableDisableMenuOptions = function(pars) {
322 var permittedActionCd = pars.permittedActionCd;
323 // dropdown options - always true
324 document.getElementById('Open CL').classList.remove('ThisLink');
326 // enable model options
327 document.getElementById('Properties CL').classList
329 document.getElementById('Close Model').classList
331 // disable models options
332 document.getElementById('Save CL').classList.add('ThisLink');
333 document.getElementById('Revert Model Changes').classList
336 // enable menu options
337 document.getElementById('Save CL').classList.remove('ThisLink');
338 document.getElementById('Properties CL').classList
340 document.getElementById('Revert Model Changes').classList
342 document.getElementById('Close Model').classList
344 document.getElementById('Validation Test').classList
346 document.getElementById('Refresh Status').classList
349 // enable/disable menu options based on permittedActionCd
351 this.checkPermittedActionCd(permittedActionCd, 'Validation Test',
353 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
354 this.checkPermittedActionCd(permittedActionCd, 'Resubmit',
356 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
357 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
359 .checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
360 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
361 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
362 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy',