<commit_before>'use strict';

let FileFunnel = require('filefunnel.js');
let angular = require('angular');

let ff = angular.module('filefunnel', ['ngMaterial']);

ff.controller('FFUploadController', function($scope, $mdDialog, options) {
  let ff = new FileFunnel(null, options);
  $scope.ff = ff;

  ff._elements.fileInput.on('change', () => {
    $scope.$apply();
  });

  ff.on('success', file => {
    if (ff.status === FileFunnel.status.COMPLETED) {
      $mdDialog.hide(ff.files);
    }
  }).on('error', file => {
    ff.progressType = 'determinate';
	$scope.$apply();
  }).on('progress', file => {
    ff.progressType = 'determinate';
  }).on('start', file => {
    ff.progressType = 'indeterminate';
  });

  $scope.FileFunnelStatus = FileFunnel.status;
  ff.progressType = 'determinate';
});

ff.service('fileFunnelService', function($mdDialog, formulaFieldConfig) {
  const DEFAULTS = {
    server: "http://apptest.data.npolar.no/_file",
    accept: "*/*",
    chunked: true,
    multiple: false
  };

  let configs = formulaFieldConfig.getInstance();
  let defineOptions = function (config, formula) {
    configs.addConfig(Object.assign({}, DEFAULTS, config));
    if (formula) {
      formula.addTemplate({
        match: config.match,
        template: '<npdc:formula-file></npdc:formula-file>'
      });
    }
  };

  let getOptions = function (field) {
    return configs.getMatchingConfig(field);
  };

  let showUpload = function(ev, options) {
    return $mdDialog.show({
      clickOutsideToClose: true,
      controller: 'FFUploadController',
      locals: {
        options: options
      },
      targetEvent: ev,
      template: require('./filefunnel.html')
    });
  };

  return {
    defineOptions,
    getOptions,
    showUpload,
    status: FileFunnel.status
  };
});

ff.directive('filefunnel', function(fileFunnelService) {
  return {
    restrict: 'A',
    controller($scope, $mdDialog) {
      let options = fileFunnelService.getOptions($scope.field);

      $scope.showUpload = function(ev, target) {
        fileFunnelService.showUpload(ev, options)
          .then(files => {
            if (target[0] instanceof HTMLInputElement) {
              target[0].value = options.server + files[0].location;
            } else if ($scope.field) {
              $scope.field.fields.forEach(field => {
                switch (field.id) {
                  case 'uri':
                    field.value = options.server + files[0].location;
                    break;
                  case 'filename':
                    field.value = files[0].reference.name;
                    break;
                  case 'filesize':
                    field.value = files[0].reference.size;
                    break;
                  case 'mimetype':
                    field.value = files[0].reference.type;
                    break;
                  default:
                    // noop
                }
                field.readonly = true;
              });

              if ($scope.field.itemAdd) {
                let oldItemAdd = $scope.field.itemAdd;<commit_msg>geTOptions return defaults if no match<commit_after>'use strict';

let FileFunnel = require('filefunnel.js');
let angular = require('angular');

let ff = angular.module('filefunnel', ['ngMaterial']);

ff.controller('FFUploadController', function($scope, $mdDialog, options) {
  let ff = new FileFunnel(null, options);
  $scope.ff = ff;

  ff._elements.fileInput.on('change', () => {
    $scope.$apply();
  });

  ff.on('success', file => {
    if (ff.status === FileFunnel.status.COMPLETED) {
      $mdDialog.hide(ff.files);
    }
  }).on('error', file => {
    ff.progressType = 'determinate';
	$scope.$apply();
  }).on('progress', file => {
    ff.progressType = 'determinate';
  }).on('start', file => {
    ff.progressType = 'indeterminate';
  });

  $scope.FileFunnelStatus = FileFunnel.status;
  ff.progressType = 'determinate';
});

ff.service('fileFunnelService', function($mdDialog, formulaFieldConfig) {
  const DEFAULTS = {
    server: "http://apptest.data.npolar.no/_file",
    accept: "*/*",
    chunked: true,
    multiple: false
  };

  let configs = formulaFieldConfig.getInstance();
  let defineOptions = function (config, formula) {
    configs.addConfig(Object.assign({}, DEFAULTS, config));
    if (formula) {
      formula.addTemplate({
        match: config.match,
        template: '<npdc:formula-file></npdc:formula-file>'
      });
    }
  };

  let getOptions = function (field) {
    return configs.getMatchingConfig(field) || DEFAULTS;
  };

  let showUpload = function(ev, options) {
    return $mdDialog.show({
      clickOutsideToClose: true,
      controller: 'FFUploadController',
      locals: {
        options: options
      },
      targetEvent: ev,
      template: require('./filefunnel.html')
    });
  };

  return {
    defineOptions,
    getOptions,
    showUpload,
    status: FileFunnel.status
  };
});

ff.directive('filefunnel', function(fileFunnelService) {
  return {
    restrict: 'A',
    controller($scope, $mdDialog) {
      let options = fileFunnelService.getOptions($scope.field);
      $scope.showUpload = function(ev, target) {
        fileFunnelService.showUpload(ev, options)
          .then(files => {
            if (target[0] instanceof HTMLInputElement) {
              target[0].value = options.server + files[0].location;
            } else if ($scope.field) {
              $scope.field.fields.forEach(field => {
                switch (field.id) {
                  case 'uri':
                    field.value = options.server + files[0].location;
                    break;
                  case 'filename':
                    field.value = files[0].reference.name;
                    break;
                  case 'filesize':
                    field.value = files[0].reference.size;
                    break;
                  case 'mimetype':
                    field.value = files[0].reference.type;
                    break;
                  default:
                    // noop
                }
                field.readonly = true;
              });

              if ($scope.field.itemAdd) {
                let oldItemAdd = $scope.field.itemAdd;
{'fraction_non_alphanumeric': 0.1429489238676518, 'fraction_numerical': 0.0022486347574686796, 'mean_word_length': 2.1213032581453635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '4595844', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1783, 'n_words': 337}