<commit_before>/*
 * Copyright (c) 2014 Kagilum SAS.
 *
 * This file is part of iceScrum.
 *
 * iceScrum is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * iceScrum is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with iceScrum.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *
 * <NAME> (<EMAIL>)
 *
 */
controllers.controller('projectCtrl', ["$scope", 'ProjectService', 'Session', '$modal', function($scope, ProjectService, Session, $modal) {
    $scope.showProjectEditModal = function(view) {
        var childScope = $scope.$new();
        if (view) {
            $scope.panel = { current: view };
        }
        $modal.open({
            keyboard: false,
            templateUrl: $scope.serverUrl + "/project/edit",
            size: 'lg',
            scope: childScope,
            controller: 'editProjectModalCtrl'
        });
    };
    $scope.showProjectListModal = function(type) {
        $modal.open({
            keyboard: false,
            templateUrl: $scope.serverUrl + "/project/listModal",
            size: 'lg',
            controller: ['$scope', '$controller', 'ProjectService', function($scope, $controller, ProjectService) {
                $controller('abstractProjectListCtrl', { $scope: $scope });
                // Functions
                $scope.searchProjects = function() {
                    var offset = $scope.projectsPerPage * ($scope.currentPage - 1);
                    var listFunction = type == 'public' ? ProjectService.listPublic : ProjectService.listByUser;
                    listFunction($scope.projectSearch, offset).then(function(projectsAndTotal) {
                        $scope.totalProjects = projectsAndTotal.total;
                        $scope.projects = projectsAndTotal.projects;
                        if (!_.isEmpty($scope.projects) && _.isEmpty($scope.project)) {
                            $scope.selectProject(_.first($scope.projects));
                        }
                    });
                };
                // Init
                $scope.totalProjects = 0;
                $scope.currentPage = 1;
                $scope.projectsPerPage = 9; // Constant
                $scope.projectSearch = '';
                $scope.projects = [];
                $scope.searchProjects();
            }]
        });
    };

    $scope['import'] = function(project) {
        var url = $scope.serverUrl + "/project/import";
        $modal.open({
            keyboard: false,
            templateUrl: url + "Dialog",
            controller: ['$scope', '$http', function($scope, $http) {
                $scope.flowConfig = {target: url, singleFile: true};
                $scope.changes = false;
                $scope._changes = {
                    showTeam: false,
                    showProject: false
                };
                $scope.progress = false;

                $scope.checkValidation = function($message) {
                    if ($message) {
                        $scope.progress = false;
                        $scope.changes = !angular.isObject($message) ? JSON.parse($message) : $message;
                        $scope._changes = angular.copy($scope.changes);
                        $scope._changes = angular.extend($scope._changes, {
                            showTeam: $scope.changes.team ? true : false,
                            showUsers: $scope.changes.users ? true : false,
                            showProjectName: $scope.changes.product ? ($scope.changes.product.name ? true : false) : false,
                            showProjectPkey: $scope.changes.product ? ($scope.changes.product.pkey ? true : false) : false
                        });
                    }
                };

                $scope.applyChanges = function() {
                    $http({
                        url: url,
                        method: 'POST',
                        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                        transformRequest: function(data) {
                            return formObjectData(data, 'changes.');
                        },
                        data: $scope.changes
                    })
                    .then(function(response) {
                            if (response.data && response.data.class == 'Product') {
                                document.location = $scope.serverUrl + '/p/' + response.data.pkey + '/';
                            } else {
                                $scope.checkValidation(response.data);
                            }
                        }, function() {
                            $scope.progress = false;
                        }
                    );
                    $scope.progress = true;
                };
            }]
        });
    };
    $scope['export'] = function(project) {
        var modal = $modal.open({
            keyboard: false,
            templateUrl: "project/exportDialog",
            controller: ['$scope', function($scope) {
                $scope.zip = true;
                $scope.progress = false;
                $scope.start = function() {
                    $scope.downloadFile("project/export" + ($scope.zip ? "?zip=true" : ""));
                    $scope.progress = true;
                }
            }]
        });
        modal.result.then(
            function() {
                $scope.downloadFile("");
            },
            function() {
                $scope.downloadFile("");
            }
        );
    };

    $scope['gotoHome'] = function(){
        $scope.$state.go('home');
    };

    // Init
    $scope.currentProject = Session.getProject();
}]);

