diff --git a/app/corpora/decorators.py b/app/corpora/decorators.py index 1d6eb2e1..1cf78feb 100644 --- a/app/corpora/decorators.py +++ b/app/corpora/decorators.py @@ -9,11 +9,11 @@ def corpus_follower_permission_required(*permissions): @wraps(f) def decorated_function(*args, **kwargs): corpus_id = kwargs.get('corpus_id') - cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first() - if cfa is None: - abort(403) - corpus = cfa.corpus + corpus = Corpus.query.get_or_404(corpus_id) if not (corpus.user == current_user or current_user.is_administrator()): + cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first() + if cfa is None: + abort(403) if not all([cfa.role.has_permission(p) for p in permissions]): abort(403) return f(*args, **kwargs) diff --git a/app/corpora/files/routes.py b/app/corpora/files/routes.py index 108acf1a..1df7c9bf 100644 --- a/app/corpora/files/routes.py +++ b/app/corpora/files/routes.py @@ -14,9 +14,7 @@ from ..decorators import corpus_follower_permission_required from ..utils import corpus_endpoint_arguments_constructor as corpus_eac from . import bp from .forms import CreateCorpusFileForm, UpdateCorpusFileForm -from .utils import ( - corpus_file_dynamic_list_constructor as corpus_file_dlc -) +from .utils import corpus_file_dynamic_list_constructor as corpus_file_dlc @bp.route('//files') @@ -60,7 +58,7 @@ def create_corpus_file(corpus_id): flash(f'Corpus File "{corpus_file.filename}" added', category='corpus') return '', 201, {'Location': corpus.url} return render_template( - 'corpora/files/create_corpus_file.html.j2', + 'corpora/files/create.html.j2', title='Add corpus file', form=form, corpus=corpus diff --git a/app/corpora/routes.py b/app/corpora/routes.py index c42165db..75f7dfc0 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -40,7 +40,7 @@ def create_corpus(): flash(f'Corpus "{corpus.title}" created', 'corpus') return redirect(corpus.url) return render_template( - 'corpora/create_corpus.html.j2', + 'corpora/create.html.j2', title='Create corpus', form=form ) @@ -72,13 +72,13 @@ def corpus(corpus_id): abort(403) -@bp.route('//analyse') +@bp.route('//analysis') @corpus_follower_permission_required('VIEW') -@register_breadcrumb(bp, '.entity.analyse', 'Analyse', endpoint_arguments_constructor=corpus_eac) -def analyse_corpus(corpus_id): +@register_breadcrumb(bp, '.entity.analysis', 'Analysis', endpoint_arguments_constructor=corpus_eac) +def analysis(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) return render_template( - 'corpora/analyse_corpus.html.j2', + 'corpora/analysis.html.j2', corpus=corpus, title=f'Analyse Corpus {corpus.title}' ) diff --git a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js index 5ca7960b..f5cb8712 100644 --- a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js +++ b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js @@ -7,8 +7,6 @@ class CorpusAnalysisApp { container: document.querySelector('#corpus-analysis-app-container'), extensionTabs: document.querySelector('#corpus-analysis-app-extension-tabs'), initModal: document.querySelector('#corpus-analysis-app-init-modal'), - initError: document.querySelector('#corpus-analysis-app-init-error'), - initProgress: document.querySelector('#corpus-analysis-app-init-progress'), overview: document.querySelector('#corpus-analysis-app-overview') }; // Materialize elements @@ -27,6 +25,7 @@ class CorpusAnalysisApp { init() { this.disableActionElements(); this.elements.m.initModal.open(); + // Init data this.data.cQiClient = new CQiClient(this.settings.corpusId); this.data.cQiClient.connect() @@ -43,14 +42,17 @@ class CorpusAnalysisApp { this.elements.m.initModal.close(); }, cQiError => { - this.elements.initError.innerText = JSON.stringify(cQiError); - this.elements.initError.classList.remove('hide'); - this.elements.initProgress.classList.add('hide'); + let errorsElement = this.elements.initModal.querySelector('.errors'); + let progressElement = this.elements.initModal.querySelector('.progress'); + errorsElement.innerText = JSON.stringify(cQiError); + errorsElement.classList.remove('hide'); + progressElement.classList.add('hide'); if ('payload' in cQiError && 'code' in cQiError.payload && 'msg' in cQiError.payload) { app.flash(`${cQiError.payload.code}: ${cQiError.payload.msg}`, 'error'); } } ); + // Add event listeners for (let extensionSelectorElement of this.elements.overview.querySelectorAll('.extension-selector')) { extensionSelectorElement.addEventListener('click', () => { diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2 index b63c8c39..f893e898 100644 --- a/app/templates/_scripts.html.j2 +++ b/app/templates/_scripts.html.j2 @@ -108,6 +108,21 @@ app.flash(message, message); } + // Initialize manual modal + let manualModalTableOfContentsElement = document.querySelector('#manual-modal-table-of-contents'); + let manualModalTableOfContents = M.Tabs.init(manualModalTableOfContentsElement); + let manualModalElement = document.querySelector('#manual-modal'); + let manualModal = M.Modal.init( + manualModalElement, + { + onOpenStart: (manualModalElement, modalTriggerElement) => { + if ('manualModalChapter' in modalTriggerElement.dataset) { + manualModalTableOfContents.select(modalTriggerElement.dataset.manualModalChapter); + } + } + } + ); + // Initialize terms of use modal const termsOfUseModal = document.getElementById('terms-of-use-modal'); M.Modal.init( diff --git a/app/templates/corpora/analyse_corpus.concordance.html.j2 b/app/templates/corpora/_analysis/concordance.html.j2 similarity index 92% rename from app/templates/corpora/analyse_corpus.concordance.html.j2 rename to app/templates/corpora/_analysis/concordance.html.j2 index 15682431..2fa63377 100644 --- a/app/templates/corpora/analyse_corpus.concordance.html.j2 +++ b/app/templates/corpora/_analysis/concordance.html.j2 @@ -9,9 +9,9 @@ - help Corpus Query Language tutorial + help Corpus Query Language tutorial | - info Tagsets + info Tagsets | info Examples diff --git a/app/templates/corpora/analyse_corpus.reader.html.j2 b/app/templates/corpora/_analysis/reader.html.j2 similarity index 100% rename from app/templates/corpora/analyse_corpus.reader.html.j2 rename to app/templates/corpora/_analysis/reader.html.j2 diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analysis.html.j2 similarity index 65% rename from app/templates/corpora/analyse_corpus.html.j2 rename to app/templates/corpora/analysis.html.j2 index 7d9debe1..dcb42b9f 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analysis.html.j2 @@ -32,216 +32,25 @@ -{% include "corpora/analyse_corpus.reader.html.j2" %} -{% include "corpora/analyse_corpus.concordance.html.j2" %} + +{# #} +{% include "corpora/_analysis/reader.html.j2" %} + +{% include "corpora/_analysis/concordance.html.j2" %} {% endblock page_content %} {% block modals %} {{ super() }}