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) {
35 //This will open the methods located in the app.js
36 if (undefined == name) {
38 }else if (name.toLowerCase().indexOf("policy") >= 0){
41 $rootScope.selectedBoxName = name.toLowerCase();
45 function handleQueryToBackend(def, svcAction, svcUrl, svcPayload) {
47 $http.put(svcUrl, svcPayload).success(
51 if (typeof data.statusCodeValue === 'undefined'
52 || data.statusCodeValue === 200) {
53 alertService.alertMessage(
54 "Action Successful: " + svcAction, 1)
56 if (typeof data.body !== 'undefined') {
57 alertService.alertMessage("Action Failure: "
58 + svcAction + ", " + data.body.errorMessageForUi, 2);
60 alertService.alertMessage("Action Failure: "
63 def.reject(svcAction + " not successful");
69 if (typeof data.body !== 'undefined') {
70 alertService.alertMessage("Action Failure: " + svcAction
71 + ", " + data.body.errorMessageForUi, 2);
74 .alertMessage("Action Failure: " + svcAction, 2);
76 def.reject(svcAction + " not successful");
79 this.toggleDeploy = function(uiAction, modelName, controlNamePrefixIn,
80 bpmnTextIn, propTextIn, svgXmlIn,
81 templateName, typeID, controlNameUuid,
82 modelEventService, deploymentId) {
86 var action = uiAction.toLowerCase();
87 var deployUrl = "/restservices/clds/v1/clds/" + action + "/"
91 controlNamePrefix : controlNamePrefixIn,
92 bpmnText : bpmnTextIn,
93 propText : propTextIn,
95 templateName : templateName,
97 controlNameUuid : controlNameUuid,
98 event : modelEventService,
99 deploymentId : deploymentId
101 handleQueryToBackend(def, action, deployUrl, requestData);
104 this.getModel = function(modelName) {
106 var def = $q.defer();
108 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
109 $http.get(svcUrl).success(function(data) {
112 }).error(function(data) {
114 def.reject("Open Model not successful");
118 this.getSavedModel = function() {
120 var def = $q.defer();
122 var svcUrl = "/restservices/clds/v1/clds/model-names";
123 $http.get(svcUrl).success(function(data) {
126 }).error(function(data) {
128 def.reject("Open Model not successful");
132 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn,
135 var def = $q.defer();
137 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
140 controlNamePrefix : controlNamePrefixIn,
141 bpmnText : bpmnTextIn,
142 propText : propTextIn
144 $http.put(svcUrl, svcRequest).success(function(data) {
147 }).error(function(data) {
149 def.reject("Save Model not successful");
153 this.processAction = function(uiAction, modelName, controlNamePrefixIn,
154 bpmnTextIn, propTextIn, svgXmlIn,
155 templateName, typeID, deploymentId) {
157 var def = $q.defer();
159 // console.log(svgXmlIn);
160 var svcUrl = "/restservices/clds/v1/clds/";
161 var svcAction = uiAction.toLowerCase();
162 if (svcAction == "save" || svcAction == "refresh") {
163 svcUrl = svcUrl + "model/" + modelName;
164 } else if (svcAction == "test") {
165 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
167 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
171 controlNamePrefix : controlNamePrefixIn,
172 bpmnText : bpmnTextIn,
173 propText : propTextIn,
174 imageText : svgXmlIn,
175 templateName : templateName,
177 deploymentId : deploymentId
179 handleQueryToBackend(def, svcAction, svcUrl, svcRequest);
182 this.manageAction = function(modelName, typeId, typeName) {
184 var def = $q.defer();
187 url : "/restservices/clds/v1/clds/getDispatcherInfo",
195 $http(config).success(function(data) {
198 }).error(function(data) {
200 def.reject("manage action not successful");
204 this.checkPermittedActionCd = function(permittedActionCd, menuText,
207 if (permittedActionCd.indexOf(actionCd) > -1) {
208 document.getElementById(menuText).classList.remove('ThisLink');
210 document.getElementById(menuText).classList.add('ThisLink');
213 this.processActionResponse = function(modelName, pars) {
215 // populate control name (prefix and uuid here)
216 var controlNamePrefix = pars.controlNamePrefix;
217 var controlNameUuid = pars.controlNameUuid;
218 deploymentId = pars.deploymentId;
219 var modelEventService = pars.modelEventService;
220 typeID = pars.typeId;
221 var headerText = "Closed Loop Modeler - " + modelName;
222 if (controlNameUuid != null) {
223 var actionCd = pars.event.actionCd;
224 var actionStateCd = pars.event.actionStateCd;
225 headerText = headerText + " [" + controlNamePrefix
226 + controlNameUuid + "]";
228 document.getElementById("modeler_name").textContent = headerText;
229 document.getElementById("templa_name").textContent = ("Template Used - " + selected_template);
231 disableBPMNAddSVG(pars);
232 this.enableDisableMenuOptions(pars);
234 this.processRefresh = function(pars) {
237 if (typeof pars.body !== 'undefined') {
240 typeID = newPars.typeId;
241 deploymentId = newPars.deploymentId;
243 this.enableDisableMenuOptions(newPars);
244 elementMap = JSON.parse(newPars.propText);
246 function setStatus(pars) {
248 var status = pars.status;
249 // apply color to status
250 var statusColor = 'white';
251 if (status.trim() === "DESIGN") {
253 } else if (status.trim() === "DISTRIBUTED") {
255 } else if (status.trim() === "ACTIVE") {
256 statusColor = 'green'
257 } else if (status.trim() === "STOPPED") {
259 } else if (status.trim() === "DELETING") {
261 } else if (status.trim() === "ERROR") {
262 statusColor = 'orange'
263 } else if (status.trim() === "UNKNOWN") {
268 var statusMsg = '<span style="background-color:'
270 + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '
271 + status + ' </span>';
273 if ($("#status_clds").length >= 1)
274 $("#status_clds").remove();
275 $("#activity_modeler")
277 '<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: '
278 + statusMsg + '</span>');
280 function disableBPMNAddSVG(pars) {
282 var svg = pars.imageText.substring(pars.imageText.indexOf("<svg"))
283 if ($("#svgContainer").length > 0)
284 $("#svgContainer").remove();
285 $("#js-canvas").append(
286 "<span id=\"svgContainer\">" + svg + "</span>");
287 /* added code for height width viewBox */
288 $("#svgContainer svg").removeAttr("height");
289 $("#svgContainer svg").removeAttr('viewBox');
290 $("#svgContainer svg").removeAttr('width');
291 $("#svgContainer svg").attr('width', '100%');
292 $("#svgContainer svg").attr('height', '100%');
293 $("#svgContainer").click(
296 // console.log($(event.target).parent().html())
297 // console.log($($(event.target).parent()).attr("data-element-id"))
298 var name = $($(event.target).parent()).attr("data-element-id")
299 lastElementSelected = $($(event.target).parent()).attr(
301 checkIfElementType(name)
304 this.enableDisableMenuOptions = function(pars) {
306 var permittedActionCd = pars.permittedActionCd;
307 // dropdown options - always true
308 document.getElementById('Open CL').classList.remove('ThisLink');
310 // enable model options
311 document.getElementById('Properties CL').classList
313 document.getElementById('Close Model').classList
315 // disable models options
316 document.getElementById('Save CL').classList.add('ThisLink');
317 document.getElementById('Revert Model Changes').classList
320 // enable menu options
321 document.getElementById('Save CL').classList.remove('ThisLink');
322 document.getElementById('Properties CL').classList
324 document.getElementById('Revert Model Changes').classList
326 document.getElementById('Close Model').classList
328 document.getElementById('Validation Test').classList
330 document.getElementById('Refresh Status').classList
333 // enable/disable menu options based on permittedActionCd
335 this.checkPermittedActionCd(permittedActionCd, 'Validation Test',
337 this.checkPermittedActionCd(permittedActionCd, 'Submit', 'SUBMIT');
338 this.checkPermittedActionCd(permittedActionCd, 'Resubmit',
340 this.checkPermittedActionCd(permittedActionCd, 'Update', 'UPDATE');
341 this.checkPermittedActionCd(permittedActionCd, 'Stop', 'STOP');
343 .checkPermittedActionCd(permittedActionCd, 'Restart', 'RESTART');
344 this.checkPermittedActionCd(permittedActionCd, 'Delete', 'DELETE');
345 this.checkPermittedActionCd(permittedActionCd, 'Deploy', 'DEPLOY');
346 this.checkPermittedActionCd(permittedActionCd, 'UnDeploy',