<commit_before>export default function(ngapp, xelib, fileHelpers) {
    ngapp.directive('saveModal', function () {
        return {
            restrict: 'E',
            templateUrl: 'directives/saveModal.html',
            controller: 'saveModalController',
            scope: false
        }
    });

    ngapp.controller('saveModalController', function($scope, $timeout) {
        $scope.message = 'Saving data';
        $scope.detailedMessage = '';
        $scope.pluginsToSave = $scope.plugins.filter(function(plugin) {
            return plugin.hasOwnProperty('errors');
        });
        $scope.total = $scope.pluginsToSave.length;

        var alertException = function(callback) {
            try {
                callback();
            } catch (x) {
                alert(x);
            }
        };

        $scope.save = function() {
            $timeout(function() {
                if ($scope.pluginsToSave.length > 0) {
                    $scope.applyErrorResolutions();
                    $scope.savePlugins();
                    $scope.saveCache();
                }
                $scope.finalize();
            }, 50);
        };

        $scope.applyErrorResolutions = function() {
            $scope.$applyAsync(function() {
                $scope.message = 'Applying error resolutions';
            });
            $scope.pluginsToSave.forEach(function(plugin, index) {
                $scope.detailedMessage = `${plugin.filename} (${index}/${$scope.total})`;
                plugin.errors.forEach(function(error) {
                    if (error.resolution && error.resolution.hasOwnProperty('execute')) {
                        alertException(function() {
                            error.resolution.execute(error);
                        });
                    }
                });
            });
        };

        $scope.savePlugins = function() {
            $scope.$applyAsync(function() {
                $scope.message = 'Saving plugins';
            });
            $scope.pluginsToSave.forEach(function(plugin, index) {
                $scope.detailedMessage = `${plugin.filename} (${index}/${$scope.total})`;
                alertException(function() {
                    xelib.SaveFile(plugin._id);
                });
            });
        };

        var buildCache = function() {
            var cache = [];
            $scope.pluginsToSave.forEach(function(plugin, index) {<commit_msg>now saving plugins only when errors have been resolved in them<commit_after>export default function(ngapp, xelib, fileHelpers) {
    ngapp.directive('saveModal', function () {
        return {
            restrict: 'E',
            templateUrl: 'directives/saveModal.html',
            controller: 'saveModalController',
            scope: false
        }
    });

    ngapp.controller('saveModalController', function($scope, $timeout) {
        $scope.message = 'Saving data';
        $scope.detailedMessage = '';
        $scope.pluginsToSave = $scope.plugins.filter(function(plugin) {
            return plugin.hasOwnProperty('errors');
        });
        $scope.total = $scope.pluginsToSave.length;

        var alertException = function(callback) {
            try {
                callback();
            } catch (x) {
                alert(x);
            }
        };

        $scope.save = function() {
            $timeout(function() {
                if ($scope.pluginsToSave.length > 0) {
                    $scope.applyErrorResolutions();
                    $scope.savePlugins();
                    $scope.saveCache();
                }
                $scope.finalize();
            }, 50);
        };

        $scope.applyErrorResolutions = function() {
            $scope.$applyAsync(function() {
                $scope.message = 'Applying error resolutions';
            });
            $scope.pluginsToSave.forEach(function(plugin, index) {
                $scope.detailedMessage = `${plugin.filename} (${index}/${$scope.total})`;
                plugin.errors.forEach(function(error) {
                    if (error.resolution && error.resolution.hasOwnProperty('execute')) {
                        if (!plugin.errorsResolved) plugin.errorsResolved = true;
                        alertException(function() {
                            error.resolution.execute(error);
                        });
                    }
                });
            });
        };

        $scope.savePlugins = function() {
            $scope.$applyAsync(function() {
                $scope.message = 'Saving plugins';
            });
            $scope.pluginsToSave.forEach(function(plugin, index) {
                $scope.detailedMessage = `${plugin.filename} (${index}/${$scope.total})`;
                if (!plugin.errorsResolved) return;
                alertException(function() {
                    xelib.SaveFile(plugin._id);
                });
            });
        };

        var buildCache = function() {
            var cache = [];
            $scope.pluginsToSave.forEach(function(plugin, index) {
{'fraction_non_alphanumeric': 0.12941408561846518, 'fraction_numerical': 0.0011836654172420597, 'mean_word_length': 1.4950787401574803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '636408', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1222, 'n_words': 189}