<commit_before>'use strict';

angular.module('semdomtrans.edit', ['jsonRpc', 'ui.bootstrap', 'bellows.services',  'ngAnimate', 'palaso.ui.notice', 'semdomtrans.services', 'palaso.ui.sd.term', 'palaso.ui.sd.questions', 'palaso.ui.scroll', 'palaso.ui.typeahead', 'palaso.ui.sd.ws'])
// DBE controller
.controller('editCtrl', ['$scope', '$state', '$stateParams', 'semdomtransEditService', 'semdomtransEditorDataService', 'sessionService', 'modalService', 'silNoticeService', '$rootScope', '$filter', '$timeout',
function($scope, $state, $stateParams, semdomEditApi, editorDataService, sessionService, modal, notice, $rootScope, $filter, $timeout) {

  $scope.selectedTab = 0;
  $scope.control = $scope;
  $scope.currentQuestionPos = 0;
  $scope.tabDisplay = {"val": '0'};
  $scope.state = "edit";
  $scope.filteredByDepthItems = [];
  $scope.filteredByDepthItemsDict = {};
  $scope.displayedItems = [];
  $scope.selectedDepth = 1;
  $scope.searchText = "";
  $scope.isEditingWorkingSet = false;
  $scope.subDomain = "1";
  $scope.hideTranslated = false;
  
  var api = semdomEditApi;
 
  
  $scope.$watch("subDomain", function(newVal) {
    $scope.reloadItems($scope.selectedDepth);
  });
  
  $scope.selectSubDomain = function(subDomain) {
    $scope.subDomain = subDomain;
  }
  
  $scope.reloadItems = function reloadItems(depth, delay) {
     if (delay == undefined) {
       delay = 0;
     }
      var query = $scope.selectedText;
      $timeout(function() {
            if (query != $scope.selectedText)
              return;
            
            $scope.filteredByDepthItems = [];
            var addedToFiltered = {};
            
            // get all actually included items in
            for (var i in $scope.itemsTree) {
              var node = $scope.itemsTree[i];
              var item = node.content;
              if (isIncluded(item.key) && item.key[0] == $scope.subDomain) {
                if (checkDepth(item.key)) {
                  $scope.filteredByDepthItems.push(item);
                }
              }              
            }
            
            // apply filter       
            $scope.filteredByDepthItems = $filter('filter')($scope.filteredByDepthItems, $scope.searchText);
            
            // check off that items have been added (to avoid duplicates in next step)
            for (var i in $scope.filteredByDepthItems) {
              var item = $scope.filteredByDepthItems[i];
              addedToFiltered[item.key] = true;
            }
            
            // add ancestors of included items
            for (var i in $scope.filteredByDepthItems) {
              var node = $scope.itemsTree[$scope.filteredByDepthItems[i].key];
              var item = node.content;      
              if (isIncluded(item.key) && item.key[0] == $scope.subDomain) {
                while(node.parent != '') {
                  if (checkDepth(node.parent) && (angular.isUndefined(addedToFiltered[node.parent]) || !addedToFiltered[node.parent])) {
                    $scope.filteredByDepthItems.push($scope.itemsTree[node.parent].content);
                    addedToFiltered[node.parent] = true;
                  }
                  
                  node = $scope.itemsTree[node.parent];
                }
              }
            }
            
            
            $scope.filteredByDepthItems.sort(function(a, b) {
              if (a.key < b.key) {
                return -1;
              } else {
                return 1;
              }
            });
            
          
            
            $scope.displayedItems = $scope.filteredByDepthItems;
            if (!$scope.$$phase) {
              $scope.$apply()      
            }
          }, delay);
  }
  /*
   * Determines if a semdom item is completely translated
   */
  
  function isItemTranslatedCompletely(item) {
    var translated = true;
    translated = translated && (item.name.status == 0);
    translated = translated && (item.description.status == 0);
    for (var i = 0; i < item.searchKeys.length; i++) {
      translated = translated && (item.searchKeys[i].status == 0);
    }
    
    for (var i = 0; i < item.questions.length; i++) {
      translated = translated && (item.questions[i].question.status == 0);
      translated = translated && (item.questions[i].terms.status == 0);
    }
    
    return translated;
  }
  
  $scope.$watch('selectedDepth', function(newVal, oldVal) {
    if (oldVal != newVal) {
      var depth = newVal;
      $timeout(function() {
        if (depth == $scope.selectedDepth) {
            $scope.reloadItems(newVal);
        }
      }, 500);
    }<commit_msg>* Bug fix: use correct status to determine if field is translated or not (4 instead of 0)<commit_after>'use strict';

angular.module('semdomtrans.edit', ['jsonRpc', 'ui.bootstrap', 'bellows.services',  'ngAnimate', 'palaso.ui.notice', 'semdomtrans.services', 'palaso.ui.sd.term', 'palaso.ui.sd.questions', 'palaso.ui.scroll', 'palaso.ui.typeahead', 'palaso.ui.sd.ws'])
// DBE controller
.controller('editCtrl', ['$scope', '$state', '$stateParams', 'semdomtransEditService', 'semdomtransEditorDataService', 'sessionService', 'modalService', 'silNoticeService', '$rootScope', '$filter', '$timeout',
function($scope, $state, $stateParams, semdomEditApi, editorDataService, sessionService, modal, notice, $rootScope, $filter, $timeout) {

  $scope.selectedTab = 0;
  $scope.control = $scope;
  $scope.currentQuestionPos = 0;
  $scope.tabDisplay = {"val": '0'};
  $scope.state = "edit";
  $scope.filteredByDepthItems = [];
  $scope.filteredByDepthItemsDict = {};
  $scope.displayedItems = [];
  $scope.selectedDepth = 1;
  $scope.searchText = "";
  $scope.isEditingWorkingSet = false;
  $scope.subDomain = "1";
  $scope.hideTranslated = false;
  
  var api = semdomEditApi;
 
  
  $scope.$watch("subDomain", function(newVal) {
    $scope.reloadItems($scope.selectedDepth);
  });
  
  $scope.selectSubDomain = function(subDomain) {
    $scope.subDomain = subDomain;
  }
  
  $scope.reloadItems = function reloadItems(depth, delay) {
     if (delay == undefined) {
       delay = 0;
     }
      var query = $scope.selectedText;
      $timeout(function() {
            if (query != $scope.selectedText)
              return;
            
            $scope.filteredByDepthItems = [];
            var addedToFiltered = {};
            
            // get all actually included items in
            for (var i in $scope.itemsTree) {
              var node = $scope.itemsTree[i];
              var item = node.content;
              if (isIncluded(item.key) && item.key[0] == $scope.subDomain) {
                if (checkDepth(item.key)) {
                  $scope.filteredByDepthItems.push(item);
                }
              }              
            }
            
            // apply filter       
            $scope.filteredByDepthItems = $filter('filter')($scope.filteredByDepthItems, $scope.searchText);
            
            // check off that items have been added (to avoid duplicates in next step)
            for (var i in $scope.filteredByDepthItems) {
              var item = $scope.filteredByDepthItems[i];
              addedToFiltered[item.key] = true;
            }
            
            // add ancestors of included items
            for (var i in $scope.filteredByDepthItems) {
              var node = $scope.itemsTree[$scope.filteredByDepthItems[i].key];
              var item = node.content;      
              if (isIncluded(item.key) && item.key[0] == $scope.subDomain) {
                while(node.parent != '') {
                  if (checkDepth(node.parent) && (angular.isUndefined(addedToFiltered[node.parent]) || !addedToFiltered[node.parent])) {
                    $scope.filteredByDepthItems.push($scope.itemsTree[node.parent].content);
                    addedToFiltered[node.parent] = true;
                  }
                  
                  node = $scope.itemsTree[node.parent];
                }
              }
            }
            
            
            $scope.filteredByDepthItems.sort(function(a, b) {
              if (a.key < b.key) {
                return -1;
              } else {
                return 1;
              }
            });           
            
            $scope.displayedItems = $scope.filteredByDepthItems;
            if (!$scope.$$phase) {
              $scope.$apply()      
            }
          }, delay);
  }
  /*
   * Determines if a semdom item is completely translated
   */
  
  function isItemTranslatedCompletely(item) {
    var translated = true;
    translated = translated && (item.name.status == 4);
    translated = translated && (item.description.status == 4);
    for (var i = 0; i < item.searchKeys.length; i++) {
      translated = translated && (item.searchKeys[i].status == 4);
    }
    
    for (var i = 0; i < item.questions.length; i++) {
      translated = translated && (item.questions[i].question.status == 4);
      translated = translated && (item.questions[i].terms.status == 4);
    }
    
    return translated;
  }
  
  $scope.$watch('selectedDepth', function(newVal, oldVal) {
    if (oldVal != newVal) {
      var depth = newVal;
      $timeout(function() {
        if (depth == $scope.selectedDepth) {
            $scope.reloadItems(newVal);
        }
      }, 500);
    }
{'fraction_non_alphanumeric': 0.1373032023133769, 'fraction_numerical': 0.004498232837099711, 'mean_word_length': 1.982433727243692, 'pattern_counts': {'":': 2, '<': 9, '<?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': '7554825', 'n_tokens_mistral': 2787, 'n_tokens_neox': 2663, 'n_words': 525}