[VID-6] Initial rebase push
[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                 PropertyService.setServerResponseTimeoutMsec(10000)\r
134 \r
135                 $scope.isSpinnerVisible = true;\r
136         \r
137                 \r
138                 $scope.error = "";\r
139                 $scope.success = "";\r
140                 $scope.pollAttempts = 0;\r
141                 $scope.log = "";                                \r
142                 $scope.isSubmitEnabled = false;\r
143                 $scope.isCancelEnabled = false;\r
144                 \r
145         }\r
146 \r
147 \r
148     \r
149     $scope.handleInitialResponse = function(response) {\r
150                 try {\r
151                         $scope.isCancelEnabled = true;\r
152                         \r
153                         if (response.data.status < 200 || response.data.status > 202) {\r
154                                 showError(FIELD.ERROR.AAI_ERROR, "");\r
155                                 return;\r
156                         }\r
157                         else\r
158                         {\r
159                                 DataService.setUpdatedVNFProvStatus($scope.targetProvStatus);\r
160                                 $scope.detailsControl.setList(StatusService.getVNFStatusList());\r
161                                 showSuccess(FIELD.STATUS.SUCCESS_VNF_PROV_STATUS, $scope.targetProvStatus);\r
162                                 \r
163                         }\r
164                         $scope.status = FIELD.STATUS.DONE;\r
165                         $scope.isSpinnerVisible = false;\r
166 //                      DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);\r
167                 } catch (error) {\r
168                         $scope.showContentError(error);\r
169                 }\r
170         }\r
171     \r
172         /* $scope.setVnfProvStatus = function(vnfId, targetProvStatus) {\r
173                 \r
174                 $scope.init();\r
175                  $log\r
176                     .debug("AaiService:setVnfProvStatus: vnf-id: "\r
177                             + vnfId + " Target Prov_Status: " + targetProvStatus);\r
178             var url =  "aai_vnf_update/"\r
179             + vnfId + "/" + targetProvStatus + "?r=" + Math.random();\r
180 \r
181             $http.get(url,\r
182                     {\r
183                         timeout : PropertyService\r
184                                 .getServerResponseTimeoutMsec()\r
185                     }).then(function(response) {\r
186                         \r
187                         $scope.handleInitialResponse(response);\r
188                     })["catch"]\r
189                     (UtilityService.runHttpErrorHandler);\r
190            \r
191         };*/\r
192         \r
193 \r
194         $scope.cancel = function() {\r
195                 $scope.isDialogVisible = false;\r
196                 $scope.popup.isVisible = false;\r
197                 runCallback(false);\r
198         }\r
199 \r
200         var runCallback = function(response) {\r
201                 if (angular.isFunction(callbackFunction)) {\r
202                         callbackFunction({\r
203                                 isSuccessful : response.isSuccessful,\r
204                                 control : $scope.userProvidedControl.getList(),\r
205                                 instanceId : response.instanceId\r
206                         });\r
207                 }\r
208         }\r
209    \r
210         var showSuccess = function(summary, details) {\r
211                 var message = summary;\r
212                 if (UtilityService.hasContents(details)) {\r
213                     message += " (" + details + ")";\r
214                 }\r
215                 $scope.isSpinnerVisible = false;\r
216                 $scope.isSuccessVisible = true;\r
217                 $scope.success = message;\r
218             }\r
219                 \r
220     var showError = function(summary, details) {\r
221         var message = summary;\r
222         if (UtilityService.hasContents(details)) {\r
223             message += " (" + details + ")";\r
224         }\r
225         $scope.isSpinnerVisible = false;\r
226         $scope.isErrorVisible = true;\r
227         $scope.error = message;\r
228     }\r
229 }\r
230 \r
231 appDS2.controller("statusDialogController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",\r
232         "$log", "MsoService", "StatusService", "DataService", "PropertyService", "UtilityService",\r
233         statusDialogController ]);\r