<commit_before>/**
 * (c) 2016 <NAME>
 * Licensed under the MIT license.
 */
'use strict';

/**
 * @ngdoc function
 * @name dashboard.controller:OverviewCtrl
 * @description
 * # OverviewCtrl
 * Controller of the dashboard
 */
angular.module('dashboard')
    .controller('overviewCtrl', ['$scope', '$log', 'ENV', 'SigningOpenApi', '$state', '$rootScope', 'CONST', '$stateParams', 'MTGD', 'StorageSrv', '$http', 'DialogUtils', 'AhjoMeetingSrv', function ($scope, $log, ENV, SigningOpenApi, $state, $rootScope, CONST, $stateParams, MTGD, StorageSrv, $http, DialogUtils, AhjoMeetingSrv) {
        $log.debug("overviewCtrl: CONTROLLER, mode: ", $stateParams.state);
        var self = this;
        self.loading = 0;
        self.signReqsHeader = 'Avoimet allekirjoituspyynnöt';
        self.signErr = null;
        self.blockMode = CONST.BLOCKMODE.DEFAULT;
        self.vbl = MTGD.VISIBLE;
        self.bms = CONST.BLOCKMODE;

        var visibleMtgs = StorageSrv.getKey(CONST.KEY.VISIBLE_MTGS);
        switch (visibleMtgs) {
            case MTGD.VISIBLE.OPEN:
                self.vblMtgs = MTGD.VISIBLE.OPEN;
                break;
            case MTGD.VISIBLE.CLOSED:
                self.vblMtgs = MTGD.VISIBLE.CLOSED;
                break;
            default:
                self.vblMtgs = MTGD.VISIBLE.OPEN;
                break;
        }

        var signingRes = StorageSrv.getKey(CONST.KEY.SIGNING_RES);
        self.closedSignReqs = signingRes ? signingRes : false;

        $rootScope.menu = CONST.MENU.CLOSED;
        var mode = $stateParams.state;
        var storedMode = localStorage.overviewState;

        if (mode === CONST.HOMEMODE.ALL) {
            if (storedMode === '1') {
                mode = CONST.HOMEMODE.MEETINGS;
            }
            else if (storedMode === '2') {
                mode = CONST.HOMEMODE.ESIGN;
            }
        }

        switch (mode) {
            case CONST.HOMEMODE.MEETINGS:
                self.hasMeetings = true;
                break;
            case CONST.HOMEMODE.ESIGN:
                self.hasEsign = true;
                break;
            default:
                self.hasMeetings = true;
                self.hasEsign = true;
                break;
        }

        localStorage.overviewState = mode;

        function goToMeeting(meetingItem, meetingRole) {
            $log.debug("overviewCtrl.goToMeeting");
            StorageSrv.setKey(CONST.KEY.MEETING_ITEM, meetingItem);
            StorageSrv.setKey(CONST.KEY.MEETING_ROLE, meetingRole);
            $state.go(CONST.APPSTATE.MEETING, { 'menu': CONST.MENU.FULL });
        }

        self.loginMeeting = function (meetingItem, meetingRole) {
            $log.debug("overviewCtrl.loginMeeting");
            DialogUtils.openProgress(null, 'STR_MTG_LOGIN_PROGRESS');
            AhjoMeetingSrv.meetingLogin(meetingItem.meetingGuid, meetingRole.RoleID).then(function () {
                goToMeeting(meetingItem, meetingRole);
            }, function (error) {
                $log.error("overviewCtrl.loginMeeting: " + JSON.stringify(error));
                $rootScope.failedInfo('STR_LOGIN_FAILED');
            }).finally(function () {
                DialogUtils.closeProgress();
            });
        };

        self.showInfo = function () {
            $log.debug("overviewCtrl: showInfo");
        };

        self.upperClicked = function () {
            self.blockMode = (self.blockMode === CONST.BLOCKMODE.PRIMARY || self.blockMode === CONST.BLOCKMODE.SECONDARY) ? CONST.BLOCKMODE.DEFAULT : CONST.BLOCKMODE.PRIMARY;
        };

        self.lowerClicked = function () {
            self.blockMode = (self.blockMode === CONST.BLOCKMODE.SECONDARY || self.blockMode === CONST.BLOCKMODE.PRIMARY) ? CONST.BLOCKMODE.DEFAULT : CONST.BLOCKMODE.SECONDARY;
        };

        self.setMtgsVisible = function (mtgs) {
            self.vblMtgs = mtgs;
            StorageSrv.setKey(CONST.KEY.VISIBLE_MTGS, mtgs);
        };

        self.setClosedSignReqs = function (value) {
            self.closedSignReqs = value;
            StorageSrv.setKey(CONST.KEY.SIGNING_RES, value);
        };

        function logoutRest() {
            $log.debug("overviewCtrl.logoutRest");
            self.logoutProm = $http({
                method: 'GET',
                withCredentials: true,
                url: ENV.AHJOAPI_USERLOGOUTREST
            }).then(function successCallback(/*response*/) {
                $log.debug("overviewCtrl.logoutRest: done");
                $state.go(CONST.APPSTATE.LOGIN);
            }, function errorCallback(error) {
                $log.error(error);
            }).finally(function () {
            });
        }

        self.logout = function () {
            $log.debug("overviewCtrl.logout");
            if (!self.logoutProm) {
                logoutRest();
            }
            else {
                $log.error("overviewCtrl.logout: ignored");
            }
        };

        $scope.$on('$destroy', function () {
            $log.debug("overviewCtrl: DESTROY");
        });
    }]);<commit_msg>Clear dialogs in overview and use new DialogUtils<commit_after>/**
 * (c) 2016 <NAME>
 * Licensed under the MIT license.
 */
'use strict';

