<commit_before>/**
 * Controller for cover page (index template).
 */

app.controller('mainCtrl', ['$scope', '$routeParams', 'segmentio', '$rootScope', '$timeout', 'orderByFilter', 'miaThumbnailAdapter', '$sce', 'resolvedNotes', 'initIsotope', '$location',
  function($scope, $routeParams, segmentio, $rootScope, $timeout, orderByFilter, thumbnailAdapter, $sce, notes, initIsotope, $location) {
    var dc = $rootScope.defaultCluster
    if(dc && dc !== 'highlights') $location.path('/clusters/'+$rootScope.defaultCluster)

    var data = $scope.data = notes
    $rootScope.loaded = false

    var cluster = $rootScope.defaultCluster || $routeParams.cluster || 'highlights'
    var clusterObjectIds = data.clusters[cluster.replace(/^(g)?(\d+)/i, '$1$2')]
    if(clusterObjectIds) {
      $scope.cluster = $rootScope.defaultCluster = cluster
      $scope.isGallery = cluster.match(/^G\d/i)
      $scope.gallery = $scope.cluster.replace('G', '')
      $rootScope.showingCluster = $scope.showingCluster = 
        (typeof $rootScope.showingCluster === 'undefined') ? true : $rootScope.showingCluster
      if(!$rootScope.clusterObjects) {
        $scope.clusterObjects = clusterObjectIds.map(function(objectId) {
          var isStory = objectId.match && objectId.match(/stories\/(\d+)/)
          if(isStory) return data.stories[isStory[1]]
          return data.objects[objectId]
        }).filter(function(o) { return o })
        var startPanels = addPanelsToClusterObjects()
        $rootScope.clusterObjects = $scope.clusterObjects = orderByFilter($scope.clusterObjects, random)
        startPanels.map(function(p) { $scope.clusterObjects.unshift(p) })

        $rootScope.otherObjects = $scope.otherObjects = $rootScope.otherObjects = loadAllObjects()
      } else {
        $scope.clusterObjects = $rootScope.clusterObjects
        $scope.otherObjects = $rootScope.otherObjects
      }
    } else { // not a valid cluster
      $location.path('/')
    }

    $scope.toggleSeeAll = function() {
      var container = $('.cover-wrapper')[0]
      if($scope.showingCluster) $timeout(function() { container.scrollLeft = container.scrollWidth-window.innerWidth }, 0)
      $scope.loading = true
      $rootScope.showingCluster = $scope.showingCluster = !$scope.showingCluster

      $timeout(function() {
        $timeout(initIsotope, 0)
        $scope.loading = false
      }, 0)
    }

    // Maintain the random order of the cluster objects, and add all the others
    // in random order. Then any 'end' panels.
    function loadAllObjects() {
      var c = $scope.clusterObjects
      var others = []

      angular.forEach(data.objects, function(o) {
        (c.indexOf(o) > -1) || others.push(o)
      })
      others = orderByFilter(others, random)

      angular.forEach(data.panels, function(p) {
        if(c.indexOf(p) == -1 && p.position == 'end') others.push(p)
      })
      
      return others
      return angular.copy(c).map(function(o) {
        // angular.copy and $sce.trust don't work together. this prevents an sce.unsafe
        if(o.recordType == 'panel') o.trustedContent = $sce.trustAsHtml(o.content)
        return o
      }).concat(others)
    }

    // Add the panels that should be randomized to `clusterObjects` and
    // return the panels that need to be at the beginning so they can be
    // `unshifted` after randomization happens
    // TODO: should panels go into the cluster objects or the other objects?
    function addPanelsToClusterObjects() {
      var panels = []
      angular.forEach(data.panels, function(p) { panels.push(p) })
      panels.filter(function(p) { return p.position == 'random' })
        .map(function(p) { $scope.clusterObjects.push(p) })<commit_msg>(temporarily) hide new TDX japan<commit_after>/**
 * Controller for cover page (index template).
 */

app.controller('mainCtrl', ['$scope', '$routeParams', 'segmentio', '$rootScope', '$timeout', 'orderByFilter', 'miaThumbnailAdapter', '$sce', 'resolvedNotes', 'initIsotope', '$location',
  function($scope, $routeParams, segmentio, $rootScope, $timeout, orderByFilter, thumbnailAdapter, $sce, notes, initIsotope, $location) {
    var dc = $rootScope.defaultCluster
    if(dc && dc !== 'highlights') $location.path('/clusters/'+$rootScope.defaultCluster)

    var data = $scope.data = notes
    $rootScope.loaded = false
    var japanObjects = [122167, 122102, 122502, 122505, 3369, 122189, 122166, 122492, 122113, 122115, 6612]

    var cluster = $rootScope.defaultCluster || $routeParams.cluster || 'highlights'
    var clusterObjectIds = data.clusters[cluster.replace(/^(g)?(\d+)/i, '$1$2')]
    if(clusterObjectIds) {
      $scope.cluster = $rootScope.defaultCluster = cluster
      $scope.isGallery = cluster.match(/^G\d/i)
      $scope.gallery = $scope.cluster.replace('G', '')
      $rootScope.showingCluster = $scope.showingCluster = 
        (typeof $rootScope.showingCluster === 'undefined') ? true : $rootScope.showingCluster
      if(!$rootScope.clusterObjects) {
        $scope.clusterObjects = clusterObjectIds.map(function(objectId) {
          var isStory = objectId.match && objectId.match(/stories\/(\d+)/)
          if(isStory) return data.stories[isStory[1]]
          return data.objects[objectId]
        }).filter(function(o) { return o })
        var startPanels = addPanelsToClusterObjects()
        $rootScope.clusterObjects = $scope.clusterObjects = orderByFilter($scope.clusterObjects, random)
        startPanels.map(function(p) { $scope.clusterObjects.unshift(p) })

        $rootScope.otherObjects = $scope.otherObjects = $rootScope.otherObjects = loadAllObjects()
      } else {
        $scope.clusterObjects = $rootScope.clusterObjects
        $scope.otherObjects = $rootScope.otherObjects
      }
    } else { // not a valid cluster
      $location.path('/')
    }

    $scope.toggleSeeAll = function() {
      var container = $('.cover-wrapper')[0]
      if($scope.showingCluster) $timeout(function() { container.scrollLeft = container.scrollWidth-window.innerWidth }, 0)
      $scope.loading = true
      $rootScope.showingCluster = $scope.showingCluster = !$scope.showingCluster

      $timeout(function() {
        $timeout(initIsotope, 0)
        $scope.loading = false
      }, 0)
    }

    // Maintain the random order of the cluster objects, and add all the others
    // in random order. Then any 'end' panels.
    function loadAllObjects() {
      var c = $scope.clusterObjects
      var others = []

      angular.forEach(data.objects, function(o) {
        if(japanObjects.indexOf(parseInt(o.id)) > -1) return console.info('rejecting', o.id);
        (c.indexOf(o) > -1) || others.push(o)
      })
      others = orderByFilter(others, random)

      angular.forEach(data.panels, function(p) {
        if(c.indexOf(p) == -1 && p.position == 'end') others.push(p)
      })
      
      return others
      return angular.copy(c).map(function(o) {
        // angular.copy and $sce.trust don't work together. this prevents an sce.unsafe
        if(o.recordType == 'panel') o.trustedContent = $sce.trustAsHtml(o.content)
        return o
      }).concat(others)
    }

    // Add the panels that should be randomized to `clusterObjects` and
    // return the panels that need to be at the beginning so they can be
    // `unshifted` after randomization happens
    // TODO: should panels go into the cluster objects or the other objects?
    function addPanelsToClusterObjects() {
      var panels = []
      angular.forEach(data.panels, function(p) { panels.push(p) })
      panels.filter(function(p) { return p.position == 'random' })
        .map(function(p) { $scope.clusterObjects.push(p) })
{'fraction_non_alphanumeric': 0.1409904612570234, 'fraction_numerical': 0.010584084672677381, 'mean_word_length': 3.2008781558726676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5660095', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2270, 'n_words': 508}