From 338e760bfb98844bd2edcd4f6f8196e7d283248d Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 15 Apr 2020 10:32:21 +0200 Subject: [PATCH 1/3] Hide analyze button if corpus is not ready for this --- app/corpora/cqi/models/corpora.py | 3 +++ app/static/css/nopaque.css | 3 +++ app/static/js/nopaque.lists.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/corpora/cqi/models/corpora.py b/app/corpora/cqi/models/corpora.py index 0f67e195..8c282794 100644 --- a/app/corpora/cqi/models/corpora.py +++ b/app/corpora/cqi/models/corpora.py @@ -61,6 +61,9 @@ class Corpus(Model): subattr_value return lookups + def drop(self): + return self.client.api.corpus_drop_corpus(self.attrs['api_name']) + def query(self, query, subcorpus_name='Results'): return self.client.api.cqp_query(self.attrs['api_name'], subcorpus_name, query) diff --git a/app/static/css/nopaque.css b/app/static/css/nopaque.css index 17e8803b..1e3763dd 100644 --- a/app/static/css/nopaque.css +++ b/app/static/css/nopaque.css @@ -74,6 +74,9 @@ indicator will show up how the column is sorted right now.; */ } /* styles for resource lists */ +.analyse-link[href=""] { + display: none; +} .service[data-service]:before { content: "help"; } diff --git a/app/static/js/nopaque.lists.js b/app/static/js/nopaque.lists.js index 8cfda3c9..d8861bbe 100644 --- a/app/static/js/nopaque.lists.js +++ b/app/static/js/nopaque.lists.js @@ -56,7 +56,7 @@ RessourceList.dataMapper = { corpus: corpus => ({creation_date: corpus.creation_date, description: corpus.description, id: corpus.id, - "analyse-link": `/corpora/${corpus.id}/analyse`, + "analyse-link": ["analysing", "prepared", "start analysis"].includes(corpus.status) ? `/corpora/${corpus.id}/analyse` : "", "edit-link": `/corpora/${corpus.id}`, status: corpus.status, title: corpus.title}), From b251f9993d4a15e2a99a0820f6b336ddbb630016 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 15 Apr 2020 12:49:26 +0200 Subject: [PATCH 2/3] Add message if corpus is empty --- app/static/css/nopaque.css | 4 ++++ app/templates/corpora/corpus.html.j2 | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/static/css/nopaque.css b/app/static/css/nopaque.css index 1e3763dd..24027647 100644 --- a/app/static/css/nopaque.css +++ b/app/static/css/nopaque.css @@ -68,6 +68,10 @@ indicator will show up how the column is sorted right now.; */ z-index: 999; /* tmp fix */ } +.show-if-only-child:not(:only-child) { + display: none !important; +} + /* class for expert view */ .expert-view { cursor: pointer; diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index dd14e7e1..1812f64c 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -36,7 +36,7 @@
searchAnalyze {% if corpus.files[0] is defined %} - buildBuild + merge_typeCompile {% endif %} deleteDelete
@@ -49,6 +49,7 @@
Files + @@ -60,6 +61,12 @@ + + + {% for file in corpus.files %} @@ -160,7 +167,7 @@ } setStatus(status) { - let analyzeElement, buildElement, progressIndicatorElement, statusElement; + let analyzeElement, compileElement, progressIndicatorElement, statusElement; progressIndicatorElement = document.getElementById("progress-indicator"); if (["queued", "running", "start analysis", "stop analysis"].includes(status)) { @@ -180,11 +187,11 @@ analyzeElement.classList.add("disabled", "hide"); } - buildElement = document.getElementById("build"); + compileElement = document.getElementById("compile"); if (status === 'unprepared') { - buildElement.classList.remove("disabled", "hide"); + compileElement.classList.remove("disabled", "hide"); } else { - buildElement.classList.add("disabled", "hide"); + compileElement.classList.add("disabled", "hide"); } } } From b1d819444e4710ccb250dda7bd1492652b46bf1a Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 15 Apr 2020 14:30:41 +0200 Subject: [PATCH 3/3] corpus page: Only show compile buttons if corpus is unprepared AND has files. --- app/corpora/views.py | 11 +++++++---- app/models.py | 19 +++++++++++++++++++ app/templates/corpora/add_corpus_file.html.j2 | 14 +++++++++++++- app/templates/corpora/corpus.html.j2 | 18 ++++++++---------- app/templates/jobs/job.html.j2 | 8 +++----- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/app/corpora/views.py b/app/corpora/views.py index 1a220499..dc4d4ade 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,4 +1,4 @@ -from flask import (abort, current_app, flash, redirect, request, +from flask import (abort, current_app, flash, make_response, redirect, request, render_template, url_for, send_from_directory) from flask_login import current_user, login_required from threading import Thread @@ -99,8 +99,8 @@ def add_corpus_file(corpus_id): for corpus_file in corpus.files: if filename == corpus_file.filename: flash('File already registered to this corpus.') - return redirect(url_for('corpora.add_corpus_file', - corpus_id=corpus_id)) + return make_response({'redirect_url': url_for('corpora.corpus', corpus_id=corpus.id)}, 500) + # return redirect(url_for('corpora.add_corpus_file', corpus_id=corpus_id)) # Save the file dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id)) file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'], @@ -125,7 +125,10 @@ def add_corpus_file(corpus_id): corpus_file.id)) thread.start() flash('Corpus file added!') - return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) + return make_response( + {'redirect_url': url_for('corpora.corpus', corpus_id=corpus.id)}, + 201) + # return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) return render_template('corpora/add_corpus_file.html.j2', add_corpus_file_form=add_corpus_file_form, corpus=corpus, title='Add corpus file') diff --git a/app/models.py b/app/models.py index f8e6fbc6..d4044e57 100644 --- a/app/models.py +++ b/app/models.py @@ -426,6 +426,24 @@ class CorpusFile(db.Model): self.corpus.status = 'unprepared' db.session.commit() + def to_dict(self): + return {'id': self.id, + 'address': self.address, + 'author': self.author, + 'booktitle': self.booktitle, + 'chapter': self.chapter, + 'dir': self.dir, + 'editor': self.editor, + 'filename': self.filename, + 'institution': self.institution, + 'journal': self.journal, + 'pages': self.pages, + 'publisher': self.publisher, + 'publishing_year': self.publishing_year, + 'school': self.school, + 'title': self.title, + 'corpus_id': self.corpus_id} + class Corpus(db.Model): """ @@ -455,6 +473,7 @@ class Corpus(db.Model): return {'id': self.id, 'creation_date': self.creation_date.timestamp(), 'description': self.description, + 'files': [file.to_dict() for file in self.files], 'status': self.status, 'title': self.title, 'user_id': self.user_id} diff --git a/app/templates/corpora/add_corpus_file.html.j2 b/app/templates/corpora/add_corpus_file.html.j2 index f792f0fe..beb46ba3 100644 --- a/app/templates/corpora/add_corpus_file.html.j2 +++ b/app/templates/corpora/add_corpus_file.html.j2 @@ -8,7 +8,7 @@
-
+ {{ add_corpus_file_form.hidden_tag() }}
@@ -103,4 +103,16 @@
+ + {% endblock %} diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 1812f64c..fcf181c5 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -35,9 +35,7 @@
searchAnalyze - {% if corpus.files[0] is defined %} merge_typeCompile - {% endif %} deleteDelete
@@ -121,6 +119,7 @@ constructor(corpusId, foreignCorpusFlag) { this.corpusId = corpusId; this.foreignCorpusFlag = foreignCorpusFlag; + if (this.foreignCorpusFlag) { nopaque.foreignCorporaSubscribers.push(this); } else { @@ -131,14 +130,11 @@ _init() { let corpus; - if (this.foreignCorpusFlag) { - corpus = nopaque.foreignCorpora[this.corpusId]; - } else { - corpus = nopaque.corpora[this.corpusId]; - } + corpus = (this.foreignCorpusFlag ? nopaque.foreignCorpora[this.corpusId] + : nopaque.corpora[this.corpusId]); // Status - this.setStatus(corpus.status); + this.setStatus(corpus.status, corpus.files.length); } _update(patch) { @@ -167,7 +163,9 @@ } setStatus(status) { - let analyzeElement, compileElement, progressIndicatorElement, statusElement; + let analyzeElement, compileElement, numFiles, progressIndicatorElement, statusElement; + + numFiles = (this.foreignCorpusFlag ? nopaque.foreignCorpora[this.corpusId] : nopaque.corpora[this.corpusId]).files.length; progressIndicatorElement = document.getElementById("progress-indicator"); if (["queued", "running", "start analysis", "stop analysis"].includes(status)) { @@ -188,7 +186,7 @@ } compileElement = document.getElementById("compile"); - if (status === 'unprepared') { + if (status === "unprepared" && numFiles > 0) { compileElement.classList.remove("disabled", "hide"); } else { compileElement.classList.add("disabled", "hide"); diff --git a/app/templates/jobs/job.html.j2 b/app/templates/jobs/job.html.j2 index bd0e7086..5b45d19a 100644 --- a/app/templates/jobs/job.html.j2 +++ b/app/templates/jobs/job.html.j2 @@ -146,6 +146,7 @@ constructor(jobId, foreignJobFlag) { this.jobId = jobId; this.foreignJobFlag = foreignJobFlag; + if (this.foreignJobFlag) { nopaque.foreignJobsSubscribers.push(this); } else { @@ -156,11 +157,8 @@ _init() { let job; - if (this.foreignJobFlag) { - job = nopaque.foreignJobs[this.jobId]; - } else { - job = nopaque.jobs[this.jobId]; - } + job = (this.foreignJobFlag ? nopaque.foreignJobs[this.jobId] + : nopaque.jobs[this.jobId]); // End date this.setEndDate(job.end_date);
+ bookNothing here... +

Corpus is empty. Add texts using the option below.

+
{{ file.filename }}