<commit_before>/*jslint browser: true*/
/*globals $, jQuery, angular, TypiCMS, alertify, top, window, console*/

(function (angular) {

    'use strict';

    angular.module('typicms').controller('ListController', ['$http', '$scope', '$location', '$api', '$cookies', function ($http, $scope, $location, $api, $cookies) {

        $scope.itemsByPage = 100;
        $scope.allChecked = false;
        $scope.deleteLimit = 1000;
        var url = $location.absUrl().split('?')[0],
            modulePath = url.split('/')[4],
            $params = {};

        $scope.TypiCMS = TypiCMS;

        if (TypiCMS.content_locale == null) {
            TypiCMS.content_locale = TypiCMS.locale;
        }

        // if we query menulinks menu_id value :
        if (modulePath === 'menus' && url.split('/')[5]) {
            $params.menu_id = url.split('/')[5];
            modulePath = 'menulinks';
        }

        if (modulePath === 'projects' && url.split('/')[5]) {
            modulePath = 'projects/categories';
        }

        if (modulePath === 'pages' && url.split('/')[5]) {
            $params.page_id = url.split('/')[5];
            modulePath = 'sections';
        }

        if (TypiCMS.models) {
            $scope.models = TypiCMS.models;
            $scope.displayedModels = [].concat($scope.models);
        } else {
            $api.query($params).$promise.then(function (all) {
                $scope.models = all;
                // Copy the references (you could clone ie angular.copy but then have to go through a dirty checking for the matches)
                $scope.displayedModels = [].concat($scope.models);
            });
        }

        /**
         * Empty object that will contain checked items
         */
        $scope.checked = {
            models: []
        };

        /**
         * Check all items
         */
        $scope.toggleCheckAll = function () {
            var countChecked = $scope.checked.models.length
            $scope.checked.models = [];
            if (countChecked < $scope.displayedModels.length) {
                this.checkAll();
            }
        };

        /**
         * Check all items
         */
        $scope.checkAll = function () {
            $scope.allChecked = true;
            $scope.checked.models = [];
            $scope.displayedModels.forEach(function (model) {
                $scope.checked.models.push(model);
            });
        };

        /**
         * Uncheck all items
         */
        $scope.uncheckAll = function () {
            $scope.allChecked = false;
            $scope.checked.models = [];
        };

        /**
         * Set all checked items online or offline
         */
        $scope.setItems = function (column, value, label) {

            var ids = [],
                models = $scope.checked.models,
                number = models.length,
                data = {};

            if (!window.confirm('Are you sure you want to set ' + number + ' items ' + label + '?')) {
                return false;
            }

            if (typeof value === 'object') {
                for (var key in value) {
                    if (value.hasOwnProperty(key)) {
                        data[column+'->'+key] = value[key];
                    }
                }
            } else {
                data[column] = value;
            }

            models.forEach(function (model) {
                ids.push(model.id);
                if (typeof value === 'object') {
                    for (var key in value) {
                        if (value.hasOwnProperty(key)) {
                            model[column][key] = value[key];
                            model[column+'_translated'] = value[key];
                        }
                    }
                } else {
                    model[column] = value;
                }
            });

            $api.update({id: ids.join()}, data).$promise.then(
                function (data) {
                    if (data.number < number) {
                        alertify.error((number - data.number) + ' items could not be set ' + label + '.');
                    } else {
                        alertify.success(data.number + ' items set ' + label + '.');
                    }
                },
                function (reason) {
                    alertify.error('Error ' + reason.status + ' ' + reason.statusText);
                }
            );

        };

        /**
         * Check all items that have a key equal to value
         */
        $scope.check = function (column, value) {
            $scope.allChecked = false;
            $scope.checked.models = [];
            $scope.models.forEach(function (model) {

                if (typeof value === 'object') {
                    for (var key in value) {
                        if (value.hasOwnProperty(key)) {
                            if (model[column][key] == value[key]) {
                                $scope.checked.models.push(model);
                            }
                        }
                    }
                } else {
                    if (model[column] == value) {
                        $scope.checked.models.push(model);
                    }
                }

            });
        };

        /**
         * Check all offline items
         */
        $scope.checkUnpublished = function () {
            this.checkStatus(0);
        };

        /**
         * Check all online items
         */
        $scope.checkPublished = function () {
            this.checkStatus(1);
        };

        /**
         * Delete checked items
         */
        $scope.deleteChecked = function () {

            var ids = [],
                models = $scope.checked.models,
                number = models.length;

            if ($scope.checked.models.length > $scope.deleteLimit) {
                alertify.error('Impossible to delete more than ' + $scope.deleteLimit + ' items in one go.');
                return false;
            }<commit_msg>docblocks<commit_after>/*jslint browser: true*/
/*globals $, jQuery, angular, TypiCMS, alertify, top, window, console*/

(function (angular) {

    'use strict';

    angular.module('typicms').controller('ListController', ['$http', '$scope', '$location', '$api', '$cookies', function ($http, $scope, $location, $api, $cookies) {

        $scope.itemsByPage = 100;
        $scope.allChecked = false;
        $scope.deleteLimit = 1000;
        var url = $location.absUrl().split('?')[0],
            modulePath = url.split('/')[4],
            $params = {};

        $scope.TypiCMS = TypiCMS;

        if (TypiCMS.content_locale == null) {
            TypiCMS.content_locale = TypiCMS.locale;
        }

        // if we query menulinks menu_id value :
        if (modulePath === 'menus' && url.split('/')[5]) {
            $params.menu_id = url.split('/')[5];
            modulePath = 'menulinks';
        }

        if (modulePath === 'projects' && url.split('/')[5]) {
            modulePath = 'projects/categories';
        }

        if (modulePath === 'pages' && url.split('/')[5]) {
            $params.page_id = url.split('/')[5];
            modulePath = 'sections';
        }

        if (TypiCMS.models) {
            $scope.models = TypiCMS.models;
            $scope.displayedModels = [].concat($scope.models);
        } else {
            $api.query($params).$promise.then(function (all) {
                $scope.models = all;
                // Copy the references (you could clone ie angular.copy but then have to go through a dirty checking for the matches)
                $scope.displayedModels = [].concat($scope.models);
            });
        }

        /**
         * Empty object that will contain checked items
         */
        $scope.checked = {
            models: []
        };

        /**
         * Check all items
         */
        $scope.toggleCheckAll = function () {
            var countChecked = $scope.checked.models.length
            $scope.checked.models = [];
            if (countChecked < $scope.displayedModels.length) {
                this.checkAll();
            }
        };

        /**
         * Check all items
         */
        $scope.checkAll = function () {
            $scope.allChecked = true;
            $scope.checked.models = [];
            $scope.displayedModels.forEach(function (model) {
                $scope.checked.models.push(model);
            });
        };

        /**
         * Uncheck all items
         */
        $scope.uncheckAll = function () {
            $scope.allChecked = false;
            $scope.checked.models = [];
        };

        /**
         * Set all checked items published or unpublished
         */
        $scope.setItems = function (column, value, label) {

            var ids = [],
                models = $scope.checked.models,
                number = models.length,
                data = {};

            if (!window.confirm('Are you sure you want to set ' + number + ' items ' + label + '?')) {
                return false;
            }

            if (typeof value === 'object') {
                for (var key in value) {
                    if (value.hasOwnProperty(key)) {
                        data[column+'->'+key] = value[key];
                    }
                }
            } else {
                data[column] = value;
            }

            models.forEach(function (model) {
                ids.push(model.id);
                if (typeof value === 'object') {
                    for (var key in value) {
                        if (value.hasOwnProperty(key)) {
                            model[column][key] = value[key];
                            model[column+'_translated'] = value[key];
                        }
                    }
                } else {
                    model[column] = value;
                }
            });

            $api.update({id: ids.join()}, data).$promise.then(
                function (data) {
                    if (data.number < number) {
                        alertify.error((number - data.number) + ' items could not be set ' + label + '.');
                    } else {
                        alertify.success(data.number + ' items set ' + label + '.');
                    }
                },
                function (reason) {
                    alertify.error('Error ' + reason.status + ' ' + reason.statusText);
                }
            );

        };

        /**
         * Check all items that have a key equal to value
         */
        $scope.check = function (column, value) {
            $scope.allChecked = false;
            $scope.checked.models = [];
            $scope.models.forEach(function (model) {

                if (typeof value === 'object') {
                    for (var key in value) {
                        if (value.hasOwnProperty(key)) {
                            if (model[column][key] == value[key]) {
                                $scope.checked.models.push(model);
                            }
                        }
                    }
                } else {
                    if (model[column] == value) {
                        $scope.checked.models.push(model);
                    }
                }

            });
        };

        /**
         * Check all unpublished items
         */
        $scope.checkUnpublished = function () {
            this.checkStatus(0);
        };

        /**
         * Check all published items
         */
        $scope.checkPublished = function () {
            this.checkStatus(1);
        };

        /**
         * Delete checked items
         */
        $scope.deleteChecked = function () {

            var ids = [],
                models = $scope.checked.models,
                number = models.length;

            if ($scope.checked.models.length > $scope.deleteLimit) {
                alertify.error('Impossible to delete more than ' + $scope.deleteLimit + ' items in one go.');
                return false;
            }
{'fraction_non_alphanumeric': 0.1325161504058307, 'fraction_numerical': 0.002650323008116614, 'mean_word_length': 1.1878963580358761, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4624868', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3004, 'n_words': 644}