Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / statusDialogController.js
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 "use strict";\r
22 \r
23 var statusDialogController = function(COMPONENT, FIELD, $scope, $http, $timeout, $log, MsoService, StatusService, DataService, PropertyService, UtilityService) {\r
24 \r
25     $scope.isDialogVisible = false;\r
26     $scope.summaryControl = {};\r
27     $scope.detailsControl = {};\r
28     $scope.userProvidedControl = {};\r
29     \r
30     var callbackFunction = undefined;\r
31     var componentId = undefined;\r
32     \r
33     $scope.$on("ComponentStatus", function(event, request) {\r
34 \r
35         $scope.log = "";\r
36         $scope.isSpinnerVisible = true;\r
37         $scope.isErrorVisible = false;\r
38         $scope.isSuccessVisible = false;\r
39         $scope.isSubmitEnabled = false;\r
40         $scope.isDataVisible = false;\r
41         $scope.isDialogVisible = true;\r
42         $scope.popup.isVisible = true;\r
43         $scope.isCancelEnabled = true;\r
44         $scope.success = "";\r
45         $scope.error = "";\r
46 \r
47         $scope.vnfid = undefined;\r
48         $scope.targetProvStatus = undefined;\r
49         \r
50         callbackFunction = request.callbackFunction;\r
51         componentId = request.componentId;\r
52         \r
53         StatusService.initializeComponent(request.componentId);\r
54 \r
55         /*StatusService.setHttpErrorHandler(function(response) {\r
56                 showError("System failure", UtilityService\r
57                                 .getHttpErrorMessage(response));\r
58         });*/\r
59 \r
60         $scope.componentName = StatusService.getComponentDisplayName();\r
61 \r
62         $scope.summaryControl.setList(StatusService.getSummaryList());\r
63 \r
64         $scope.detailsControl.setList(StatusService.getVNFStatusList());\r
65 \r
66         StatusService.getParameters(handleGetParametersResponse);\r
67         \r
68         //UtilityService.setHttpErrorHandler(function(response) {\r
69         //    showError("System failure", UtilityService\r
70         //          .getHttpErrorMessage(response));\r
71         //});\r
72 \r
73 \r
74     });\r
75     \r
76     var handleGetParametersResponse = function(parameters, dontshow) {\r
77                 $scope.summaryControl.setList(parameters.summaryList);\r
78                 $scope.userProvidedControl.setList(parameters.userProvidedList);\r
79 \r
80                 $scope.isSpinnerVisible = false;\r
81                 if (dontshow)\r
82                   $scope.isDataVisible = false;\r
83                 else\r
84                         $scope.isDataVisible = true;\r
85                 $scope.isSubmitEnabled = true;\r
86         };\r
87 \r
88         $scope.userParameterChanged = function(id) {\r
89                 StatusService.updateUserParameterList(id, $scope.userProvidedControl);\r
90         }\r
91 \r
92     /*$scope.submit = function() {\r
93 \r
94         var requiredFields = $scope.userProvidedControl.getRequiredFields();\r
95                 if (requiredFields === "") {\r
96                         $scope.isErrorVisible = false;\r
97                 } else {\r
98                         showError("Missing data", requiredFields);\r
99                         return;\r
100                 }\r
101                 var paramList = $scope.userProvidedControl.getList();\r
102                 var targetprovstatus = "";\r
103                 \r
104                 if ( paramList != null ) {\r
105                         for (var i = 0; i < paramList.length; i++) {\r
106                                 if (paramList[i].id === FIELD.ID.VNF_TARGETPROVSTATUS) {\r
107                                         targetprovstatus = paramList[i].value;\r
108                                         break;\r
109                                 }\r
110                         }\r
111                 }\r
112         \r
113                 $scope.vnfid = DataService.getVnfInstanceId();\r
114                 $scope.targetProvStatus = StatusService.getTargetProvParameterText(targetprovstatus);\r
115                 \r
116                 $scope.setVnfProvStatus($scope.vnfid, $scope.targetProvStatus);\r
117         \r
118            // $scope.isDialogVisible = false;\r
119 \r
120           //  $scope.popup.isVisible = false;\r
121         \r
122     }*/\r
123     \r
124     $scope.init = function() {\r
125                 \r
126         StatusService.updateVnfProvStatus = "";\r
127                 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();\r
128                 PropertyService.setMsoMaxPollingIntervalMsec(msecs);\r
129                 \r
130                 var polls = PropertyService.retrieveMsoMaxPolls();\r
131                 PropertyService.setMsoMaxPolls(polls);\r
132                 \r
133                 $scope.isSpinnerVisible = true;\r
134         \r
135                 \r
136                 $scope.error = "";\r
137                 $scope.success = "";\r
138                 $scope.pollAttempts = 0;\r
139                 $scope.log = "";                                \r
140                 $scope.isSubmitEnabled = false;\r
141                 $scope.isCancelEnabled = false;\r
142                 \r
143         }\r
144 \r
145 \r
146     \r
147     $scope.handleInitialResponse = function(response) {\r
148                 try {\r
149                         $scope.isCancelEnabled = true;\r
150                         \r
151                         if (response.data.status < 200 || response.data.status > 202) {\r
152                                 showError(FIELD.ERROR.AAI_ERROR, "");\r
153                                 return;\r
154                         }\r
155                         else\r
156                         {\r
157                                 DataService.setUpdatedVNFProvStatus($scope.targetProvStatus);\r
158                                 $scope.detailsControl.setList(StatusService.getVNFStatusList());\r
159                                 showSuccess(FIELD.STATUS.SUCCESS_VNF_PROV_STATUS, $scope.targetProvStatus);\r
160                                 \r
161                         }\r
162                         $scope.status = FIELD.STATUS.DONE;\r
163                         $scope.isSpinnerVisible = false;\r
164 //                      DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);\r
165                 } catch (error) {\r
166                         $scope.showContentError(error);\r
167                 }\r
168         }\r
169     \r
170         /* $scope.setVnfProvStatus = function(vnfId, targetProvStatus) {\r
171                 \r
172                 $scope.init();\r
173                  $log\r
174                     .debug("AaiService:setVnfProvStatus: vnf-id: "\r
175                             + vnfId + " Target Prov_Status: " + targetProvStatus);\r
176             var url =  "aai_vnf_update/"\r
177             + vnfId + "/" + targetProvStatus + "?r=" + Math.random();\r
178 \r
179             $http.get(url,\r
180                     {\r
181                         timeout : PropertyService\r
182                                 .getServerResponseTimeoutMsec()\r
183                     }).then(function(response) {\r
184                         \r
185                         $scope.handleInitialResponse(response);\r
186                     })["catch"]\r
187                     (UtilityService.runHttpErrorHandler);\r
188            \r
189         };*/\r
190         \r
191 \r
192         $scope.cancel = function() {\r
193                 $scope.isDialogVisible = false;\r
194                 $scope.popup.isVisible = false;\r
195                 runCallback(false);\r
196         }\r
197 \r
198         var runCallback = function(response) {\r
199                 if (angular.isFunction(callbackFunction)) {\r
200                         callbackFunction({\r
201                                 isSuccessful : response.isSuccessful,\r
202                                 control : $scope.userProvidedControl.getList(),\r
203                                 instanceId : response.instanceId\r
204                         });\r
205                 }\r
206         }\r
207    \r
208         var showSuccess = function(summary, details) {\r
209                 var message = summary;\r
210                 if (UtilityService.hasContents(details)) {\r
211                     message += " (" + details + ")";\r
212                 }\r
213                 $scope.isSpinnerVisible = false;\r
214                 $scope.isSuccessVisible = true;\r
215                 $scope.success = message;\r
216             }\r
217                 \r
218     var showError = function(summary, details) {\r
219         var message = summary;\r
220         if (UtilityService.hasContents(details)) {\r
221             message += " (" + details + ")";\r
222         }\r
223         $scope.isSpinnerVisible = false;\r
224         $scope.isErrorVisible = true;\r
225         $scope.error = message;\r
226     }\r
227 }\r
228 \r
229 appDS2.controller("statusDialogController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",\r
230         "$log", "MsoService", "StatusService", "DataService", "PropertyService", "UtilityService",\r
231         statusDialogController ]);\r