<commit_before>(function () {
    'use strict';

    /**
     * @ngdoc controller
     * @name data-prep.export.controller:ExportCtrl
     * @description Export controller.
     * @requires data-prep.services.preparation.service:PreparationService
     * @requires data-prep.services.recipe.service:RecipeService
     * @requires data-prep.services.utils.service:RestURLs
     * @requires data-prep.services.export.service:ExportService
     */
    function ExportCtrl($timeout, state, PreparationService, RecipeService, RestURLs, ExportService) {
        var vm = this;
        vm.state = state;
        vm.preparationService = PreparationService;
        vm.recipeService = RecipeService;
        vm.exportService = ExportService;

        /**
         * @ngdoc property
         * @name currentExportType
         * @propertyOf data-prep.export.controller:ExportCtrl
         * @description Current export type
         * @type {Object}
         */
        vm.currentExportType = null;

        /**
         * @ngdoc property
         * @name currentExportParameters
         * @propertyOf data-prep.export.controller:ExportCtrl
         * @description Current export parameters model, bound to form inputs
         * @type {Object}
         */
        vm.currentExportParameters = null;

        /**
         * @ngdoc method
         * @name resetCurrentParameters
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Reset current export parameters with the saved one from localStorage
         */
        vm.resetCurrentParameters = function resetCurrentParameters() {
            vm.currentExportParameters = ExportService.getParameters();
            vm.currentExportType = ExportService.getType(vm.currentExportParameters.exportType);
        };

        /**
         * @ngdoc method
         * @name changeTypeAndExport
         * @methodOf data-prep.export.controller:ExportCtrl
         * @param {object} exportType The export type
         * @description Change the export type and launch the export.
         * If the export type has parameters, we init the form and display a modal
         */
        vm.changeTypeAndExport = function (exportType) {
            var parameters = {exportType: exportType.id};
            vm.currentExportType = exportType;
            vm.currentExportParameters = parameters;
            
            if (exportType.parameters) {
                _.forEach(exportType.parameters, function(param) {
                    parameters['exportParameters.' + param.name] = param.defaultValue.value;
                    //hack for fileName as we don't know it with exportTypes parameters
                    //so if empty use the dataset.name
                    if (param.name === 'fileName'){
                        var allParameters = ExportService.getParameters();
                        if (allParameters && allParameters['exportParameters.fileName']){
                            parameters['exportParameters.' + param.name] = allParameters['exportParameters.fileName'];
                        } else {
                            parameters['exportParameters.' + param.name] = vm.state.playground.dataset.name;
                        }
                    }
                });
                vm.showModal = true;
            }
            else {
                ExportService.setParameters(parameters);
                $timeout(vm.export);
            }
        };

        /**
         * @ngdoc method
         * @name saveEditionAndExport
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Save the currently edited export parameters and launch the export
         */
        vm.saveEditionAndExport = function saveEditionAndExport() {
            ExportService.setParameters(vm.currentExportParameters);
            $timeout(vm.export);
        };

        /**
         * @ngdoc method
         * @name export
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Launch the export<commit_msg>[TDP-188] prefer preparation.name as default if any.<commit_after>(function () {
    'use strict';

    /**
     * @ngdoc controller
     * @name data-prep.export.controller:ExportCtrl
     * @description Export controller.
     * @requires data-prep.services.preparation.service:PreparationService
     * @requires data-prep.services.recipe.service:RecipeService
     * @requires data-prep.services.utils.service:RestURLs
     * @requires data-prep.services.export.service:ExportService
     */
    function ExportCtrl($timeout, state, PreparationService, RecipeService, RestURLs, ExportService) {
        var vm = this;
        vm.state = state;
        vm.preparationService = PreparationService;
        vm.recipeService = RecipeService;
        vm.exportService = ExportService;

        /**
         * @ngdoc property
         * @name currentExportType
         * @propertyOf data-prep.export.controller:ExportCtrl
         * @description Current export type
         * @type {Object}
         */
        vm.currentExportType = null;

        /**
         * @ngdoc property
         * @name currentExportParameters
         * @propertyOf data-prep.export.controller:ExportCtrl
         * @description Current export parameters model, bound to form inputs
         * @type {Object}
         */
        vm.currentExportParameters = null;

        /**
         * @ngdoc method
         * @name resetCurrentParameters
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Reset current export parameters with the saved one from localStorage
         */
        vm.resetCurrentParameters = function resetCurrentParameters() {
            vm.currentExportParameters = ExportService.getParameters();
            vm.currentExportType = ExportService.getType(vm.currentExportParameters.exportType);
        };

        /**
         * @ngdoc method
         * @name changeTypeAndExport
         * @methodOf data-prep.export.controller:ExportCtrl
         * @param {object} exportType The export type
         * @description Change the export type and launch the export.
         * If the export type has parameters, we init the form and display a modal
         */
        vm.changeTypeAndExport = function (exportType) {
            var parameters = {exportType: exportType.id};
            vm.currentExportType = exportType;
            vm.currentExportParameters = parameters;
            
            if (exportType.parameters) {
                _.forEach(exportType.parameters, function(param) {
                    parameters['exportParameters.' + param.name] = param.defaultValue.value;
                    //hack for fileName as we don't know it with exportTypes parameters
                    //so if empty use the dataset.name
                    if (param.name === 'fileName'){
                        var allParameters = ExportService.getParameters();
                        if (allParameters && allParameters['exportParameters.fileName']){
                            parameters['exportParameters.' + param.name] = allParameters['exportParameters.fileName'];
                        } else if (vm.state.playground.preparation && vm.state.playground.preparation.name) {
                            parameters['exportParameters.' + param.name] = vm.state.playground.preparation.name;
                        } else {
                            parameters['exportParameters.' + param.name] = vm.state.playground.dataset.name;
                        }
                    }
                });
                vm.showModal = true;
            }
            else {
                ExportService.setParameters(parameters);
                $timeout(vm.export);
            }
        };

        /**
         * @ngdoc method
         * @name saveEditionAndExport
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Save the currently edited export parameters and launch the export
         */
        vm.saveEditionAndExport = function saveEditionAndExport() {
            ExportService.setParameters(vm.currentExportParameters);
            $timeout(vm.export);
        };

        /**
         * @ngdoc method
         * @name export
         * @methodOf data-prep.export.controller:ExportCtrl
         * @description Launch the export
{'fraction_non_alphanumeric': 0.08928571428571429, 'fraction_numerical': 0.0003595397890699904, 'mean_word_length': 1.9066527342389412, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2766087', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1927, 'n_words': 444}