<commit_before>'use strict';

angular.module('impactApp').directive('numeroSecu', function() {
  return {
    require: 'ngModel',
    link: function(scope, elem, attr, ngModel) {
      const isValid = (value) => {
        if (!value) {
          return true;
        }

        const valueKey = value.slice(-2);
        const valueRest = value.slice(0, -2);
        const computedKey = 97 - valueRest % 97;

        return parseInt(valueKey) === computedKey;
      };

      //For DOM -> model validation
      ngModel.$parsers.unshift((value) => {
        const valid = isValid(value);
        ngModel.$setValidity('numero-secu', valid);
        return value;
      });

      //For model -> DOM validation
      ngModel.$formatters.unshift((value) => {
        const valid = isValid(value);
        ngModel.$setValidity('numero-secu', valid);
        return value;
      });
    }
  };
});
<commit_msg>suppression des espace du numero de secu pour la validation (#341)<commit_after>'use strict';

angular.module('impactApp').directive('numeroSecu', function() {
  return {
    require: 'ngModel',
    link: function(scope, elem, attr, ngModel) {
      const isValid = (value) => {
        if (!value) {
          return true;
        }

        value = value.replace(/ /g, '');

        const valueKey = value.slice(-2);
        const valueRest = value.slice(0, -2);
        const computedKey = 97 - valueRest % 97;

        console.log('valueKey : ' + valueKey);
        console.log('valueRest : ' + valueRest);
        console.log('computedKey : ' + computedKey);

        return parseInt(valueKey) === computedKey;
      };

      //For DOM -> model validation
      ngModel.$parsers.unshift((value) => {
        const valid = isValid(value);
        ngModel.$setValidity('numero-secu', valid);
        return value;
      });

      //For model -> DOM validation
      ngModel.$formatters.unshift((value) => {
        const valid = isValid(value);
        ngModel.$setValidity('numero-secu', valid);
        return value;
      });
    }
  };
});

{'fraction_non_alphanumeric': 0.14856307842182173, 'fraction_numerical': 0.008280565026790063, 'mean_word_length': 2.234645669291339, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3628156', 'n_tokens_mistral': 625, 'n_tokens_neox': 603, 'n_words': 135}