<commit_before>app.controller('IdeaController', function($controller, $scope, FeatureProposalRepo, Idea, IdeaState, ServiceRepo) {

    angular.extend(this, $controller('AbstractIdeaController', {
        $scope: $scope
    }));

    $scope.ideaToDelete = {};

    $scope.states = IdeaState;

    $scope.weaverTable = {
        repo: $scope.ideaRepo,
        columns: [{
                gloss: 'Service',
                property: 'service.name',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Title',
                property: 'title',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Description',
                property: 'description',
                filterable: true,
                sortable: false
            },
            {
                gloss: 'Last Modified',
                property: 'lastModified',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Status',
                property: 'state',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Actions',
                filterable: false,
                sortable: false
            }
        ],
        activeSort: [{
                property: 'service.name',
                direction: 'ASC'
            },
            {
                property: 'lastModified',
                direction: 'DESC'
            }
        ]
    };

    ServiceRepo.ready().then(function () {

        $scope.tableParams = $scope.ideaRepo.getTableParams();
        $scope.featureProposalsTableParams = FeatureProposalRepo.getTableParams();

        $scope.resetIdeas = function () {
            $scope.resetForms($scope.ideaData);
            $scope.ideaData = new Idea({
                title: '',
                description: '',
                service: $scope.service ? $scope.service : $scope.services[0]
            });
            $scope.closeModal();
        };

        $scope.resetIdeas();

    });

    $scope.createIdea = function () {
        $scope.creating = true;
        $scope.ideaRepo.create($scope.ideaData).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.creating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.editIdea = function (idea) {
        $scope.ideaData = idea;
        $scope.openModal('#editIdeaModal');
    };

    $scope.updateIdea = function () {
        $scope.updating = true;
        $scope.ideaRepo.update($scope.ideaData).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.updating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.confirmReject = function(idea) {
        $scope.resetIdeas();
        $scope.openModal('#rejectIdeaModal');
        $scope.ideaToReject = idea;
    };

    $scope.rejectIdea = function () {
        $scope.updating = true;
        $scope.ideaRepo.reject($scope.ideaToReject).then(function(res) {
            var result = angular.fromJson(res.body);
            if (result.meta.status === 'SUCCESS') {
                $scope.resetIdeas();
                $scope.updating = false;
                $scope.ideaToReject = {};
            } else if (result.meta.status === 'INVALID') {
                $scope.updating = false;
            }
        });
    };

    $scope.confirmSendToHelpdesk = function (idea) {
        $scope.resetIdeas();
        $scope.openModal('#sendToHelpdeskModal');
        $scope.ideaToSendToHelpdesk = idea;
    };

    $scope.sendToHelpdesk = function () {
        $scope.updating = true;
        $scope.ideaRepo.sendToHelpdesk($scope.ideaToSendToHelpdesk).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.resetIdeas();
                $scope.updating = false;
                $scope.ideaToSendToHelpdesk = {};
            }
        });
    };

    $scope.confirmDelete = function(idea) {
        $scope.resetIdeas();
        $scope.openModal('#deleteIdeaModal');
        $scope.ideaToDelete = idea;
    };

    $scope.deleteIdea = function () {
        $scope.deleting = true;
        $scope.ideaToDelete.delete().then(function () {
            $scope.closeModal();
            $scope.deleting = false;
            $scope.ideaToDelete = {};
        });
    };

    $scope.elevateIdea = function (idea) {
        $scope.elevating = true;
        FeatureProposalRepo.elevate(idea).then(function (res) {
            var apiRes = angular.fromJson(res.body);
            if (apiRes.meta.status === 'SUCCESS') {
                $scope.elevating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.setOverallCheckbox = function () {
        var overallCheckbox = angular.element('#overallCheckbox')[0];
        if ($scope.selectedIdeas.length === 0) {
            overallCheckbox.indeterminate = false;
            overallCheckbox.checked = false;
        } else if ($scope.selectedIdeas.length === $scope.ideasTableParams._settings.total) {
            overallCheckbox.indeterminate = false;
            overallCheckbox.checked = true;
        } else {
            overallCheckbox.indeterminate = true;
            overallCheckbox.checked = false;
        }
    };

    $scope.toggleSelectIdea = function (idea) {
        if ($scope.isSelectedIdea(idea)) {
            $scope.removeIdeaFromSelected(idea);
        } else {
            $scope.selectedIdeas.push(idea);
        }
        $scope.setOverallCheckbox();
    };

    $scope.toggleAll = function () {
        if ($scope.overallCheckboxValue || $scope.anyOnPageSelected()) {
            for (var i in $scope.ideasTableParams.data) {
                var ii = $scope.ideasTableParams.data[i];
                if ($scope.isSelectedIdea(ii)) {
                    $scope.removeIdeaFromSelected(ii);
                }
            }
        } else {
            for (var j in $scope.ideasTableParams.data) {
                var ij = $scope.ideasTableParams.data[j];
                if (!$scope.isSelectedIdea(ij)) {
                    $scope.selectedIdeas.push(ij);
                }
            }
        }
        $scope.setOverallCheckbox();
    };

    $scope.anyOnPageSelected = function () {
        var anySelected = false;
        for (var i in $scope.ideasTableParams.data) {
            var idea = $scope.ideasTableParams.data[i];
            if ($scope.isSelectedIdea(idea)) {
                anySelected = true;
                break;
            }
        }
        return anySelected;
    };

    $scope.isSelectedIdea = function (idea) {
        var selected = false;
        for (var i in $scope.selectedIdeas) {
            if (idea.id === $scope.selectedIdeas[i].id) {
                selected = true;
                break;
            }<commit_msg>Fixed loop to ignore visibleColumnCount<commit_after>app.controller('IdeaController', function($controller, $scope, FeatureProposalRepo, Idea, IdeaState, ServiceRepo) {

    angular.extend(this, $controller('AbstractIdeaController', {
        $scope: $scope
    }));

    $scope.ideaToDelete = {};

    $scope.states = IdeaState;

    $scope.weaverTable = {
        repo: $scope.ideaRepo,
        columns: [{
                gloss: 'Service',
                property: 'service.name',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Title',
                property: 'title',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Description',
                property: 'description',
                filterable: true,
                sortable: false
            },
            {
                gloss: 'Last Modified',
                property: 'lastModified',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Status',
                property: 'state',
                filterable: true,
                sortable: true
            },
            {
                gloss: 'Actions',
                filterable: false,
                sortable: false
            }
        ],
        activeSort: [{
                property: 'service.name',
                direction: 'ASC'
            },
            {
                property: 'lastModified',
                direction: 'DESC'
            }
        ]
    };

    ServiceRepo.ready().then(function () {

        $scope.tableParams = $scope.ideaRepo.getTableParams();
        $scope.featureProposalsTableParams = FeatureProposalRepo.getTableParams();

        $scope.resetIdeas = function () {
            $scope.resetForms($scope.ideaData);
            $scope.ideaData = new Idea({
                title: '',
                description: '',
                service: $scope.service ? $scope.service : $scope.services[0]
            });
            $scope.closeModal();
        };

        $scope.resetIdeas();

    });

    $scope.createIdea = function () {
        $scope.creating = true;
        $scope.ideaRepo.create($scope.ideaData).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.creating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.editIdea = function (idea) {
        $scope.ideaData = idea;
        $scope.openModal('#editIdeaModal');
    };

    $scope.updateIdea = function () {
        $scope.updating = true;
        $scope.ideaRepo.update($scope.ideaData).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.updating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.confirmReject = function(idea) {
        $scope.resetIdeas();
        $scope.openModal('#rejectIdeaModal');
        $scope.ideaToReject = idea;
    };

    $scope.rejectIdea = function () {
        $scope.updating = true;
        $scope.ideaRepo.reject($scope.ideaToReject).then(function(res) {
            var result = angular.fromJson(res.body);
            if (result.meta.status === 'SUCCESS') {
                $scope.resetIdeas();
                $scope.updating = false;
                $scope.ideaToReject = {};
            } else if (result.meta.status === 'INVALID') {
                $scope.updating = false;
            }
        });
    };

    $scope.confirmSendToHelpdesk = function (idea) {
        $scope.resetIdeas();
        $scope.openModal('#sendToHelpdeskModal');
        $scope.ideaToSendToHelpdesk = idea;
    };

    $scope.sendToHelpdesk = function () {
        $scope.updating = true;
        $scope.ideaRepo.sendToHelpdesk($scope.ideaToSendToHelpdesk).then(function (res) {
            if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
                $scope.resetIdeas();
                $scope.updating = false;
                $scope.ideaToSendToHelpdesk = {};
            }
        });
    };

    $scope.confirmDelete = function(idea) {
        $scope.resetIdeas();
        $scope.openModal('#deleteIdeaModal');
        $scope.ideaToDelete = idea;
    };

    $scope.deleteIdea = function () {
        $scope.deleting = true;
        $scope.ideaToDelete.delete().then(function () {
            $scope.closeModal();
            $scope.deleting = false;
            $scope.ideaToDelete = {};
        });
    };

    $scope.elevateIdea = function (idea) {
        $scope.elevating = true;
        FeatureProposalRepo.elevate(idea).then(function (res) {
            var apiRes = angular.fromJson(res.body);
            if (apiRes.meta.status === 'SUCCESS') {
                $scope.elevating = false;
                $scope.resetIdeas();
            }
        });
    };

    $scope.setOverallCheckbox = function () {
        var overallCheckbox = angular.element('#overallCheckbox')[0];
        if ($scope.selectedIdeas.length === 0) {
            overallCheckbox.indeterminate = false;
            overallCheckbox.checked = false;
        } else if ($scope.selectedIdeas.length === $scope.ideasTableParams._settings.total) {
            overallCheckbox.indeterminate = false;
            overallCheckbox.checked = true;
        } else {
            overallCheckbox.indeterminate = true;
            overallCheckbox.checked = false;
        }
    };

    $scope.toggleSelectIdea = function (idea) {
        if ($scope.isSelectedIdea(idea)) {
            $scope.removeIdeaFromSelected(idea);
        } else {
            $scope.selectedIdeas.push(idea);
        }
        $scope.setOverallCheckbox();
    };

    $scope.toggleAll = function () {
        if ($scope.overallCheckboxValue || $scope.anyOnPageSelected()) {
            for (var i in $scope.ideasTableParams.data) {
                var ii = $scope.ideasTableParams.data[i];
                if ($scope.isSelectedIdea(ii)) {
                    $scope.removeIdeaFromSelected(ii);
                }
            }
        } else {
            for (var j = 0; j < $scope.ideasTableParams.data.length; j++) {
                var ij = $scope.ideasTableParams.data[j];
                if (!$scope.isSelectedIdea(ij)) {
                    $scope.selectedIdeas.push(ij);
                }
            }
        }
        $scope.setOverallCheckbox();
    };

    $scope.anyOnPageSelected = function () {
        var anySelected = false;
        for (var i in $scope.ideasTableParams.data) {
            var idea = $scope.ideasTableParams.data[i];
            if ($scope.isSelectedIdea(idea)) {
                anySelected = true;
                break;
            }
        }
        return anySelected;
    };

    $scope.isSelectedIdea = function (idea) {
        var selected = false;
        for (var i in $scope.selectedIdeas) {
            if (idea.id === $scope.selectedIdeas[i].id) {
                selected = true;
                break;
            }
{'fraction_non_alphanumeric': 0.12764606265876377, 'fraction_numerical': 0.0004939316963025684, 'mean_word_length': 1.5263814616755793, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '4019451', 'n_tokens_mistral': 4090, 'n_tokens_neox': 3877, 'n_words': 608}