From 6b1f588f29da4323df5926f11a4806791cd2a6ba Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Thu, 6 Aug 2020 16:08:03 +0200 Subject: [PATCH] Add asynch version of Session initialization --- .../modules/nopaque.CorpusAnalysisClient.js | 121 +++++ ...js => nopaque.CorpusAnalysisClient.js.bak} | 0 .../templates/corpora/analyse_corpus.html.j2 | 386 +-------------- .../corpora/analyse_corpus.html.j2.bak | 440 ++++++++++++++++++ 4 files changed, 580 insertions(+), 367 deletions(-) create mode 100644 web/app/static/js/modules/nopaque.CorpusAnalysisClient.js rename web/app/static/js/{nopaque.CorpusAnalysisClient.js => nopaque.CorpusAnalysisClient.js.bak} (100%) create mode 100644 web/app/templates/corpora/analyse_corpus.html.j2.bak diff --git a/web/app/static/js/modules/nopaque.CorpusAnalysisClient.js b/web/app/static/js/modules/nopaque.CorpusAnalysisClient.js new file mode 100644 index 00000000..9c172608 --- /dev/null +++ b/web/app/static/js/modules/nopaque.CorpusAnalysisClient.js @@ -0,0 +1,121 @@ +class CorpusAnalysisClient { + constructor(corpusId, socket) { + this.corpusId = corpusId; + this.socket = socket; + this.displays = {}; + } + + setDisplay(type, display) { + this.displays[type] = display; + } + + async initSession() { + let request = await this.requestSession(); + let recvieveSession = await this.recvieveSession(); + console.log("corpus_analysis_init: Waiting for response"); // this happens inbetween the two functions above + } + + requestSession() { // should be private with ES2020 + console.log("corpus_analysis_init: Emitting to server"); + if (this.displays.init != undefined) { + this.displays.init.element.M_Modal.open(); + this.displays.init.setVisibilityByStatus("waiting"); + } + return new Promise((resolve, reject) => { + this.socket.emit("corpus_analysis_init", this.corpusId); + resolve(); + }) + } + + recvieveSession() { // should be private with ES2020 + this.socket.on("corpus_analysis_init", (response) => { + console.log("corpus_analysis_init: Recieving response from server"); + if (response.code === 200) { + console.log("corpus_analysis_init: Initialization succeeded"); + if (this.displays.init != undefined) { + this.displays.init.element.M_Modal.close(); + this.displays.init.setVisibilityByStatus("success"); + } + } else { + let errorText = `Error ${response.code} - ${response.msg}`; + if (this.displays.init.errorContainer != undefined) { + this.displays.init.errorContainer.innerHTML = `

` + + `error ${errorText}

`; + } + if (this.displays.init != undefined) { + this.displays.init.setVisibilityByStatus("error"); + } + console.error(`corpus_analysis_init: ${errorText}`); + } + }); + } +} + +class CorpusAnalysisDisplay { + constructor(element) { + this.element = (() => {if (element instanceof HTMLElement) { + return element; + } else { + element = element["$el"][0]; + return element; + } + })(); // with this function modals can also be handeld + this.errorContainer = element.querySelector(".error-container"); + this.showOnError = element.querySelectorAll(".show-on-error"); + this.showOnSuccess = element.querySelectorAll(".show-on-success"); + this.showWhileWaiting = element.querySelectorAll(".show-while-waiting"); + this.hideOnComplete = element.querySelectorAll(".hide-on-complete") + } + + setVisibilityByStatus(status) { + switch (status) { + case "error": + for (let element of this.showOnError) { + element.classList.remove("hide"); + } + for (let element of this.showOnSuccess) { + element.classList.add("hide"); + } + for (let element of this.showWhileWaiting) { + element.classList.add("hide"); + } + break; + case "success": + for (let element of this.showOnError) { + element.classList.add("hide"); + + } + for (let element of this.showOnSuccess) { + element.classList.remove("hide"); + } + for (let element of this.showWhileWaiting) { + element.classList.add("hide"); + } + break; + case "waiting": + for (let element of this.showOnError) { + element.classList.add("hide"); + } + for (let element of this.showOnSuccess) { + element.classList.add("hide"); + } + for (let element of this.showWhileWaiting) { + element.classList.remove("hide"); + } + break; + default: + // Hide all + for (let element of this.showOnError) { + element.classList.add("hide"); + } + for (let element of this.showOnSuccess) { + element.classList.add("hide"); + } + for (let element of this.showWhileWaiting) { + element.classList.add("hide"); + } + } + } +} + +export {CorpusAnalysisClient, CorpusAnalysisDisplay}; \ No newline at end of file diff --git a/web/app/static/js/nopaque.CorpusAnalysisClient.js b/web/app/static/js/nopaque.CorpusAnalysisClient.js.bak similarity index 100% rename from web/app/static/js/nopaque.CorpusAnalysisClient.js rename to web/app/static/js/nopaque.CorpusAnalysisClient.js.bak diff --git a/web/app/templates/corpora/analyse_corpus.html.j2 b/web/app/templates/corpora/analyse_corpus.html.j2 index 1ca61ba3..420ab29f 100644 --- a/web/app/templates/corpora/analyse_corpus.html.j2 +++ b/web/app/templates/corpora/analyse_corpus.html.j2 @@ -65,376 +65,28 @@ {% include 'modals/export_query_results.html.j2' %} {% include 'modals/context_modal.html.j2' %} + + - - - - {% endblock %} diff --git a/web/app/templates/corpora/analyse_corpus.html.j2.bak b/web/app/templates/corpora/analyse_corpus.html.j2.bak new file mode 100644 index 00000000..1ca61ba3 --- /dev/null +++ b/web/app/templates/corpora/analyse_corpus.html.j2.bak @@ -0,0 +1,440 @@ +{% extends "nopaque.html.j2" %} + +{% set headline = ' ' %} + +{% set full_width = True %} +{% set imported = False %} + +{% block page_content %} +
+
+
+ +
+
+
+
+ search + {{ query_form.query() }} + {{ query_form.query.label }} + + + help + + CQP query language tutorial + + +
+
+
+
+ {{ M.render_field(query_form.submit, material_icon='send') }} +
+
+
+
+
+
+ + +
+
+
+
+
+ {% include 'interactions/infos.html.j2' %} + {% include 'interactions/export.html.j2' %} + {% include 'interactions/create.html.j2' %} + {% include 'interactions/display.html.j2' %} + {% include 'interactions/analysis.html.j2' %} + {% include 'interactions/cite.html.j2' %} +
+ {% include 'tables/query_results.html.j2' %} +
+
+
+ + +{% include 'interactions/scroll_to_top.html.j2' %} + + +{% include 'modals/show_metadata.html.j2' %} +{% include 'modals/show_text_details.html.j2' %} +{% include 'modals/analysis_init.html.j2' %} +{% include 'modals/export_query_results.html.j2' %} +{% include 'modals/context_modal.html.j2' %} + + + + + + + +{% endblock %}