<commit_before>(function(module) {
    module.factory('selectItems', selectItemsService);

    selectItemsService.$inject = ["$modal"];
    function selectItemsService($modal) {
        return {
            open: function() {
                var tabs = {
                    processes: false,
                    files: false,
                    samples: false,
                    reviews: false
                };

                if (arguments.length === 0) {
                    throw "Invalid arguments to service selectItems:open()";
                }

                for (var i = 0; i < arguments.length; i++) {
                    tabs[arguments[i]] = true;
                }

                var modal = $modal.open({
                    size: 'lg',
                    templateUrl: 'global.services/select-items/select-items.html',
                    controller: 'SelectItemsServiceModalController',
                    controllerAs: 'ctrl',
                    resolve: {
                        showProcesses: function() {
                            return tabs.processes;
                        },

                        showFiles: function() {
                            return tabs.files;
                        },

                        showSamples: function() {
                            return tabs.samples;
                        },

                        showReviews: function() {
                            return tabs.reviews;
                        }
                    }
                });
                return modal.result;
            }
        };
    }

    module.controller('SelectItemsServiceModalController', SelectItemsServiceModalController);
    SelectItemsServiceModalController.$inject = ['$modalInstance', 'showProcesses',
        'showFiles', 'showSamples', 'showReviews', 'projectsService', '$stateParams', 'project'];

    function SelectItemsServiceModalController($modalInstance, showProcesses, showFiles, showSamples,
                                               showReviews, projectsService, $stateParams, project) {
        var ctrl = this;

        ctrl.project = project.get();
        ctrl.tabs = loadTabs();
        ctrl.activeTab = ctrl.tabs[0].name;
        ctrl.setActive = setActive;
        ctrl.isActive = isActive;
        ctrl.ok = ok;
        ctrl.cancel = cancel;
        ctrl.processes = [];
        ctrl.samples = [];

        /////////////////////////

        function setActive(tab) {
            ctrl.activeTab = tab;
        }

        function isActive(tab) {
            return ctrl.activeTab === tab;
        }

        function ok() {
            var selectedProcesses = ctrl.processes.filter(function(p) {
                return p.input || p.output;
            });

            var selectedSamples = ctrl.samples.filter(function(s) {
                return s.selected;
            });

            var selectedFiles = getSelectedFiles();

            $modalInstance.close({
                processes: selectedProcesses,
                samples: selectedSamples,
                files: selectedFiles
            });
        }

        function getSelectedFiles() {
            var files = [],
                treeModel = new TreeModel(),
                root = treeModel.parse(project.get().files[0]);
            // Walk the tree looking for selected files and adding them to the
            // list of files. Also reset the selected flag so the next time
            // the popup for files is used it doesn't show previously selected
            // items.
            root.walk({strategy: 'pre'}, function(node) {
                if (node.model.data.selected) {
                    node.model.data.selected = false;
                    if (node.model.data._type === 'file') {
                        files.push(node.model.data);
                    }
                }
            });
            return files;
        }

        function cancel() {
            $modalInstance.dismiss('cancel');
        }

        function loadTabs() {<commit_msg>Handle case where there are no files.<commit_after>(function(module) {
    module.factory('selectItems', selectItemsService);

    selectItemsService.$inject = ["$modal"];
    function selectItemsService($modal) {
        return {
            open: function() {
                var tabs = {
                    processes: false,
                    files: false,
                    samples: false,
                    reviews: false
                };

                if (arguments.length === 0) {
                    throw "Invalid arguments to service selectItems:open()";
                }

                for (var i = 0; i < arguments.length; i++) {
                    tabs[arguments[i]] = true;
                }

                var modal = $modal.open({
                    size: 'lg',
                    templateUrl: 'global.services/select-items/select-items.html',
                    controller: 'SelectItemsServiceModalController',
                    controllerAs: 'ctrl',
                    resolve: {
                        showProcesses: function() {
                            return tabs.processes;
                        },

                        showFiles: function() {
                            return tabs.files;
                        },

                        showSamples: function() {
                            return tabs.samples;
                        },

                        showReviews: function() {
                            return tabs.reviews;
                        }
                    }
                });
                return modal.result;
            }
        };
    }

    module.controller('SelectItemsServiceModalController', SelectItemsServiceModalController);
    SelectItemsServiceModalController.$inject = ['$modalInstance', 'showProcesses',
        'showFiles', 'showSamples', 'showReviews', 'projectsService', '$stateParams', 'project'];

    function SelectItemsServiceModalController($modalInstance, showProcesses, showFiles, showSamples,
                                               showReviews, projectsService, $stateParams, project) {
        var ctrl = this;

        ctrl.project = project.get();
        ctrl.tabs = loadTabs();
        ctrl.activeTab = ctrl.tabs[0].name;
        ctrl.setActive = setActive;
        ctrl.isActive = isActive;
        ctrl.ok = ok;
        ctrl.cancel = cancel;
        ctrl.processes = [];
        ctrl.samples = [];

        /////////////////////////

        function setActive(tab) {
            ctrl.activeTab = tab;
        }

        function isActive(tab) {
            return ctrl.activeTab === tab;
        }

        function ok() {
            var selectedProcesses = ctrl.processes.filter(function(p) {
                return p.input || p.output;
            });

            var selectedSamples = ctrl.samples.filter(function(s) {
                return s.selected;
            });

            var selectedFiles = getSelectedFiles();

            $modalInstance.close({
                processes: selectedProcesses,
                samples: selectedSamples,
                files: selectedFiles
            });
        }

        function getSelectedFiles() {
            if (!showFiles) {
                return [];
            }
            var files = [],
                treeModel = new TreeModel(),
                root = treeModel.parse(project.get().files[0]);
            // Walk the tree looking for selected files and adding them to the
            // list of files. Also reset the selected flag so the next time
            // the popup for files is used it doesn't show previously selected
            // items.
            root.walk({strategy: 'pre'}, function(node) {
                if (node.model.data.selected) {
                    node.model.data.selected = false;
                    if (node.model.data._type === 'file') {
                        files.push(node.model.data);
                    }
                }
            });
            return files;
        }

        function cancel() {
            $modalInstance.dismiss('cancel');
        }

        function loadTabs() {
{'fraction_non_alphanumeric': 0.10299328039095908, 'fraction_numerical': 0.0009773976786805131, 'mean_word_length': 1.2064690026954177, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3632948', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1767, 'n_words': 413}