From ea7bb82661d9baf18a372cf59874d50c79a1c491 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 8 Jul 2020 15:24:18 +0200 Subject: [PATCH 1/2] Unify more tables (Corpus: corpus files view) --- web/app/corpora/views.py | 15 ++- web/app/results/views.py | 3 +- web/app/static/js/nopaque.lists.js | 109 +++++++++++++++---- web/app/templates/corpora/corpus.html.j2 | 40 ++++--- web/app/templates/jobs/job.html.j2 | 12 +- web/app/templates/macros/materialize.html.j2 | 5 +- web/requirements.txt | 1 - 7 files changed, 134 insertions(+), 51 deletions(-) diff --git a/web/app/corpora/views.py b/web/app/corpora/views.py index 6d78c8b4..765e53d3 100644 --- a/web/app/corpora/views.py +++ b/web/app/corpora/views.py @@ -9,6 +9,7 @@ from .forms import (AddCorpusFileForm, AddCorpusForm, EditCorpusFileForm, from .. import db from ..models import Corpus, CorpusFile import os +from .. import logger @corpora.route('/add', methods=['GET', 'POST']) @@ -44,7 +45,17 @@ def corpus(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) if not (corpus.creator == current_user or current_user.is_administrator()): abort(403) - return render_template('corpora/corpus.html.j2', corpus=corpus, + corpus_files = [dict(filename=corpus_file.filename, + author=corpus_file.author, + title=corpus_file.title, + publishing_year=corpus_file.publishing_year, + corpus_id=corpus.id, + id=corpus_file.id + ) + for corpus_file in corpus.files] + return render_template('corpora/corpus.html.j2', + corpus=corpus, + corpus_files=corpus_files, title='Corpus') @@ -216,7 +227,7 @@ def prepare_corpus(corpus_id): abort(403) if corpus.files.all(): tasks.build_corpus(corpus_id) - flash('Corpus gets build now.', 'corpus') + flash('Building Corpus...', 'corpus') else: flash('Can not build corpus, please add corpus file(s).', 'corpus') return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) diff --git a/web/app/results/views.py b/web/app/results/views.py index 4b591122..53ccd8d8 100644 --- a/web/app/results/views.py +++ b/web/app/results/views.py @@ -10,6 +10,7 @@ from flask import (abort, render_template, current_app, request, redirect, from flask_login import current_user, login_required import json import os +from .. import logger @results.route('/import_results', methods=['GET', 'POST']) @@ -69,7 +70,7 @@ def results_overview(): ''' # get all results of current user results = User.query.get(current_user.id).results - + logger.warning(results) def __p_time(time_str): # helper to convert the datetime into a nice readable string return datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S.%f') diff --git a/web/app/static/js/nopaque.lists.js b/web/app/static/js/nopaque.lists.js index a2584e71..fdcd4bbd 100644 --- a/web/app/static/js/nopaque.lists.js +++ b/web/app/static/js/nopaque.lists.js @@ -1,6 +1,7 @@ class RessourceList extends List { constructor(idOrElement, subscriberList, type, options={}) { - if (!["corpus", "job", "result", "user", "job_input"].includes(type)) { + if (!["corpus", "job", "result", "user", "job_input", + "corpus_file"].includes(type)) { console.error("Unknown Type!"); return; } @@ -78,7 +79,17 @@ RessourceList.dataMapper = { "analyse-link": ["analysing", "prepared", "start analysis"].includes(corpus.status) ? `/corpora/${corpus.id}/analyse` : "", "edit-link": `/corpora/${corpus.id}`, status: corpus.status, - title: corpus.title}), + title: corpus.title + }), + // Mapping for corpus file entities shown in the corpus overview + corpus_file: corpus_file => ({filename: corpus_file.filename, + author: corpus_file.author, + title: corpus_file.title, + publishing_year: corpus_file.publishing_year, + "edit-link": `${corpus_file.corpus_id}/files/${corpus_file.id}/edit`, + "download-link": `${corpus_file.corpus_id}/files/${corpus_file.id}/download`, + "delete-modal": `delete-corpus-file-${corpus_file.id}-modal` + }), // Mapping for job entities shown in the dashboard table. job: job => ({creation_date: job.creation_date, description: job.description, @@ -86,11 +97,13 @@ RessourceList.dataMapper = { link: `/jobs/${job.id}`, service: job.service, status: job.status, - title: job.title}), + title: job.title + }), // Mapping for job input files shown in table on every job page job_input: job_input => ({filename: job_input.filename, id: job_input.job_id, - "download-link": `${job_input.job_id}/inputs/${job_input.id}/download`}), + "download-link": `${job_input.job_id}/inputs/${job_input.id}/download` + }), // Mapping for imported result entities from corpus analysis. // Shown in imported results table result: result => ({ query: result.query, @@ -101,14 +114,16 @@ RessourceList.dataMapper = { corpus_type : result.corpus_type, "details-link": `${result.id}/details`, "inspect-link": `${result.id}/inspect`, - "delete-modal": `delete-result-${result.id}-modal`}), + "delete-modal": `delete-result-${result.id}-modal` + }), // Mapping for user entities shown in admin table user: user => ({username: user.username, email: user.email, role_id: user.role_id, confirmed: user.confirmed, id: user.id, - "profile-link": `user/${user.id}`}) + "profile-link": `user/${user.id}` + }) }; @@ -146,12 +161,12 @@ RessourceList.options = { - - + + edit - search + search `, @@ -165,6 +180,42 @@ RessourceList.options = { {name: "edit-link", attr: "href"}, {name: "status", attr: "data-status"}] }, + // Corpus file entity blueprint setting html strucuture per entity per row + // Link classes have to correspond with Links defined in the Mapping process + corpus_file: {item: ` + + + + + + + edit + + + file_download + + + delete + + + `, + valueNames: ["filename", + "author", + "title", + "publishing_year", + {name: "edit-link", attr: "href"}, + {name: "download-link", attr: "href"}, + {name: "delete-modal", attr: "data-target"}] + }, // Job entity blueprint setting html strucuture per entity per row // Link classes have to correspond with Links defined in the Mapping process job: {item: ` @@ -180,9 +231,9 @@ RessourceList.options = { - + - send + send `, @@ -198,8 +249,12 @@ RessourceList.options = { }, job_input: {item : ` - - file_download + + + file_download `, @@ -217,12 +272,24 @@ RessourceList.options = { - - info_outline + + + info_outline - search + + search - delete + + delete `, @@ -246,8 +313,12 @@ RessourceList.options = { - - edit + + + edit `, diff --git a/web/app/templates/corpora/corpus.html.j2 b/web/app/templates/corpora/corpus.html.j2 index 0a0a8c76..fdbe2b8b 100644 --- a/web/app/templates/corpora/corpus.html.j2 +++ b/web/app/templates/corpora/corpus.html.j2 @@ -59,41 +59,34 @@
-
+
Files - +
+ search + + +
+
    - - - - - + + + + + - + - {% for file in corpus.files %} - - - - - - - - {% endfor %}
    FilenameAuthorTitlePublishing yearFilenameAuthorTitlePublishing year{# Actions #}
    bookNothing here...

    Corpus is empty. Add texts using the option below.

    {{ file.filename }}{{ file.author }}{{ file.title }}{{ file.publishing_year }} - edit - file_download - delete -
    +
      addAdd corpus file @@ -129,6 +122,11 @@