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) {
34 //This will open the methods located in the app.js
35 if (undefined == name) {
37 }else if (name === "OperationalPolicy"){
40 $rootScope.selectedBoxName = name;
44 this.getModel = function(modelName) {
46 var svcUrl = "/restservices/clds/v2/loop/" + modelName;
47 $http.get(svcUrl).success(function(data) {
49 setStatus(data.lastComputedState);
51 }).error(function(data) {
52 def.reject("Open Model not successful");
56 this.getSavedModel = function() {
58 var svcUrl = "/restservices/clds/v2/loop/getAllNames";
59 $http.get(svcUrl).success(function(data) {
62 }).error(function(data) {
64 def.reject("Open Model not successful");
68 this.processAction = function(uiAction, modelName) {
70 var svcAction = uiAction.toLowerCase();
71 var svcUrl = "/restservices/clds/v2/loop/" + svcAction + "/" + modelName;
73 $http.put(svcUrl).success(
76 alertService.alertMessage("Action Successful: " + svcAction, 1)
80 alertService.alertMessage("Action Failure: " + svcAction, 2);
81 def.reject(svcAction + " not successful");
86 this.manageAction = function(modelName, typeId, typeName) {
90 url : "/restservices/clds/v1/clds/getDispatcherInfo",
98 $http(config).success(function(data) {
101 }).error(function(data) {
103 def.reject("manage action not successful");
107 this.processActionResponse = function(modelName) {
108 // populate control name (prefix and uuid here)
109 $("#loop_name").text(getLoopName());
110 manageCLImage(modelName);
111 enableDisableMenuOptions();
113 this.refreshStatus = function(modelName) {
114 var def = $q.defer();
115 var svcUrl = "/restservices/clds/v2/loop/getstatus/" + modelName;
116 $http.get(svcUrl).success(function(data) {
118 setStatus(data.lastComputedState);
120 }).error(function(data) {
121 def.reject("Refresh Status not successful");
125 function setStatus(status) {
126 // apply color to status
127 var statusColor = 'white';
128 if (status.trim() === "DESIGN") {
130 } else if (status.trim() === "SUBMITTED") {
132 } else if (status.trim() === "DEPLOYED") {
134 } else if (status.trim() === "RUNNING") {
135 statusColor = 'green'
136 } else if (status.trim() === "STOPPED") {
137 statusColor = 'orange'
138 } else if (status.trim() === "IN_ERROR") {
140 } else if (status.trim() === "WAITING") {
141 statusColor = 'greenyellow'
143 var statusMsg = '<span style="background-color:'
145 + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '
146 + status + ' </span>';
148 if ($("#status_clds").length >= 1)
149 $("#status_clds").remove();
150 $("#activity_modeler")
152 '<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: '
153 + statusMsg + '</span>');
155 var statusTable = '<table id="status_components_table" style="width:100%"><tr><th><span align="left" class="text">Component</span></th><th><span align="center" class="text">State</span></th><th><span align="right" class="text">Description</span></th></tr>';
157 $.each(cl_props['components'], function(componentIndex, componentValue) {
158 statusTable+='<tr><td>'+componentIndex+'</td>';
159 statusTable+='<td>'+componentValue['componentState']['stateName']+'</td>';
160 statusTable+='<td>'+componentValue['componentState']['description']+'</td></tr>';
162 statusTable+= '</table>';
163 if ($("#status_components").length >= 1)
164 $("#status_components").remove();
165 $("#activity_modeler")
167 '<span id="status_components" style="position: absolute; left: 61%;top: 191px; font-size:10px;">'
168 + statusTable + '</span>');
171 function manageCLImage(modelName) {
172 getModelImage(modelName).then(function(pars) {
174 if ($("#svgContainer").length > 0)
175 $("#svgContainer").remove();
176 $("#loop-content").append(
177 "<span id=\"svgContainer\">" + svg + "</span>");
178 $("#svgContainer svg").attr('width', '100%');
179 $("#svgContainer svg").attr('height', '100%');
180 $("#svgContainer").click(
182 var name = $($($($(event.target).parent()).parent()).parent()).attr("data-element-id")
183 checkIfElementType(name)
188 function enableDisableMenuOptions () {
190 enableAllActionMenu();
192 function getModelImage(modelName) {
193 var def = $q.defer();
194 var svcUrl = "/restservices/clds/v2/loop/svgRepresentation/" + modelName;
195 $http.get(svcUrl).success(function(data) {
197 }).error(function(data) {
198 def.reject("Not able to get the model image");