controllers.controller('dashboardCtrl', ['$scope', 'ProjectService', 'ReleaseService', 'SprintService', 'PushService', function($scope, ProjectService, ReleaseService, SprintService, PushService) {
    $scope.authorizedRelease = function(action, release) {
        return ReleaseService.authorizedRelease(action, release);
    };
    $scope.authorizedSprint = function(action, sprint) {
        return SprintService.authorizedSprint(action, sprint);
    };
    $scope.updateRelease = function(release) {
        if (!_.isEqual($scope.editableReleaseReference, $scope.editableRelease)) {
            ReleaseService.update(release)
                .then(function(updatedRelease) {
                    angular.extend($scope.release, updatedRelease);
                    $scope.editableRelease = $scope.release;
                    $scope.editableReleaseReference = $scope.release;
                    $scope.notifySuccess('todo.is.ui.release.updated');
                });
        }
    };
    $scope.updateSprint = function(sprint) {
        if (!_.isEqual($scope.editableCurrentOrLastSprintReference, $scope.editableCurrentOrLastSprint)) {
            SprintService.update(sprint, $scope.currentProject.id)
                .then(function(updatedSprint) {
                    angular.extend($scope.currentOrLastSprint, updatedSprint);<commit_msg>- close project -> gotohome<commit_after>/*
 * Copyright (c) 2014 Kagilum SAS.
 *
 * This file is part of iceScrum.
 *
 * iceScrum is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * iceScrum is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with iceScrum.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *
 * <NAME> (<EMAIL>)
 *
 */
controllers.controller('projectCtrl', ["$scope", 'ProjectService', 'Session', '$modal', function($scope, ProjectService, Session, $modal) {
    $scope.showProjectEditModal = function(view) {
        var childScope = $scope.$new();
        if (view) {
            $scope.panel = { current: view };
        }
        $modal.open({
            keyboard: false,
            templateUrl: $scope.serverUrl + "/project/edit",
            size: 'lg',
            scope: childScope,
            controller: 'editProjectModalCtrl'
        });
    };
    $scope.showProjectListModal = function(type) {
        $modal.open({
            keyboard: false,
            templateUrl: $scope.serverUrl + "/project/listModal",
            size: 'lg',
            controller: ['$scope', '$controller', 'ProjectService', function($scope, $controller, ProjectService) {
                $controller('abstractProjectListCtrl', { $scope: $scope });
                // Functions
                $scope.searchProjects = function() {
                    var offset = $scope.projectsPerPage * ($scope.currentPage - 1);
                    var listFunction = type == 'public' ? ProjectService.listPublic : ProjectService.listByUser;
                    listFunction($scope.projectSearch, offset).then(function(projectsAndTotal) {
                        $scope.totalProjects = projectsAndTotal.total;
                        $scope.projects = projectsAndTotal.projects;
                        if (!_.isEmpty($scope.projects) && _.isEmpty($scope.project)) {
                            $scope.selectProject(_.first($scope.projects));
                        }
                    });
                };
                // Init
                $scope.totalProjects = 0;
                $scope.currentPage = 1;
                $scope.projectsPerPage = 9; // Constant
                $scope.projectSearch = '';
                $scope.projects = [];
                $scope.searchProjects();
            }]
        });
    };

    $scope['import'] = function(project) {
        var url = $scope.serverUrl + "/project/import";
        $modal.open({
            keyboard: false,
            templateUrl: url + "Dialog",
            controller: ['$scope', '$http', function($scope, $http) {
                $scope.flowConfig = {target: url, singleFile: true};
                $scope.changes = false;
                $scope._changes = {
                    showTeam: false,
                    showProject: false
                };
                $scope.progress = false;

                $scope.checkValidation = function($message) {
                    if ($message) {
                        $scope.progress = false;
                        $scope.changes = !angular.isObject($message) ? JSON.parse($message) : $message;
                        $scope._changes = angular.copy($scope.changes);
                        $scope._changes = angular.extend($scope._changes, {
                            showTeam: $scope.changes.team ? true : false,
                            showUsers: $scope.changes.users ? true : false,
                            showProjectName: $scope.changes.product ? ($scope.changes.product.name ? true : false) : false,
                            showProjectPkey: $scope.changes.product ? ($scope.changes.product.pkey ? true : false) : false
                        });
                    }
                };

                $scope.applyChanges = function() {
                    $http({
                        url: url,
                        method: 'POST',
                        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                        transformRequest: function(data) {
                            return formObjectData(data, 'changes.');
                        },
                        data: $scope.changes
                    })
                    .then(function(response) {
                            if (response.data && response.data.class == 'Product') {
                                document.location = $scope.serverUrl + '/p/' + response.data.pkey + '/';
                            } else {
                                $scope.checkValidation(response.data);
                            }
                        }, function() {
                            $scope.progress = false;
                        }
                    );
                    $scope.progress = true;
                };
            }]
        });
    };
    $scope['export'] = function(project) {
        var modal = $modal.open({
            keyboard: false,
            templateUrl: "project/exportDialog",
            controller: ['$scope', function($scope) {
                $scope.zip = true;
                $scope.progress = false;
                $scope.start = function() {
                    $scope.downloadFile("project/export" + ($scope.zip ? "?zip=true" : ""));
                    $scope.progress = true;
                }
            }]
        });
        modal.result.then(
            function() {
                $scope.downloadFile("");
            },
            function() {
                $scope.downloadFile("");
            }
        );
    };

    $scope.goToHome = function(){
        $scope.$state.go('root');
    };

    // Init
    $scope.currentProject = Session.getProject();
}]);

controllers.controller('dashboardCtrl', ['$scope', 'ProjectService', 'ReleaseService', 'SprintService', 'PushService', function($scope, ProjectService, ReleaseService, SprintService, PushService) {
    $scope.authorizedRelease = function(action, release) {
        return ReleaseService.authorizedRelease(action, release);
    };
    $scope.authorizedSprint = function(action, sprint) {
        return SprintService.authorizedSprint(action, sprint);
    };
    $scope.updateRelease = function(release) {
        if (!_.isEqual($scope.editableReleaseReference, $scope.editableRelease)) {
            ReleaseService.update(release)
                .then(function(updatedRelease) {
                    angular.extend($scope.release, updatedRelease);
                    $scope.editableRelease = $scope.release;
                    $scope.editableReleaseReference = $scope.release;
                    $scope.notifySuccess('todo.is.ui.release.updated');
                });
        }
    };
    $scope.updateSprint = function(sprint) {
        if (!_.isEqual($scope.editableCurrentOrLastSprintReference, $scope.editableCurrentOrLastSprint)) {
            SprintService.update(sprint, $scope.currentProject.id)
                .then(function(updatedSprint) {
                    angular.extend($scope.currentOrLastSprint, updatedSprint);
{'fraction_non_alphanumeric': 0.12063066085206306, 'fraction_numerical': 0.0013418316001341832, 'mean_word_length': 1.5664600550964187, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554855', 'n_tokens_mistral': 3699, 'n_tokens_neox': 3527, 'n_words': 746}