<commit_before>'use strict';

/**
 * @ngdoc function
 * @name cortex.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the cortex
 */
angular.module('cortex')
    .controller('NavCtrl', function($q, $state, $uibModal, AnalyzerSrv, NotificationService) {
        this.newAnalysis = function () {

            AnalyzerSrv.list()
                .then(function(analyzers) {
                    var modalInstance = $uibModal.open({
                        animation: true,
                        templateUrl: 'views/analysis.form.html',
                        controller: 'AnalyzerFormCtrl',
                        controllerAs: 'vm',
                        size: 'lg',
                        resolve: {
                            initialData: function () {
                                return {
                                    analyzers: angular.copy(analyzers),
                                    dataTypes: _.keys(AnalyzerSrv.getTypes())
                                };
                            }
                        }
                    });

                    modalInstance.result.then(function (result) {
                        var artifact = _.omit(result, 'ids');

                        return $q.all(_.map(result.ids.split(','), function(analyzerId){
                            artifact.analyzer = {
                                id: analyzerId
                            };

                            return AnalyzerSrv.run(analyzerId, artifact);
                        }));
                    }).then(function (response) {
                        if($state.is('jobs')) {
                            $state.reload();
                        } else {
                            $state.go('jobs');
                        }
                        _.each(response, function(resp) {
                            NotificationService.success(resp.data.analyzerId + ' started successfully on ' + (resp.data.artifact.data || resp.data.artifact.attributes.filename));
                        });
                    });
                });
        };
    })
    .controller('AnalyzersCtrl', function ($state, $uibModal, $q, $log, AnalyzerSrv, NotificationService, analyzers) {
        this.search = {
            description: '',
            dataTypeList: ''
        };

        this.analyzers = analyzers;
        this.datatypes = AnalyzerSrv.getTypes();

        this.run = function (analyzer, dataType) {
            var modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'views/analyzers.form.html',
                controller: 'AnalyzerFormCtrl',
                controllerAs: 'vm',
                size: 'lg',
                resolve: {
                    initialData: function () {
                        return {
                            analyzer: angular.copy(analyzer),
                            dataType: angular.copy(dataType)
                        };
                    }
                }
            });

            modalInstance.result.then(function (result) {
                return AnalyzerSrv.run(result.analyzer.id, result);
            }).then(function (response) {
                $state.go('jobs');
                NotificationService.success(response.data.analyzerId + ' started successfully on ' + response.data.artifact.data);
            });
        };

        this.filterByType = function (type) {
            if (this.search.dataTypeList === type) {
                this.search.dataTypeList = '';
            } else {
                this.search.dataTypeList = type;
            }
        };

    })
    .controller('AnalyzerFormCtrl', function ($uibModalInstance, Tlps, initialData) {
        this.initialData = initialData;
        this.tlps = Tlps;
        this.formData = {
            analyzer: this.initialData.analyzer,
            tlp: Tlps[2],
            dataType: this.initialData.dataType
        };

        this.isFile = function () {
            return this.formData.dataType === 'file';
        };<commit_msg>#39 Handle analyzer launch fail<commit_after>'use strict';

/**
 * @ngdoc function
 * @name cortex.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the cortex
 */
angular.module('cortex')
    .controller('NavCtrl', function($q, $state, $uibModal, AnalyzerSrv, NotificationService) {
        this.newAnalysis = function () {

            AnalyzerSrv.list()
                .then(function(analyzers) {
                    var modalInstance = $uibModal.open({
                        animation: true,
                        templateUrl: 'views/analysis.form.html',
                        controller: 'AnalyzerFormCtrl',
                        controllerAs: 'vm',
                        size: 'lg',
                        resolve: {
                            initialData: function () {
                                return {
                                    analyzers: angular.copy(analyzers),
                                    dataTypes: _.keys(AnalyzerSrv.getTypes())
                                };
                            }
                        }
                    });

                    modalInstance.result.then(function (result) {
                        var artifact = _.omit(result, 'ids');

                        return $q.all(_.map(result.ids.split(','), function(analyzerId){
                            artifact.analyzer = {
                                id: analyzerId
                            };

                            return AnalyzerSrv.run(analyzerId, artifact);
                        }));
                    }).then(function (response) {
                        if($state.is('jobs')) {
                            $state.reload();
                        } else {
                            $state.go('jobs');
                        }
                        _.each(response, function(resp) {
                            NotificationService.success(resp.data.analyzerId + ' started successfully on ' + (resp.data.artifact.data || resp.data.artifact.attributes.filename));
                        });
                    }).catch(function(err) {
                        if(err != 'cancel') {
                            NotificationService.error(('An error occurred: ' + err.statusText) || 'An unexpected error occurred');
                        }
                    });
                });
        };
    })
    .controller('AnalyzersCtrl', function ($state, $uibModal, $q, $log, AnalyzerSrv, NotificationService, analyzers) {
        this.search = {
            description: '',
            dataTypeList: ''
        };

        this.analyzers = analyzers;
        this.datatypes = AnalyzerSrv.getTypes();

        this.run = function (analyzer, dataType) {
            var modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'views/analyzers.form.html',
                controller: 'AnalyzerFormCtrl',
                controllerAs: 'vm',
                size: 'lg',
                resolve: {
                    initialData: function () {
                        return {
                            analyzer: angular.copy(analyzer),
                            dataType: angular.copy(dataType)
                        };
                    }
                }
            });

            modalInstance.result.then(function (result) {
                return AnalyzerSrv.run(result.analyzer.id, result);
            }).then(function (response) {
                $state.go('jobs');
                NotificationService.success(response.data.analyzerId + ' started successfully on ' + response.data.artifact.data);
            }).catch(function(err) {
                if(err != 'cancel') {
                    NotificationService.error(('An error occurred: ' + err.statusText) || 'An unexpected error occurred');
                }
            });
        };

        this.filterByType = function (type) {
            if (this.search.dataTypeList === type) {
                this.search.dataTypeList = '';
            } else {
                this.search.dataTypeList = type;
            }
        };

    })
    .controller('AnalyzerFormCtrl', function ($uibModalInstance, Tlps, initialData) {
        this.initialData = initialData;
        this.tlps = Tlps;
        this.formData = {
            analyzer: this.initialData.analyzer,
            tlp: Tlps[2],
            dataType: this.initialData.dataType
        };

        this.isFile = function () {
            return this.formData.dataType === 'file';
        };
{'fraction_non_alphanumeric': 0.10934231931210783, 'fraction_numerical': 0.00046479200557750407, 'mean_word_length': 1.150137396952286, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3077383', 'n_tokens_mistral': 2139, 'n_tokens_neox': 1978, 'n_words': 342}