status.js 2.76 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
'use strict';
angular.module('status', ['ngStorage'])
    .controller('statusController', ['$scope', '$interval', '$sce', '$timeout', '$localStorage', '$rootScope', '$http', function ($scope, $interval, $sce, $timeout, $localStorage, $rootScope, $http) {
        $scope.isConsole = true;
        $scope.isShowCleanUpBox = false;
        $scope.error = false;
        $scope.rollbackStarted = false;
        $scope.nextButton = false;

        $scope.toggleConsole = function () {
            $scope.isConsole = $scope.isConsole === false;
        };
        $scope.rollback = function () {
            $http.post('index.php/rollback');
            $scope.error = true;
            $scope.rollbackStarted = true;
        };
        $scope.goToSuccessPage = function () {
            window.location.href = '../setup/index.php#/updater-success';
        };

        $interval(
            function () {
                $http.post('index.php/status')
                    .success(function (result) {
                        if (result['complete']) {
                            $localStorage.rollbackStarted = $scope.rollbackStarted;
                            if ($scope.rollbackStarted === true) {
                                $scope.nextButton = true;
                            } else {
                                $scope.goToSuccessPage();
                            }
                        }
                        if (result.statusMessage) {
                            $('#console').html(result.statusMessage);
                        }
                        var statusText = "";
                        if (result.isUpdateInProgress) {
                            statusText = "Update application is running";
                        } else if (result.pending) {
                            statusText = "Update pending";
                        } else {
                            statusText = "Update application is not running";
                        }
                        $('#status').html(statusText);
                        if (result['error'] || $scope.error) {
                            $scope.error = true;
                        }
                    })
                    .error(function (result) {
                        $scope.error = true;
                        $scope.rollbackStarted = false;
                    });
            },
            3000
        );
        $interval(
            function () {
                $http.post('../setup/index.php/session/prolong')
                    .success(function (result) {
                    })
                    .error(function (result) {
                    });
            },
            120000
        );
    }]);