Add Loop name
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / CldsModelService.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * 
22  */
23 app
24 .service(
25 'cldsModelService',
26 [
27         'alertService',
28         '$http',
29         '$q',
30         '$rootScope',
31         function(alertService, $http, $q, $rootScope) {
32
33                 function checkIfElementType(name) {
34                 //This will open the methods located in the app.js
35                         if (undefined == name) {
36                                 return;
37                         }else if (name.toLowerCase().indexOf("policy") >= 0){
38                                 PolicyWindow();
39                         } else {
40                                 $rootScope.selectedBoxName = name;
41                                 ToscaModelWindow();
42                         }
43                 }
44                 this.toggleDeploy = function(uiAction, modelName) {
45                         var svcAction = uiAction.toLowerCase();
46                         var deployUrl = "/restservices/clds/v2/loop/" + svcAction + "Loop/" + modelName;
47                         var def = $q.defer();
48                         var sets = [];
49                         $http.put(deployUrl).success(
50                                 function(data) {
51                                         def.resolve(data);
52                                         alertService.alertMessage("Action Successful: " + svcAction, 1)
53                                         // update deploymentID, lastUpdatedStatus
54                                         setLastUpdatedStatus(data.lastUpdatedStatus);
55                                         setDeploymentStatusURL(data.dcaeDeploymentStatusUrl);
56                                         setDeploymentID(data.dcaeDeploymentId);
57                                         setStatus();
58                                         enableDisableMenuOptions();
59                         }).error(
60                                 function(data) {
61                                         def.resolve(data);
62                                         alertService.alertMessage("Action Failure: " + svcAction, 2);
63                                         def.reject(svcAction + " not successful");
64                         });
65                         return def.promise;
66                 }
67                 this.getModel = function(modelName) {
68                     var def = $q.defer();
69                     var sets = [];
70                     var svcUrl = "/restservices/clds/v2/loop/" + modelName;
71                     $http.get(svcUrl).success(function(data) {
72                         cl_props = data;
73                         $("#loop_name").text(getLoopName());
74                             def.resolve(data);
75                     }).error(function(data) {
76                             def.reject("Open Model not successful");
77                     });
78                     return def.promise;
79             };
80             this.getSavedModel = function() {
81                     var def = $q.defer();
82                     var sets = [];
83                     var svcUrl = "/restservices/clds/v2/loop/getAllNames";
84                     $http.get(svcUrl).success(function(data) {
85
86                             def.resolve(data);
87                     }).error(function(data) {
88
89                             def.reject("Open Model not successful");
90                     });
91                     return def.promise;
92             };
93             this.processAction = function(uiAction, modelName) {
94                     var def = $q.defer();
95                     var sets = [];
96                     var svcAction = uiAction.toLowerCase();
97                     var svcUrl = "/restservices/clds/v2/loop/" + svcAction + "/" + modelName;
98
99                         $http.put(svcUrl).success(
100                                 function(data) {
101                                         def.resolve(data);
102                                         alertService.alertMessage("Action Successful: " + svcAction, 1)
103                                         // update deploymentID, lastUpdatedStatus
104                                         setLastUpdatedStatus(data.lastUpdatedStatus);
105                                         setDeploymentStatusURL(data.dcaeDeploymentStatusUrl);
106                                         setDeploymentID(data.dcaeDeploymentId);
107                                         setStatus();
108                                         enableDisableMenuOptions();
109                         }).error(
110                                 function(data) {
111                                         def.resolve(data);
112                                         alertService.alertMessage("Action Failure: " + svcAction, 2);
113                                         def.reject(svcAction + " not successful");
114                         });
115                     
116                     return def.promise;
117             };
118             this.manageAction = function(modelName, typeId, typeName) {
119
120                     var def = $q.defer();
121                     var sets = [];
122                     var config = {
123                         url : "/restservices/clds/v1/clds/getDispatcherInfo",
124                         method : "GET",
125                         params : {
126                             model : modelName,
127                             typeId : typeId,
128                             typeName : typeName
129                         }
130                     };
131                     $http(config).success(function(data) {
132
133                             def.resolve(data);
134                     }).error(function(data) {
135
136                             def.reject("manage action not successful");
137                     });
138                     return def.promise;
139             };
140             this.processActionResponse = function(modelName) {
141                 // populate control name (prefix and uuid here)
142                     var headerText = "Closed Loop Modeler - " + modelName;
143                     setStatus();
144                     manageCLImage(modelName);
145                     enableDisableMenuOptions();
146             };
147             this.processRefresh = function() {
148                     setStatus();
149                     enableDisableMenuOptions();
150             }
151             function setStatus() {
152                     var status = getLastUpdatedStatus();
153                     // apply color to status
154                     var statusColor = 'white';
155                     if (status.trim() === "DESIGN") {
156                             statusColor = 'gray'
157                     } else if (status.trim() === "DISTRIBUTED") {
158                             statusColor = 'blue'
159                     } else if (status.trim() === "ACTIVE") {
160                             statusColor = 'green'
161                     } else if (status.trim() === "STOPPED") {
162                             statusColor = 'red'
163                     } else if (status.trim() === "DELETING") {
164                             statusColor = 'pink'
165                     } else if (status.trim() === "ERROR") {
166                             statusColor = 'orange'
167                     } else if (status.trim() === "UNKNOWN") {
168                             statusColor = 'blue'
169                     } else {
170                             statusColor = null;
171                     }
172                     var statusMsg = '<span style="background-color:'
173                     + statusColor
174                     + ';-moz-border-radius: 50px;  -webkit-border-radius: 50px;  border-radius: 50px;">&nbsp;&nbsp;&nbsp;'
175                     + status + '&nbsp;&nbsp;&nbsp;</span>';
176                     // display status
177                     if ($("#status_clds").length >= 1)
178                             $("#status_clds").remove();
179                     $("#activity_modeler")
180                     .append(
181                     '<span id="status_clds" style="position: absolute;  left: 61%;top: 151px; font-size:20px;">Status: '
182                     + statusMsg + '</span>');
183             }
184             function manageCLImage(modelName) {
185                 getModelImage(modelName).then(function(pars) {
186                         //var svg='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/2000/svg"> <defs> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="11" refY="10" id="markerSjdype4kmnw"> <path d="M 1 5 L 11 10 L 1 15 Z" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="20" markerHeight="20" orient="auto" refX="6" refY="6" id="markerSjdype4kmny"> <circle cx="6" cy="6" r="3.5" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="20" markerHeight="20" orient="auto" refX="8.5" refY="5" id="markerSjdype4kmo0"> <path d="m 1 5 l 0 -3 l 7 3 l -7 3 z" style="stroke-width: 1; stroke-linecap: butt; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="11" refY="10" id="markerSjdype4kmo2"> <path d="M 1 5 L 11 10 L 1 15" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="-1" refY="10" id="markerSjdype4kmo4"> <path d="M 0 10 L 8 6 L 16 10 L 8 14 Z" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="-5" refY="10" id="markerSjdype4kmo6"> <path d="M 1 4 L 5 16" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#000000" stroke="#000000" /> </marker> </defs><g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="start-circle" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <circle fill="none" r="17" cx="34" cy="41"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="Arrow_d0b22360-770d-4b05-b81c-cf148b121341" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <line y2="41" fill="none" x1="51" x2="170" y1="41"/> <polygon fill="none" points=" 166 38 166 44 172 41"/>             <polygon points=" 166 38 166 44 172 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="VES" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <rect fill="none" x="174" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="174" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="223" xml:space="preserve" y="42" stroke="none">VES</text> <line y2="83" fill="none" stroke-width="2" x1="194" x2="194" y1="1"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="Arrow_d4351927-d77a-4e04-82d1-cd8f2b008137" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="297" x2="416" y1="41"/> <polygon fill="none" points=" 412 38 412 44 418 41"/> <polygon points=" 412 38 412 44 418 41" stroke="none"/> </g> </g> </g>    <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="TCA" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <rect fill="none" x="420" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="420" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="470" xml:space="preserve" y="42" stroke="none">TCA</text> <line y2="62" fill="none" stroke-width="2" x1="420" x2="543" y1="62"/> </g> </g> </g>   <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="Arrow_5ae2966f-f971-4c3b-8237-efa551beb531" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="543" x2="662" y1="41"/> <polygon fill="none" points=" 658 38 658 44 664 41"/> <polygon points=" 658 38 658 44 664 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="Policy" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <rect fill="none" x="666" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="666" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="710" xml:space="preserve" y="42" stroke="none">Policy</text> <line y2="1" fill="none" stroke-width="2" x1="666" x2="727" y1="42"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="Arrow_ed5ccaed-6d8c-44e9-8245-85f66523cb44" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="789" x2="908" y1="41"/> <polygon fill="none" points=" 904 38 904 44 910 41"/> <polygon points=" 904 38 904 44 910 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="&apos;Dialog&apos;" font-style="normal" data-element-id="circle_stop" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="4" shape-rendering="geometricPrecision" font-family="sans-serif"> <circle fill="none" r="17" cx="929" cy="41"/> </g> </g> </g> </svg>';
187                         var svg = pars;
188                             if ($("#svgContainer").length > 0)
189                                     $("#svgContainer").remove();
190                             $("#js-canvas").append(
191                             "<span id=\"svgContainer\">" + svg + "</span>");
192                             $("#svgContainer svg").attr('width', '100%');
193                             $("#svgContainer svg").attr('height', '100%');
194                             $("#svgContainer").click(
195                             function(event) {
196                                     var name = $($($($(event.target).parent()).parent()).parent()).attr("data-element-id")
197                                     checkIfElementType(name)
198                             });
199                         }, function(data) {
200                         });
201             }
202             enableDisableMenuOptions = function() {
203                     enableDefaultMenu();
204                     //var status = getStatus();
205                 //enableActionMenu(status);
206                 enableAllActionMenu();
207             }
208             getModelImage = function(modelName) {
209                     var def = $q.defer();
210                     var sets = [];
211                     var svcUrl = "/restservices/clds/v2/loop/svgRepresentation/" + modelName;
212                     $http.get(svcUrl).success(function(data) {
213                             def.resolve(data);
214                     }).error(function(data) {
215                             def.reject("Not able to get the model image");
216                     });
217                     return def.promise;
218             };
219     } ]);