mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Add corpus page.
This commit is contained in:
		@@ -31,11 +31,28 @@ def corpus(corpus_id):
 | 
			
		||||
        files[file]['path'] = os.path.join(file)
 | 
			
		||||
 | 
			
		||||
    return render_template('main/corpora/corpus.html.j2',
 | 
			
		||||
                           corpus_id=corpus.id,
 | 
			
		||||
                           files=files,
 | 
			
		||||
                           corpus=corpus,
 | 
			
		||||
                           title='Corpus')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@main.route('/corpora/<int:corpus_id>/download')
 | 
			
		||||
@login_required
 | 
			
		||||
def corpus_download(corpus_id):
 | 
			
		||||
    file = request.args.get('file')
 | 
			
		||||
    corpus = current_user.corpora.filter_by(id=corpus_id).first()
 | 
			
		||||
    if not file or not corpus:
 | 
			
		||||
        print('File not found.')
 | 
			
		||||
        abort(404)
 | 
			
		||||
    dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
 | 
			
		||||
                       str(current_user.id),
 | 
			
		||||
                       'corpora',
 | 
			
		||||
                       str(corpus.id))
 | 
			
		||||
    return send_from_directory(as_attachment=True,
 | 
			
		||||
                               directory=dir,
 | 
			
		||||
                               filename=file)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@main.route('/dashboard', methods=['GET', 'POST'])
 | 
			
		||||
@login_required
 | 
			
		||||
def dashboard():
 | 
			
		||||
@@ -100,7 +117,7 @@ def job(job_id):
 | 
			
		||||
 | 
			
		||||
    return render_template('main/jobs/job.html.j2',
 | 
			
		||||
                           files=files,
 | 
			
		||||
                           job=job,
 | 
			
		||||
                           job_id=job.id,
 | 
			
		||||
                           title='Job')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										90
									
								
								app/templates/main/corpora/corpus.html.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								app/templates/main/corpora/corpus.html.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
{% extends "base.html.j2" %}
 | 
			
		||||
 | 
			
		||||
{% block page_content %}
 | 
			
		||||
<script>
 | 
			
		||||
  var CORPUS_ID = {{ corpus_id }}
 | 
			
		||||
 | 
			
		||||
  class InformationUpdater {
 | 
			
		||||
    constructor(corpusId) {
 | 
			
		||||
      this.corpusId = corpusId;
 | 
			
		||||
      corporaSubscribers.push(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _init() {
 | 
			
		||||
      var creationDateElement, descriptionElement, titleElement;
 | 
			
		||||
 | 
			
		||||
      this.corpus = corpora[this.corpusId];
 | 
			
		||||
      creationDateElement = document.getElementById("creation-date");
 | 
			
		||||
      creationDateElement.value = this.corpus.creation_date;
 | 
			
		||||
      descriptionElement = document.getElementById("description");
 | 
			
		||||
      descriptionElement.innerHTML = this.corpus.description;
 | 
			
		||||
      titleElement = document.getElementById("title");
 | 
			
		||||
      titleElement.innerHTML = this.corpus.title;
 | 
			
		||||
 | 
			
		||||
      M.updateTextFields();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _update(patch) {
 | 
			
		||||
      var newStatusColor, operation, pathArray, status, statusColor,
 | 
			
		||||
          updatedElement;
 | 
			
		||||
 | 
			
		||||
      for (operation of patch) {
 | 
			
		||||
        /* "/corpusId/valueName" -> ["corpusId", "valueName"] */
 | 
			
		||||
        pathArray = operation.path.split("/").slice(1);
 | 
			
		||||
        if (pathArray[0] != this.jobId) {continue;}
 | 
			
		||||
        switch(operation.op) {
 | 
			
		||||
          case "delete":
 | 
			
		||||
            location.reload();
 | 
			
		||||
            break;
 | 
			
		||||
          case "replace":
 | 
			
		||||
            switch(pathArray[1]) {
 | 
			
		||||
              case "description":
 | 
			
		||||
                updatedElement = document.getElementById("description");
 | 
			
		||||
                updatedElement.innerHTML = operation.value;
 | 
			
		||||
                break;
 | 
			
		||||
              case "title":
 | 
			
		||||
                updatedElement = document.getElementById("title");
 | 
			
		||||
                updatedElement.innerHTML = operation.value;
 | 
			
		||||
                break;
 | 
			
		||||
              default:
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
          default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  var informationUpdater = new InformationUpdater(CORPUS_ID);
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<div class="col s12 m4">
 | 
			
		||||
  <h3 id="title"></h3>
 | 
			
		||||
  <p id="description"></p>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="col s12 m8">
 | 
			
		||||
  <div class="card">
 | 
			
		||||
    <div class="card-content">
 | 
			
		||||
      <span class="card-title">Chronometrics</span>
 | 
			
		||||
      <div class="row">
 | 
			
		||||
        <div class="col s12 m6">
 | 
			
		||||
          <div class="input-field">
 | 
			
		||||
            <input disabled value="" id="creation-date" type="text" class="validate">
 | 
			
		||||
            <label for="creation-date">Creation date</label>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
      <span class="card-title">Files</span>
 | 
			
		||||
      <p>
 | 
			
		||||
      {% for file in files %}
 | 
			
		||||
      <a href="{{ url_for('main.corpus_download', corpus_id=corpus_id, file=files[file]['path']) }}" class="waves-effect waves-light btn-small">
 | 
			
		||||
        <i class="material-icons left">file_download</i>{{ file }}
 | 
			
		||||
      </a>
 | 
			
		||||
      {% endfor %}
 | 
			
		||||
      </p>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -53,8 +53,6 @@
 | 
			
		||||
        pathArray = operation.path.split("/").slice(1);
 | 
			
		||||
        if (pathArray[0] != this.jobId) {continue;}
 | 
			
		||||
        switch(operation.op) {
 | 
			
		||||
          case "add":
 | 
			
		||||
            break;
 | 
			
		||||
          case "delete":
 | 
			
		||||
            location.reload();
 | 
			
		||||
            break;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user