/**
 * @ngdoc function
 * @name dashboard.controller:OverviewCtrl
 * @description
 * # OverviewCtrl
 * Controller of the dashboard
 */
angular.module('dashboard')
    .controller('overviewCtrl', ['$scope', '$log', 'ENV', 'SigningOpenApi', '$state', '$rootScope', 'CONST', '$stateParams', 'MTGD', 'StorageSrv', '$http', 'DialogUtils', 'AhjoMeetingSrv', function ($scope, $log, ENV, SigningOpenApi, $state, $rootScope, CONST, $stateParams, MTGD, StorageSrv, $http, DialogUtils, AhjoMeetingSrv) {
        $log.debug("overviewCtrl: CONTROLLER, mode: ", $stateParams.state);
        var self = this;
        self.loading = 0;
        self.signReqsHeader = 'Avoimet allekirjoituspyynnöt';
        self.signErr = null;
        self.blockMode = CONST.BLOCKMODE.DEFAULT;
        self.vbl = MTGD.VISIBLE;
        self.bms = CONST.BLOCKMODE;

        var visibleMtgs = StorageSrv.getKey(CONST.KEY.VISIBLE_MTGS);
        switch (visibleMtgs) {
            case MTGD.VISIBLE.OPEN:
                self.vblMtgs = MTGD.VISIBLE.OPEN;
                break;
            case MTGD.VISIBLE.CLOSED:
                self.vblMtgs = MTGD.VISIBLE.CLOSED;
                break;
            default:
                self.vblMtgs = MTGD.VISIBLE.OPEN;
                break;
        }

        var signingRes = StorageSrv.getKey(CONST.KEY.SIGNING_RES);
        self.closedSignReqs = signingRes ? signingRes : false;

        $rootScope.menu = CONST.MENU.CLOSED;
        var mode = $stateParams.state;
        var storedMode = localStorage.overviewState;

        if (mode === CONST.HOMEMODE.ALL) {
            if (storedMode === '1') {
                mode = CONST.HOMEMODE.MEETINGS;
            }
            else if (storedMode === '2') {
                mode = CONST.HOMEMODE.ESIGN;
            }
        }

        switch (mode) {
            case CONST.HOMEMODE.MEETINGS:
                self.hasMeetings = true;
                break;
            case CONST.HOMEMODE.ESIGN:
                self.hasEsign = true;
                break;
            default:
                self.hasMeetings = true;
                self.hasEsign = true;
                break;
        }

        localStorage.overviewState = mode;

        function goToMeeting(meetingItem, meetingRole) {
            $log.debug("overviewCtrl.goToMeeting");
            StorageSrv.setKey(CONST.KEY.MEETING_ITEM, meetingItem);
            StorageSrv.setKey(CONST.KEY.MEETING_ROLE, meetingRole);
            $state.go(CONST.APPSTATE.MEETING, { 'menu': CONST.MENU.FULL });
        }

        self.loginMeeting = function (meetingItem, meetingRole) {
            $log.debug("overviewCtrl.loginMeeting");
            DialogUtils.openProgress('STR_MTG_LOGIN_PROGRESS');
            AhjoMeetingSrv.meetingLogin(meetingItem.meetingGuid, meetingRole.RoleID).then(function () {
                goToMeeting(meetingItem, meetingRole);
            }, function (error) {
                $log.error("overviewCtrl.loginMeeting: " + JSON.stringify(error));
                $rootScope.failedInfo('STR_LOGIN_FAILED');
            }).finally(function () {
                DialogUtils.closeProgress();
            });
        };

        self.showInfo = function () {
            $log.debug("overviewCtrl: showInfo");
        };

        self.upperClicked = function () {
            self.blockMode = (self.blockMode === CONST.BLOCKMODE.PRIMARY || self.blockMode === CONST.BLOCKMODE.SECONDARY) ? CONST.BLOCKMODE.DEFAULT : CONST.BLOCKMODE.PRIMARY;
        };

        self.lowerClicked = function () {
            self.blockMode = (self.blockMode === CONST.BLOCKMODE.SECONDARY || self.blockMode === CONST.BLOCKMODE.PRIMARY) ? CONST.BLOCKMODE.DEFAULT : CONST.BLOCKMODE.SECONDARY;
        };

        self.setMtgsVisible = function (mtgs) {
            self.vblMtgs = mtgs;
            StorageSrv.setKey(CONST.KEY.VISIBLE_MTGS, mtgs);
        };

        self.setClosedSignReqs = function (value) {
            self.closedSignReqs = value;
            StorageSrv.setKey(CONST.KEY.SIGNING_RES, value);
        };

        function logoutRest() {
            $log.debug("overviewCtrl.logoutRest");
            self.logoutProm = $http({
                method: 'GET',
                withCredentials: true,
                url: ENV.AHJOAPI_USERLOGOUTREST
            }).then(function successCallback(/*response*/) {
                $log.debug("overviewCtrl.logoutRest: done");
                $state.go(CONST.APPSTATE.LOGIN);
            }, function errorCallback(error) {
                $log.error(error);
            }).finally(function () {
            });
        }

        self.logout = function () {
            $log.debug("overviewCtrl.logout");
            if (!self.logoutProm) {
                logoutRest();
            }
            else {
                $log.error("overviewCtrl.logout: ignored");
            }
        };

        $scope.$on('$destroy', function () {
            $log.debug("overviewCtrl: DESTROY");
        });

        DialogUtils.clearAll(); // Clear all in case user navigates back from deeper views where a progress dialog etc. are displayed
    }]);
{'fraction_non_alphanumeric': 0.12455205811138015, 'fraction_numerical': 0.0013559322033898306, 'mean_word_length': 1.8981195621667135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4726241', 'n_tokens_mistral': 3152, 'n_tokens_neox': 3026, 'n_words': 496}