<commit_before>(function(){

angular
  .module('platanus.upload')
  .directive('asyncUploadPreview', asyncUploadPreview);

function asyncUploadPreview() {
  var directive = {
    link: link,
    require: 'ngModel',
    replace: true,
    scope: {
      ngModel: '=',
      documentName: '=',
      uploadUrl: '@',
      renderImageAs: '@',
      noDocumentText: '@',
      documentExtension: '@'
    },
    template:
      '<div>' +
        '<async-upload ' +
          'upload-url="{{uploadUrl}}" ' +
          'progress-callback="setProgress(event)" ' +
          'success-callback="setUploadData(uploadData)" ' +
          'error-callback="setError(errorData)" ' +
          'ng-model="ngModel"></async-upload>' +
        '<upload-progress hide-on-zero="true" progress-data="progressData"></upload-progress>' +
        '<doc-preview ' +
          'no-document-text="{{noDocumentText}}" ' +
          'render-image-as="{{renderImageAs}}" ' +
          'document-name="uploadData.documentName" ' +
          'document-extension="{{uploadData.fileExtension}}" ' +
          'document-url="uploadData.downloadUrl">' +
        '</doc-preview>' +
      '<div>'
  };

  return directive;

  function link(_scope) {
    _scope.setUploadData = setUploadData;
    _scope.setProgress = setProgress;
    _scope.setError = setError;

    function setInitialState() {
      _scope.uploadData = null;
      _scope.progressData = { loaded: 0, total: 1 };
    }

    function setProgress(event) {
      if(event) {
        _scope.progressData = event;
      }
    }

    function setError(errorData) {
      setInitialState();
    }

    function setUploadData(uploadData) {
      _scope.uploadData = uploadData.upload;
      var data = (uploadData.upload || uploadData);

      _scope.uploadData.identifier = data.identifier;
      _scope.uploadData.documentName = (data.file_name || data.fileName);
      _scope.uploadData.fileExtension = (data.file_extension || data.fileExtension);
      _scope.uploadData.downloadUrl = (data.download_url || data.downloadUrl);

      if(!_scope.uploadData.identifier || !_scope.uploadData.documentName ||
        !_scope.uploadData.fileExtension || !_scope.uploadData.downloadUrl) {
        throw 'Invalid response. Must be a json with identifier, file_name, file_extension and download_url';
      }
    }
  }
}

})();<commit_msg>feat(directives.asyncUploadPreview): set initial state<commit_after>(function(){

angular
  .module('platanus.upload')
  .directive('asyncUploadPreview', asyncUploadPreview);

function asyncUploadPreview() {
  var directive = {
    link: link,
    require: 'ngModel',
    replace: true,
    scope: {
      ngModel: '=',
      documentName: '=',
      uploadUrl: '@',
      renderImageAs: '@',
      noDocumentText: '@',
      documentExtension: '@'
    },
    template:
      '<div>' +
        '<async-upload ' +
          'upload-url="{{uploadUrl}}" ' +
          'start-callback="onStart()" ' +
          'progress-callback="setProgress(event)" ' +
          'success-callback="setUploadData(uploadData)" ' +
          'error-callback="setError(errorData)" ' +
          'ng-model="ngModel"></async-upload>' +
        '<upload-progress hide-on-zero="true" progress-data="progressData"></upload-progress>' +
        '<doc-preview ' +
          'no-document-text="{{noDocumentText}}" ' +
          'render-image-as="{{renderImageAs}}" ' +
          'document-name="uploadData.documentName" ' +
          'document-extension="{{uploadData.fileExtension}}" ' +
          'document-url="uploadData.downloadUrl">' +
        '</doc-preview>' +
      '<div>'
  };

  return directive;

  function link(_scope) {
    _scope.setUploadData = setUploadData;
    _scope.setProgress = setProgress;
    _scope.setError = setError;
    _scope.onStart = onStart;

    function setInitialState() {
      _scope.uploadData = null;
      _scope.progressData = { loaded: 0, total: 1 };
    }

    function setProgress(event) {
      if(event) {
        _scope.progressData = event;
      }
    }

    function setError(errorData) {
      setInitialState();
    }

    function onStart() {
      setInitialState();
    }

    function setUploadData(uploadData) {
      _scope.uploadData = uploadData.upload;
      var data = (uploadData.upload || uploadData);

      _scope.uploadData.identifier = data.identifier;
      _scope.uploadData.documentName = (data.file_name || data.fileName);
      _scope.uploadData.fileExtension = (data.file_extension || data.fileExtension);
      _scope.uploadData.downloadUrl = (data.download_url || data.downloadUrl);

      if(!_scope.uploadData.identifier || !_scope.uploadData.documentName ||
        !_scope.uploadData.fileExtension || !_scope.uploadData.downloadUrl) {
        throw 'Invalid response. Must be a json with identifier, file_name, file_extension and download_url';
      }
    }
  }
}

})();
{'fraction_non_alphanumeric': 0.1473360655737705, 'fraction_numerical': 0.000819672131147541, 'mean_word_length': 2.822239624119029, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1434382', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1443, 'n_words': 217}