|
24 | 24 |
|
25 | 25 | /** @ngInject */ |
26 | 26 | function ProfileCtrl($scope, $http, sharedProperties, sharedData, toastr, $cookies, $uibModal) { |
27 | | - |
28 | 27 | var urlPath = sharedProperties.getUrlPath(); |
29 | 28 |
|
30 | 29 | $scope.workflows = sharedData.getWorkflows(); |
|
65 | 64 | document.location.href="auth.html"; |
66 | 65 | } |
67 | 66 |
|
| 67 | + $scope.removeAccount = function() { |
| 68 | + |
| 69 | + var password = $("#currentPassword").val(); |
| 70 | + |
| 71 | + if (!password) { |
| 72 | + $scope.errorMessage = "Please enter your password." |
| 73 | + $uibModal.open({ |
| 74 | + animation: true, |
| 75 | + scope: $scope, |
| 76 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 77 | + size: 'md', |
| 78 | + }); |
| 79 | + return; |
| 80 | + } else { |
| 81 | + $uibModal.open({ |
| 82 | + animation: true, |
| 83 | + scope: $scope, |
| 84 | + templateUrl: 'app/pages/profile/modals/deleteAccountModal.html', |
| 85 | + size: 'md', |
| 86 | + }); |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + $scope.undeployAllWorkflows = function() { |
| 91 | + var password = $("#currentPassword").val(); |
| 92 | + $("#currentPassword").val(""); |
| 93 | + checkDeployedWorkflows(password); |
| 94 | + }; |
| 95 | + |
68 | 96 | $scope.clearPassword = function() { |
69 | 97 | $("#currentPassword").val(""); |
70 | 98 | } |
|
120 | 148 | } |
121 | 149 |
|
122 | 150 | $http(req).then(function successCallback(response) { |
123 | | - |
124 | 151 | if (response.data.status=="success") { |
125 | 152 | console.log("Message:" + response.data.data.message); |
126 | 153 | $cookies.put('name', newName); |
|
154 | 181 | templateUrl: 'app/pages/workflows/modals/errorModal.html', |
155 | 182 | size: 'md', |
156 | 183 | }); |
| 184 | + }); |
| 185 | + } |
| 186 | + |
| 187 | + function deleteAccount(password) { |
| 188 | + |
| 189 | + if ($scope.workflowUndeploymentModal) { |
| 190 | + $scope.workflowUndeploymentModal.dismiss(); |
| 191 | + } |
| 192 | + |
| 193 | + var req = { |
| 194 | + method: 'POST', |
| 195 | + url: urlPath, |
| 196 | + headers: { |
| 197 | + 'Content-Type': 'application/json' |
| 198 | + }, |
| 199 | + |
| 200 | + data: JSON.stringify({ "action" : "deleteAccount", "data" : { "user" : { "password": password, "token" : token } } }) |
| 201 | + |
| 202 | + } |
| 203 | + |
| 204 | + $http(req).then(function successCallback(response) { |
| 205 | + |
| 206 | + if (response.data.status=="success") { |
| 207 | + console.log("Message:" + response.data.data.message); |
| 208 | + $scope.logOut(); |
| 209 | + |
| 210 | + } else { |
| 211 | + console.log("Failure status returned by deleteAccount request"); |
| 212 | + console.log("Message:" + response.data.data.message); |
| 213 | + $scope.errorMessage = response.data.data.message; |
| 214 | + $uibModal.open({ |
| 215 | + animation: true, |
| 216 | + scope: $scope, |
| 217 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 218 | + size: 'md', |
| 219 | + }); |
| 220 | + |
| 221 | + } |
| 222 | + }, function errorCallback(response) { |
| 223 | + console.log("Error occurred during deleteAccount request"); |
| 224 | + console.log("Response:" + response); |
| 225 | + if (response.statusText) { |
| 226 | + $scope.errorMessage = response.statusText; |
| 227 | + } else { |
| 228 | + $scope.errorMessage = response; |
| 229 | + } |
| 230 | + $uibModal.open({ |
| 231 | + animation: true, |
| 232 | + scope: $scope, |
| 233 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 234 | + size: 'md', |
| 235 | + }); |
157 | 236 |
|
158 | 237 | }); |
| 238 | + |
| 239 | + } |
| 240 | + |
| 241 | + function checkDeployedWorkflows(password) { |
| 242 | + |
| 243 | + var req = { |
| 244 | + method: 'POST', |
| 245 | + url: urlPath, |
| 246 | + headers: { |
| 247 | + 'Content-Type': 'application/json' |
| 248 | + }, |
| 249 | + data: JSON.stringify({ "action" : "getWorkflows", "data" : { "user" : { "token" : token } } }) |
| 250 | + } |
| 251 | + |
| 252 | + $http(req).then(function successCallback(response) { |
| 253 | + |
| 254 | + if (response.data.status=="success") { |
| 255 | + |
| 256 | + $scope.workflows = response.data.data.workflows; |
| 257 | + sharedData.setWorkflows(response.data.data.workflows); |
| 258 | + var deployedWorkflows = false; |
| 259 | + for (var i=0;i<$scope.workflows.length;++i) { |
| 260 | + if ($scope.workflows[i].status=="deployed") { |
| 261 | + undeployWorkflow(i, password); |
| 262 | + deployedWorkflows = true; |
| 263 | + break; |
| 264 | + } |
| 265 | + } |
| 266 | + if (!deployedWorkflows) { |
| 267 | + deleteAccount(password); |
| 268 | + } |
| 269 | + |
| 270 | + } else { |
| 271 | + console.log("Failure status returned by getWorkflows"); |
| 272 | + console.log("Message:" + response.data.data.message); |
| 273 | + $scope.errorMessage = response.data.data.message; |
| 274 | + $uibModal.open({ |
| 275 | + animation: true, |
| 276 | + scope: $scope, |
| 277 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 278 | + size: 'md', |
| 279 | + }); |
| 280 | + return true; |
| 281 | + } |
| 282 | + }, function errorCallback(response) { |
| 283 | + console.log("Error occurred during getWorkflows"); |
| 284 | + console.log("Response:" + response); |
| 285 | + if (response.statusText) { |
| 286 | + $scope.errorMessage = response.statusText; |
| 287 | + } else { |
| 288 | + $scope.errorMessage = response; |
| 289 | + } |
| 290 | + $uibModal.open({ |
| 291 | + animation: true, |
| 292 | + scope: $scope, |
| 293 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 294 | + size: 'md', |
| 295 | + }); |
| 296 | + return true; |
| 297 | + }); |
| 298 | + } |
| 299 | + |
| 300 | + function undeployWorkflow(index, password) { |
| 301 | + var req; |
| 302 | + |
| 303 | + console.log('undeploying workflow ' + $scope.workflows[index].id); |
| 304 | + $scope.currentWorkflow = $scope.workflows[index].name; |
| 305 | + console.log($scope.currentWorkflow); |
| 306 | + if (!$scope.workflowUndeploymentModal) { |
| 307 | + $scope.workflowUndeploymentModal = $uibModal.open({ |
| 308 | + animation: true, |
| 309 | + scope: $scope, |
| 310 | + backdrop : 'static', |
| 311 | + keyboard : false, |
| 312 | + templateUrl: 'app/pages/profile/modals/workflowUndeploymentModal.html', |
| 313 | + size: 'sm', |
| 314 | + }); |
| 315 | + } |
| 316 | + $scope.workflows[index].status='undeploying'; |
| 317 | + req = { |
| 318 | + method: 'POST', |
| 319 | + url: urlPath, |
| 320 | + headers: { |
| 321 | + 'Content-Type': 'application/json' |
| 322 | + }, |
| 323 | + data: JSON.stringify({ "action" : "undeployWorkflow", "data" : { "user" : { "token" : token } , "workflow" : { "id" : $scope.workflows[index].id } } }) |
| 324 | + } |
| 325 | + |
| 326 | + $http(req).then(function successCallback(response) { |
| 327 | + |
| 328 | + if (response.data.status=="success") { |
| 329 | + setTimeout(function() {$scope.workflows[index].status='undeployed'; checkDeployedWorkflows(password); }, 2000); |
| 330 | + |
| 331 | + } else { |
| 332 | + console.log("Failure status returned by undeployWorkflow"); |
| 333 | + console.log("Message:" + response.data.data.message); |
| 334 | + $scope.workflowUndeploymentModal.dismiss(); |
| 335 | + $scope.errorMessage = response.data.data.message; |
| 336 | + $uibModal.open({ |
| 337 | + animation: true, |
| 338 | + scope: $scope, |
| 339 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 340 | + size: 'md', |
| 341 | + }); |
| 342 | + } |
| 343 | + }, function errorCallback(response) { |
| 344 | + console.log("Error occurred during undeployWorkflow"); |
| 345 | + console.log("Response:" + response); |
| 346 | + $scope.workflowUndeploymentModal.dismiss(); |
| 347 | + if (response.statusText) { |
| 348 | + $scope.errorMessage = response.statusText; |
| 349 | + } else { |
| 350 | + $scope.errorMessage = response; |
| 351 | + } |
| 352 | + |
| 353 | + $uibModal.open({ |
| 354 | + animation: true, |
| 355 | + scope: $scope, |
| 356 | + templateUrl: 'app/pages/workflows/modals/errorModal.html', |
| 357 | + size: 'md', |
| 358 | + }); |
| 359 | + |
| 360 | + }); |
| 361 | + |
159 | 362 | } |
160 | 363 |
|
161 | 364 | function changePassword(password, newPassword) { |
|
166 | 369 | headers: { |
167 | 370 | 'Content-Type': 'application/json' |
168 | 371 | }, |
| 372 | + |
169 | 373 | data: JSON.stringify({ "action" : "changePassword", "data" : { "user" : { "email" : $scope.email, "password" : password, "new_password" : newPassword } } }) |
| 374 | + |
170 | 375 | } |
171 | 376 |
|
172 | 377 | $http(req).then(function successCallback(response) { |
|
184 | 389 | templateUrl: 'app/pages/workflows/modals/errorModal.html', |
185 | 390 | size: 'md', |
186 | 391 | }); |
187 | | - |
188 | 392 | } |
189 | 393 | }, function errorCallback(response) { |
190 | 394 | console.log("Error occurred during changePassword request"); |
|
200 | 404 | templateUrl: 'app/pages/workflows/modals/errorModal.html', |
201 | 405 | size: 'md', |
202 | 406 | }); |
203 | | - |
204 | 407 | }); |
205 | 408 | } |
206 | 409 | } |
|
0 commit comments