<commit_before>
angular.module('openspecimen')
  .directive('osFileUpload', function($timeout, $q, $http, Alerts) {
    return {
      restrict: 'A',
      replace: true,
      scope: {
        ctrl: '='
      },      
      controller: function() {
        this.data = null;
        this.q = null;

        this.submit = function() {
          this.q = $q.defer();
          if (this.data) {
            this.data.submit();
          } else {
            Alerts.error('common.no_file_selected');
            this.q.reject();
          }

          return this.q.promise;
        };

        this.done = function(resp) {
          this.q.resolve(resp.result);
        };

        this.fail = function(resp) {
          var xhr = resp.xhr('responseText');
          var status = Math.floor(xhr.status / 100);
          if (status == 4) {
            var responses = eval(xhr.response);
            var errMsgs = [];
            angular.forEach(responses, function(err) {
              errMsgs.push(err.message + "(" + err.code + ")");
            });
            Alerts.errorText(errMsgs);
          } else if (status == 5) {
            Alerts.error("common.server_error");
          }

          this.q.reject(resp);
        }
      },
      link: function(scope, element, attrs, ctrl) {
        $timeout(function() {
          angular.extend(scope.ctrl, ctrl);

          element.find('input').fileupload({
            dataType: 'json',
            beforeSend: function(xhr) {
              xhr.setRequestHeader('X-OS-API-TOKEN', $http.defaults.headers.common['X-OS-API-TOKEN']);
            },
            add: function (e, data) {
              element.find('span').text(data.files[0].name);
              scope.ctrl.data = data;
            },
            done: function(e, data) {
              scope.ctrl.done(data);
            },
            fail: function(e, data) {
             scope.ctrl.fail(data);
            }
          })

        });
      },
      template: 
        '<div class="os-file-upload">' +
          '<input class="form-control" name="file" type="file">' +
          '<span class="name" translate="common.no_file_selected">' +
             'No File Selected' +
          '</span>' +
        '</div>'
    };
  });
<commit_msg>Reverted file-upload directive changes which is not needed<commit_after>
angular.module('openspecimen')
  .directive('osFileUpload', function($timeout, $q, $http, Alerts) {
    return {
      restrict: 'A',
      replace: true,
      scope: {
        ctrl: '='
      },      
      controller: function() {
        this.data = null;
        this.q = null;

        this.submit = function() {
          this.q = $q.defer();
          if (this.data) {
            this.data.submit();
          } else {
            Alerts.error('common.no_file_selected');
            this.q.reject();
          }

          return this.q.promise;
        };

        this.done = function(resp) {
          this.q.resolve(resp.result);
        };

        this.fail = function(resp) {
          var xhr = resp.xhr('responseText');
          var status = Math.floor(xhr.status / 100);
          if (status == 4) {
            var responses = eval(xhr.response);
            var errMsgs = [];
            angular.forEach(responses, function(err) {
              errMsgs.push(err.message + "(" + err.code + ")");
            });
            Alerts.errorText(errMsgs);
          } else if (status == 5) {
            Alerts.error("common.server_error");
          }

          this.q.reject(resp);
        }
      },
      link: function(scope, element, attrs, ctrl) {
        $timeout(function() {
          scope.ctrl = ctrl;

          element.find('input').fileupload({
            dataType: 'json',
            beforeSend: function(xhr) {
              xhr.setRequestHeader('X-OS-API-TOKEN', $http.defaults.headers.common['X-OS-API-TOKEN']);
            },
            add: function (e, data) {
              element.find('span').text(data.files[0].name);
              ctrl.data = data;
            },
            done: function(e, data) {
              ctrl.done(data);
            },
            fail: function(e, data) {
              ctrl.fail(data);
            }
          })
        });
      },
      template: 
        '<div class="os-file-upload">' +
          '<input class="form-control" name="file" type="file">' +
          '<span class="name" translate="common.no_file_selected">' +
             'No File Selected' +
          '</span>' +
        '</div>'
    };
  });

{'fraction_non_alphanumeric': 0.15457762052189297, 'fraction_numerical': 0.0026536930561698365, 'mean_word_length': 1.471584699453552, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5884766', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1321, 'n_words': 223}