Switch to side-by-side view

--- a
+++ b/qiita_pet/templates/upload.html
@@ -0,0 +1,300 @@
+{% extends sitebase.html %}
+
+{% block head %}
+
+<script type="text/javascript">
+  function validate_file() {
+    var ssh_key = $("#ssh-key")[0].files[0];
+    if (ssh_key.size > 4000) {
+      alert("Your input file is too large to be a valid key, please try again.");
+      $("#ssh-key").val("");
+    }
+  }
+
+  function validate_form() {
+    // modified from https://gist.github.com/dperini/729294#gistcomment-15527
+    var re_weburl = new RegExp(
+        // protocol identifier
+        "(?:(?:scp?)://)" +
+        // user:pass authentication
+        "(?:\\S+(?::\\S*)?@)?" +
+        "(?:" +
+        // IP address exclusion
+        // private & local networks
+        "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
+        "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
+        "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
+        // IP address dotted notation octets
+        // excludes loopback network 0.0.0.0
+        // excludes reserved space >= 224.0.0.0
+        // excludes network & broacast addresses
+        // (first & last IP address of each class)
+        "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
+        "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
+        "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
+        "|" +
+        // host name
+        "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
+        // domain name
+        "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
+        // TLD identifier
+        "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
+        // sorry, ignore TLD ending with dot
+        // "\\.?" +
+        ")" +
+        // port number
+        "(?::\\d{2,5})?" +
+        // resource path, excluding a trailing punctuation mark
+        "(?:[/?#](?:\\S*[^\\s!\"'()*,-.:;<>?\\[\\]_`{|}~]|))?"
+        , "gi"
+    );
+    var valid_protocol = false;
+    var url = $("#inputURL").val();
+    var ssh_key = $("#ssh-key")[0].files[0];
+
+    if (url === '' || ssh_key === '' || ssh_key === undefined){
+      alert("URL and SSH key can't be empty")
+    } else {
+      if(re_weburl.test(url)) {
+        valid_protocol = true;
+      } else {
+        alert('Not a valid URL: ' + url);
+      }
+    }
+    return valid_protocol;
+  }
+
+  function connect_to_remote_server(method) {
+    $('#remote-request-type').val(method);
+    var formData = new FormData($('#remote-form')[0]);
+    if (validate_form()) {
+      $.ajax({
+        url:'{% raw qiita_config.portal_dir %}/study/upload/remote/' + {{study_id}},
+        type:'POST',
+        data:formData,
+        contentType:false,
+        processData:false,
+        cache:false,
+        success: function(data) {
+          window.location.reload(1);
+        },
+        error: function (object, status, error_msg) {
+          bootstrapAlert("Error: " + error_msg, "danger")
+        }
+      });
+    }
+  }
+
+  {% if level == 'info' and 'Retrieving remote files:' in  message %}
+    setTimeout(function(){
+      window.location.reload(1);
+    }, 5000);
+  {% end %}
+</script>
+
+{% end %}
+
+{% block content %}
+
+{% if level != 'info' or 'Retrieving remote files:' not in message or not message %}
+
+<div class="container">
+
+  <div class="row">
+    <b>Uploading files for: {{study_title}} ({{study_info['study_alias']}})</b>
+    <br/><br/>
+    Currently we can process (<b>{{extensions.replace(',',', ')}}</b>):
+    <ul>
+      <li>Note that '.zip' files can not be processed.</li>
+      <li>Note that '.fasta' and '.fna' files require '.qual' files for submission.</li>
+      <li>Note that '.txt.' files must be tab separated and require the extension .txt.</li>
+    </ul>
+    Per our Terms of Condition for use, you certify that the files you are uploading do not contain:
+    <ul>
+      <li>protected health information within the meaning of 45 Code of Federal Regulations part 160 and part 164, subparts A and E; <a target="_blank" href="http://cmi.ucsd.edu/PHIChecklist">see checklist</a></li>
+      <li>whole genome sequencing data for any human subject; <a target="_blank" href="https://www.hmpdacc.org/hmp/doc/HumanSequenceRemoval_SOP.pdf">HMP human sequence removal protocol</a></li>
+      <li>any data that is copyrighted, protected by trade secret, or otherwise subject to third party proprietary rights, including privacy and publicity rights, unless you are the owner of such rights or have permission from the rightful owner(s) to transfer the data and grant it to Qiita, on behalf of the Regents of the University of California, <a target="_blank" href="https://qiita.ucsd.edu/iframe/?iframe=qiita-terms">all of the license rights granted in our Terms.</li>
+    </ul>
+  </div>
+
+  <div class="row" align="center">
+    <a href="{% raw qiita_config.portal_dir %}/study/description/{{study_id}}">&lt;&lt; Go to study description</a>
+  </div>
+
+  <div class="row">
+    <div class="panel-group" id="accordion">
+      <div class="panel panel-default">
+        <div class="panel-heading">
+          <h4 class="panel-title">
+            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
+              Upload via Local Machine
+            </a>
+          </h4>
+        </div>
+        <div id="collapseOne" class="panel-collapse collapse {%if not remote_files and not remote_url %} in {% end %}">
+          <div class="row" align="center">
+            <b>Upload files locally (max file size: {% if max_upload_size/1000==0 %} {{max_upload_size}} GB{% else %} {{max_upload_size/1000.0}} TB{% end %})</b>
+          </div>
+
+          <div style="height: 150px; width: 100%; background-color:lightgrey; border: 2px solid; border-radius: 25px;" class="resumable-drop-metadata" ondragenter="jQuery(this).addClass('resumable-dragover');" ondragend="jQuery(this).removeClass('resumable-dragover');" ondrop="jQuery(this).removeClass('resumable-dragover');">
+            <div align="center">
+              <p style="vertical-align: middle;">Drop files here to upload or <a class="resumable-browse-metadata"><u>select from your computer</u></a></p>
+            </div>
+          </div>
+
+            <div class="progress-metadata" style="display:none;">
+              <table>
+                <tr>
+                  <td width="100%"><div class="progress-container"><div class="progress-bar"></div></div></td>
+                  <td class="progress-text" nowrap="nowrap"></td>
+                  <td class="progress-pause" nowrap="nowrap">
+                    &nbsp;&nbsp;&nbsp;&nbsp;
+                    <a href="#" onclick="uploader.resumable.upload(); $('#uploader_status').html('~~ Uploading ~~'); return(false);" class="progress-resume-link"><span class="glyphicon glyphicon-play"></span></a>
+                    <a href="#" onclick="uploader.resumable.pause(); $('#uploader_status').html('~~ Paused ~~'); return(false);" class="progress-pause-link"><span class="glyphicon glyphicon-pause"></span></a>
+                  </td>
+                </tr>
+                <tr>
+                  <td colspan="3">
+                    <div class="blinking-message">
+                      <div id="uploader_status"></div>
+                      Keep track of your upload or pause/resume it! <span class="glyphicon glyphicon-arrow-up"></span>
+                      <br/>
+                      <small>Your upload won't be interrupted if you change networks or you close your computer, just make sure you don't leave this page. </small>
+                    </div>
+                  </td>
+                <tr>
+              </table>
+            </div>
+        </div>
+      </div>
+      <div class="panel panel-default">
+        <div class="panel-heading">
+          <h4 class="panel-title">
+            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
+              Upload via Remote Server (ADVANCED)
+            </a>
+          </h4>
+        </div>
+        <div id="collapseTwo" class="panel-collapse collapse {%if remote_files and remote_url %} in {% end %}">
+          <div class="container">
+            {%if remote_files and remote_url %}
+              <div class="row">
+                <button class="btn btn-default" data-toggle="collapse" data-target="#remote-files">
+                  <span class="glyphicon glyphicon-eye-open"></span>
+                  Files
+                </button> in {{remote_url}}
+                <div id="remote-files" class="collapse in" style="padding: 10px 10px 10px 10px; border-radius: 10px; background: #EEE;">
+                  {{', '.join(remote_files)}}
+                </div>
+              </div>
+              <br/>
+            {% end %}
+            <div class="row">
+              <button class="btn btn-default" data-toggle="collapse" data-target="#remote-file-instructions">
+                <span class="glyphicon glyphicon-eye-open"></span>
+                Instructions
+              </button>
+              <div id="remote-file-instructions" class="collapse" style="padding: 10px 10px 10px 10px; border-radius: 10px; background: #EEE;">
+                <ol>
+                  <li>Currently we only support ftp and scp.</li>
+                  <li>Prepare study files by storing them in one folder on your fileserver.</li>
+                  <li>Generate a new key by running: <code>ssh-keygen -t rsa -C "ssh test key" -f ~/.ssh/qiita-key -P ""</code> in your remote server.</li>
+                  <li>Allow access using the new key: <code>cat ~/.ssh/qiita-key.pub >> ~/.ssh/authorized_keys</code>. Note that erasing that line will remove access.</li>
+                  <li>Obtain your new generated private <code>qiita-key</code> and use it in the Key option</li>
+                  <li>Press 'List Files' to test the connection and verify the list of study files.</li>
+                  <li>If the connection is made and files are correct, press 'Transfer Files' to initiate the transfer.</li>
+                </ol>
+              </div>
+              <br/><br/>
+            </div>
+            <div class="row">
+              <form class="form-horizontal" name="remote-form" id="remote-form" enctype="multipart/form-data">
+                <input type="hidden" id="remote-request-type" name="remote-request-type">
+                <div class="form-group">
+                  <label class="col-md-1 control-label">URL</label>
+                  <div class="col-md-6">
+                    <input type="text" class="form-control" name="inputURL" id="inputURL" placeholder="scp://user@server.com:/folders/">
+                  </div>
+                  <label for="inputURL" class="col-md-1 control-label">Key</label>
+                  <div class="col-md-2">
+                      <input type="file" name="ssh-key" id="ssh-key" onchange="validate_file();">
+                  </div>
+                </div>
+                <div class="form-group">
+                  <div class="col-md-2"></div>
+                  <div class="col-md-1">
+                    <button type="button" class="btn btn-default" onclick="connect_to_remote_server('list');">List Files</button>
+                  </div>
+                  <div class="col-md-1">
+                    <button type="button" class="btn btn-default" onclick="connect_to_remote_server('transfer');">Transfer Files</button>
+                  </div>
+                </div>
+              </form>
+          </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+
+  <hr>
+  <div class="row" align="center">
+    <h3><u>Files</u></h3>
+    <table align="center" border="0">
+      <tr>
+        <td>
+          <button type="button" class="btn btn-default" onclick="$('input[name*=\'files_to_erase\']').prop('checked', true);">Select All</button>
+        </td>
+        <td width="30px">&nbsp;</td>
+        <td>
+          <button type="button" class="btn btn-default" onclick="$('input[name*=\'files_to_erase\']').removeAttr('checked');">Unselect All</button>
+        </td>
+      </tr>
+    </table>
+  </div>
+
+  <div class="row", align="center">
+    <form method="post" id="delete-files-form">
+      <div class="uploader-list" style="display:none;">
+      </div>
+    </form>
+    <div class="file-edit-container" style="display:none;">
+    </div>
+    &nbsp;
+    <button type="button" class="btn btn-danger" onclick="if(confirm('Are you sure you want to delete the selected files? You can not undo this action')) { $('#delete-files-form').submit() }">
+      <span class="glyphicon glyphicon-trash"></span> Delete selected files
+    </button>
+  </div>
+</div>
+
+
+<div style='width:inherit;text-align:center;padding-top:30px'>
+  <small><a href="{% raw qiita_config.portal_dir %}/study/description/{{study_id}}">&lt;&lt; Go to study description</a></small>
+</div>
+
+
+
+<!-- Upload required files and JS code -->
+<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/resumable.js"></script>
+<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/resumable-uploader.js"></script>
+
+<script>
+  var meta = { fileType: [] };
+  var maxFileSize = {{max_upload_size}}; // in GB
+
+  uploader = (function($){
+      return (new ResumableUploader(meta, $('.resumable-browse-metadata'),
+                                    $('.resumable-drop-metadata'), $('.progress-metadata'),
+                                    $('.uploader-list'), $('.file-edit-container'),
+                                    maxFileSize, "{{study_id}}", "{{extensions}}",
+                                    "{% raw qiita_config.portal_dir %}", '{{is_admin}}'=='True',
+                                    '{% raw qiita_config.portal_dir %}/download_upload/{{study_id}}/'));
+    })(jQuery);
+
+  {% for dirid, filename, size in files %}
+    uploader.addFile({ "dirid": "{{dirid}}", "fileName": "{{filename}}", "size": "{{size}}", "uploaded": "True" });
+  {% end  %}
+</script>
+
+{% end %}
+{% end %}