{"size": 2513, "ext": "js", "max_stars_repo_path": "kronos-web/src/main/resources/static/scripts/controllers/SettingsController.js", "max_stars_repo_name": "konexios/moonstone", "max_stars_repo_stars_event_min_datetime": "2019-12-24T05:28:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-02T21:20:16.000Z", "max_issues_repo_path": "kronos-web/src/main/resources/static/scripts/controllers/SettingsController.js", "max_issues_repo_name": "arrow-acs/moonstone", "max_issues_repo_issues_event_min_datetime": "2019-11-20T17:10:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-18T15:09:12.000Z", "max_forks_repo_path": "kronos-web/src/main/resources/static/scripts/controllers/SettingsController.js", "max_forks_repo_name": "arrow-acs/moonstone", "max_forks_repo_forks_event_min_datetime": "2021-05-02T21:20:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-02T21:20:30.000Z"}
{"max_stars_count": 3, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 39.8888888889, "max_line_length": 143, "alphanum_fraction": 0.5869478711}
controllers.controller('SettingsController', [
    '$scope', '$timeout', '$routeParams', '$uibModal', 'SettingsService', 'SecurityService', 'ErrorService', 'SpinnerService', 'ToastrService',
    function ($scope, $timeout, $routeParams, $uibModal, SettingsService, SecurityService, ErrorService, SpinnerService, ToastrService) {
        $scope.loading = true;

        $scope.activeTab = 0;

        $scope.canSaveConfigurations = SecurityService.canSaveSettings();
        $scope.canEditIoTConfig = SecurityService.canEditIoTConfig();
        $scope.canProvisionApplication = SecurityService.canProvisionApplication();

        $scope.model = null;

        $scope.collapseMenu = function(){
            if($scope.mobileLayot){
                $scope.mobileMenuShowed=!$scope.mobileMenuShowed
            }else{
                $scope.collapsedView=!$scope.collapsedView;
            }
        };

        $scope.$on('resize', function (event, data) {
            if (data.width < 992) {
                $scope.mobileLayot = true;
           } else {
               $scope.mobileLayot = false;
               $scope.mobileMenuShowed = false;
            }
            $timeout(function () {
                $scope.$apply();
            }, 0, false);
        });
        $scope.mobileMenuShowed = false;

        $scope.saveConfigurations = function(form) {
            if (form.$valid) {
                SpinnerService.wrap(SettingsService.saveConfigurations, $scope.model.configurations)
                .then(function(response) {
                    $scope.model.configurations = response.data;
                    ToastrService.popupSuccess('Configuration has been saved successfully.');
                })
                .catch(ErrorService.handleHttpError);
            } else {
                ToastrService.popupError('Configuration cannot be saved because of invalid fields, please check errors.');
            }
        };

        $scope.canShowSaveConfigsBtn = function(configurations) {
            // show save button if have one or more editable (not readonly) configurations
            return !!configurations && configurations.length > 0 && configurations.some(function(conf){ return !conf.readonly; });
        };

        SpinnerService.wrap(SettingsService.getSettings)
        .then(function(response) {
            $scope.model = response.data;
        })
        .catch(ErrorService.handleHttpError)
        .finally(function() {
            $scope.loading = false;
        });
    }
]);
