| 462 | }); |
| 463 | |
| 464 | var popupErrorModal = function() { |
| 465 | if ($scope.delay >= 128000) { |
| 466 | $scope.delay = 2000; |
| 467 | } else { |
| 468 | $scope.delay = $scope.delay * 2; |
| 469 | } |
| 470 | |
| 471 | $scope.isErrorModalOpen = true; |
| 472 | |
| 473 | var errorModal = $modal.open({ |
| 474 | controller: function($scope, $modalInstance, scope) { |
| 475 | // Give the modal reference to the root scope so it can access the |
| 476 | // `retry` variable. It needs to be passed by reference, not by |
| 477 | // value, since its value is changed outside the scope of the |
| 478 | // modal. |
| 479 | $scope.rootScope = scope; |
| 480 | }, |
| 481 | resolve: { |
| 482 | scope: function() { return $scope; } |
| 483 | }, |
| 484 | templateUrl: "template/dialog/master-gone.html" |
| 485 | }); |
| 486 | |
| 487 | // Make it such that everytime we hide the error-modal, we stop the |
| 488 | // countdown and restart the polling. |
| 489 | errorModal.result.then(function() { |
| 490 | $scope.isErrorModalOpen = false; |
| 491 | |
| 492 | if ($scope.countdown != null) { |
| 493 | if ($timeout.cancel($scope.countdown)) { |
| 494 | // Restart since they cancelled the countdown. |
| 495 | $scope.delay = 2000; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // Start polling again, but do it asynchronously (and wait at |
| 500 | // least a second because otherwise the error-modal won't get |
| 501 | // properly shown). |
| 502 | $timeout(pollState, 1000); |
| 503 | $timeout(pollMetrics, 1000); |
| 504 | }); |
| 505 | |
| 506 | $scope.retry = $scope.delay; |
| 507 | var countdown = function() { |
| 508 | if ($scope.retry === 0) { |
| 509 | errorModal.close(); |
| 510 | } else { |
| 511 | $scope.retry = $scope.retry - 1000; |
| 512 | $scope.countdown = $timeout(countdown, 1000); |
| 513 | } |
| 514 | }; |
| 515 | countdown(); |
| 516 | }; |
| 517 | |
| 518 | var pollState = function() { |
| 519 | // When the current master is not the leader, the request is redirected to |