<commit_before>import angular from 'angular';

angular.module('previewController', ['route-segment', 'fileListService']).

controller('PreviewController', ['$scope', '$routeSegment', 'Alert', 'File', 'FileList', function($scope, $routeSegment, Alert, File, FileList) {
  var vm = this;

  vm.set_file_data = file => {
    $scope.file = file;
    $scope.url = '/filesystem/' + file.id + '/download';
  };

  $scope.$routeSegment = $routeSegment;
  $scope.id = $routeSegment.$routeParams.id;
  if ($scope.id !== undefined) {
    // Try to get file from the file list first, to avoid pinging the server.
    var file = FileList.get($scope.id);
    if (file) {
      vm.set_file_data(file);
    } else {
      // If the data isn't available, contact the server to fetch file info;
      // it may not have been loaded.
      var on_failure = error => {
        Alert.alerts.push({
          type: 'danger',
          message: 'Unable to retrieve metadata for file with UUID ' + $scope.id,
        });
      };
      File.get($scope.id).then(file => {
        vm.set_file_data(file);
      }, on_failure);
    }
  }<commit_msg>Preview: replace FileList selection with SelectedFiles<commit_after>import angular from 'angular';

angular.module('previewController', ['route-segment', 'selectedFilesService']).

controller('PreviewController', ['$scope', '$routeSegment', 'Alert', 'File', 'SelectedFiles', function($scope, $routeSegment, Alert, File, SelectedFiles) {
  var vm = this;

  vm.set_file_data = file => {
    $scope.file = file;
    $scope.url = '/filesystem/' + file.id + '/download';
  };

  $scope.$routeSegment = $routeSegment;
  $scope.id = $routeSegment.$routeParams.id;
  if ($scope.id !== undefined) {
    // Try to get file from the file list first, to avoid pinging the server.
    var file = SelectedFiles.get($scope.id);
    if (file) {
      vm.set_file_data(file);
    } else {
      // If the data isn't available, contact the server to fetch file info;
      // it may not have been loaded.
      var on_failure = error => {
        Alert.alerts.push({
          type: 'danger',
          message: 'Unable to retrieve metadata for file with UUID ' + $scope.id,
        });
      };
      File.get($scope.id).then(file => {
        vm.set_file_data(file);
      }, on_failure);
    }
  }
{'fraction_non_alphanumeric': 0.1505422993492408, 'fraction_numerical': 0.0, 'mean_word_length': 2.921768707482993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938800', 'n_tokens_mistral': 712, 'n_tokens_neox': 695, 'n_words': 193}