<commit_before>'use strict';

angular.module('arethusaTranslateGuiApp').directive('trsl', [
  '$timeout',
  function($timeout) {
    var MAIN_LANGUAGE = 'en';
    var DIRTY = 'dirty-bg-dark';
    var CLEAN = 'clean-bg-dark';

    function getEventName(main) {
      return main ? 'mainChange' : 'trslChange';
    }

    function isMain(lang) {
      return MAIN_LANGUAGE === lang;
    }

    return {
      restrict: 'A',
      link: function(scope) {
        var main = isMain(scope.trsl.lang);
        var eventName = getEventName(main);

        function switchClassesAndNotify(newVal, oldVal) {
          scope.statusClass = newVal ? DIRTY : CLEAN;
          scope.toggleIcon = newVal ? 'check' : 'remove';
          if (newVal !== oldVal) {
            scope.$emit(eventName, scope.trsl);
          }
        }

        function changeStatus(bool) {
          scope.trsl.dirty = bool;
        }

        function setClean() {
          changeStatus(false);
        }

        function setDirty() {
          changeStatus(true);
        }

        scope.toggleStatus = function() {
          if (scope.trsl.dirty) {
            setClean();
          } else {
            setDirty();
          }
        };

        var timer;
        scope.trackChange = function() {
          if (timer) $timeout.cancel(timer);
          timer = $timeout(setClean, 1000);
        };

        if (main) {
          if (scope.trsl.dirty) setClean();
          scope.statusClass = '';
        } else {
          scope.$watch('trsl.dirty', switchClassesAndNotify);
          scope.$on('mainDirty', setDirty);
        }
      },
      templateUrl: 'app/i18n/trsl.directive.html'
    };
  }
]);


<commit_msg>Fix trsl directive<commit_after>'use strict';

angular.module('arethusaTranslateGuiApp').directive('trsl', [
  '$timeout',
  function($timeout) {
    var MAIN_LANGUAGE = 'en';
    var DIRTY = 'dirty-bg-dark';
    var CLEAN = 'clean-bg-dark';

    function getEventName(main) {
      return main ? 'mainChange' : 'trslChange';
    }

    function isMain(lang) {
      return MAIN_LANGUAGE === lang;
    }

    return {
      restrict: 'A',
      link: function(scope) {
        var main = isMain(scope.trsl.lang);
        var eventName = getEventName(main);

        function switchClasses(newVal) {
          scope.statusClass = newVal ? DIRTY : CLEAN;
          scope.toggleIcon = newVal ? 'check' : 'remove';
        }

        function changeStatus(bool) {
          var old = scope.trsl.dirty;
          if (main || old !== bool) {
            scope.trsl.dirty = bool;
            scope.$emit(eventName, scope.trsl);
          }
        }

        function setClean() {
          changeStatus(false);
        }

        function setDirty() {
          changeStatus(true);
        }

        scope.toggleStatus = function() {
          if (scope.trsl.dirty) {
            setClean();
          } else {
            setDirty();
          }
        };

        var timer;
        scope.trackChange = function() {
          if (timer) $timeout.cancel(timer);
          timer = $timeout(setClean, 1000);
        };

        if (main) {
          if (scope.trsl.dirty) {
            scope.trsl.dirty = false;
            scope.$emit('trslChange', scope.trsl);
          }
          scope.statusClass = '';
        } else {
          scope.$watch('trsl.dirty', switchClasses);
          scope.$on('mainDirty', setDirty);
        }
      },
      templateUrl: 'app/i18n/trsl.directive.html'
    };
  }
]);



{'fraction_non_alphanumeric': 0.13419170243204578, 'fraction_numerical': 0.0034334763948497852, 'mean_word_length': 1.73125, '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': '3497110', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1050, 'n_words': 192}