<commit_before>'use strict';

var yaocho = angular.module('yaocho');

yaocho.controller('DocumentCtrl', ['$rootScope', '$scope', '$routeParams', 'KitsuneCorpus',
function($rootScope, $scope, $routeParams, KitsuneCorpus) {
  $scope.document = KitsuneCorpus.getDoc($routeParams.slug);
  $rootScope.ui.current = $scope.document;
}]);

yaocho.controller('TopicBrowserCtrl', ['$rootScope', '$scope', '$routeParams', 'KitsuneCorpus',
function($rootScope, $scope, $routeParams, KitsuneCorpus) {
  if (!$routeParams.topic) {
    $rootScope.ui.backHidden = true;
  }

  $scope.topic = KitsuneCorpus.getTopic($routeParams.topic);
  $scope.subtopics = KitsuneCorpus.getSubTopics($routeParams.topic);
  $scope.documents = KitsuneCorpus.getTopicDocs($routeParams.topic);

  $rootScope.ui.current = $scope.topic;
}]);

yaocho.controller('CacheDownloadCtrl', ['$rootScope', '$scope', '$location', 'Kitsune',
'KitsuneCorpus', 'KStorage', 'cacheTopic',
function($rootScope, $scope, $location, Kitsune, KitsuneCorpus, KStorage, cacheTopic) {
  if ($location.path() === "/") {
    // Minimum cached docs to not display caching suggestion.
    var minCached = 5;

    $scope.update = function() {
      $scope.showCacheUpdate = false;
      $rootScope.loading = true;

      var productSlug = $rootScope.settings.product.slug;
      KStorage.fuzzySearchObjects('topic:')
      .then(function(topics) {
        return Promise.all(topics.map(cacheTopic));
      })
      .then(function() {
          var finishMsg = gettext("Documents finished downloading.");
          $rootScope.loading = false;
          $rootScope.$emit('flash', finishMsg);
      });
    }

    $scope.hideCacheUpdate = function() {
        $scope.showCacheUpdate = false;
    }

    KStorage.numObjectsExist('document', minCached)
    .then(function(exists) {
      $scope.confirmMessage = gettext("Download documents for offline use?");
      $scope.yesMsg = gettext("Yes");
      $scope.noMsg = gettext("No");
      if (!exists) {
        $scope.showCacheUpdate = true;
      }
    });
  }
}]);<commit_msg>Counts for cached documents are now accurate.<commit_after>'use strict';

var yaocho = angular.module('yaocho');

yaocho.controller('DocumentCtrl', ['$rootScope', '$scope', '$routeParams', 'KitsuneCorpus',
function($rootScope, $scope, $routeParams, KitsuneCorpus) {
  $scope.document = KitsuneCorpus.getDoc($routeParams.slug);
  $rootScope.ui.current = $scope.document;
}]);

yaocho.controller('TopicBrowserCtrl', ['$rootScope', '$scope', '$routeParams', 'KitsuneCorpus',
function($rootScope, $scope, $routeParams, KitsuneCorpus) {
  if (!$routeParams.topic) {
    $rootScope.ui.backHidden = true;
  }

  $scope.topic = KitsuneCorpus.getTopic($routeParams.topic);
  $scope.subtopics = KitsuneCorpus.getSubTopics($routeParams.topic);
  $scope.documents = KitsuneCorpus.getTopicDocs($routeParams.topic);

  $rootScope.ui.current = $scope.topic;
}]);

yaocho.controller('CacheDownloadCtrl', ['$rootScope', '$scope', '$location', 'Kitsune',
'KitsuneCorpus', 'KStorage', 'cacheTopic',
function($rootScope, $scope, $location, Kitsune, KitsuneCorpus, KStorage, cacheTopic) {
  if ($location.path() === "/") {
    // Minimum cached docs to not display caching suggestion.
    var minCached = 5;

    $scope.update = function() {
      $scope.showCacheUpdate = false;
      $rootScope.loading = true;

      var productSlug = $rootScope.settings.product.slug;
      KStorage.fuzzySearchObjects('topic:')
      .then(function(topics) {
        return Promise.all(topics.map(cacheTopic));
      })
      .then(function() {
          var finishMsg = gettext("Documents finished downloading.");
          $rootScope.loading = false;
          $rootScope.$emit('flash', finishMsg);
      });
    }

    $scope.hideCacheUpdate = function() {
        $scope.showCacheUpdate = false;
    }

    KStorage.numObjectsExist('document:', minCached)
    .then(function(exists) {
      $scope.confirmMessage = gettext("Download documents for offline use?");
      $scope.yesMsg = gettext("Yes");
      $scope.noMsg = gettext("No");
      if (!exists) {
        $scope.showCacheUpdate = true;
      }
    });
  }
}]);
{'fraction_non_alphanumeric': 0.16237051312936643, 'fraction_numerical': 0.000481811611659841, 'mean_word_length': 4.0144927536231885, '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': '472573', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1316, 'n_words': 228}