<commit_before>'use strict';

angular.module('ludwig').controller('FormCtrl', function($scope, $http, $state, $stateParams, possibleValues, droitsObtenus, test, keywords, config) {
    $scope.keywords = keywords;
    $scope.possibleValues = _.sortBy(possibleValues, 'shortLabel');
    $scope.test = test;

    $scope.pageTitle = 'Modification du test' + (test.name ? ' « ' + test.name + ' »' : '');

    $scope.submitLabel = 'Enregistrer';

    $scope.test.expectedResults.forEach(function(expectedResult) {
        expectedResult.ref = _.find($scope.possibleValues, { id: expectedResult.code });
        expectedResult.result = droitsObtenus[expectedResult.code];
    });

    $scope.droitSelected = function(expectedResult) {
        expectedResult.result = droitsObtenus[expectedResult.ref.id];
        expectedResult.expectedValue = expectedResult.result;
    };

    $scope.formatDroitValue = function(value) {
        if (_.isNumber(value)) {
            return '' + value + ' €';
        }
        return value ? 'Oui' : 'Non';
    };

    $scope.removeDroit = function(droit) {
        var index = $scope.test.expectedResults.indexOf(droit);
        $scope.test.expectedResults.splice(index, 1);
    };

    $scope.submit = function() {
        $scope.submitting = true;
        $scope.test.expectedResults.forEach(function(droit) {
            droit.code = droit.ref.id;
        });
        var test = _.pick($scope.test, ['_id', 'situation', 'name', 'description', 'expectedResults', 'keywords']);
        $http.put(config.baseApiPath + '/acceptance-tests/' + test._id, test).then(function() {
            $state.go('index.show', { 'testId': test._id });
        });
    };
});<commit_msg>Allow submitting form even if missing reference<commit_after>'use strict';

angular.module('ludwig').controller('FormCtrl', function($scope, $http, $state, $stateParams, possibleValues, droitsObtenus, test, keywords, config) {
    $scope.keywords = keywords;
    $scope.possibleValues = _.sortBy(possibleValues, 'shortLabel');
    $scope.test = test;

    $scope.pageTitle = 'Modification du test' + (test.name ? ' « ' + test.name + ' »' : '');

    $scope.submitLabel = 'Enregistrer';

    $scope.test.expectedResults.forEach(function(expectedResult) {
        expectedResult.ref = _.find($scope.possibleValues, { id: expectedResult.code });
        expectedResult.result = droitsObtenus[expectedResult.code];
    });

    $scope.droitSelected = function(expectedResult) {
        expectedResult.result = droitsObtenus[expectedResult.code];
        expectedResult.expectedValue = expectedResult.result;
    };

    $scope.formatDroitValue = function(value) {
        if (_.isNumber(value)) {
            return '' + value + ' €';
        }
        return value ? 'Oui' : 'Non';
    };

    $scope.removeDroit = function(droit) {
        var index = $scope.test.expectedResults.indexOf(droit);
        $scope.test.expectedResults.splice(index, 1);
    };

    $scope.submit = function() {
        $scope.submitting = true;
        var test = _.pick($scope.test, ['_id', 'situation', 'name', 'description', 'expectedResults', 'keywords']);
        $http.put(config.baseApiPath + '/acceptance-tests/' + test._id, test).then(function() {
            $state.go('index.show', { 'testId': test._id });
        });
    };
});
{'fraction_non_alphanumeric': 0.16129032258064516, 'fraction_numerical': 0.0006029544769369913, 'mean_word_length': 3.1578947368421053, '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': '339188', 'n_tokens_mistral': 1011, 'n_tokens_neox': 987, 'n_words': 169}