From 021375f68da3733a381532b0f090baaa6ed6dd85 Mon Sep 17 00:00:00 2001
From: Stephan Porada <sporada@uni-bielefeld.de>
Date: Wed, 16 Sep 2020 10:41:02 +0200
Subject: [PATCH] Fix query results viewer etc. to work with results having
 eitehr full or no context.

---
 .../js/modules/corpus_analysis/client/Client.js      |  4 +++-
 .../js/modules/corpus_analysis/view/ResultsView.js   |  4 +++-
 .../json_schema/nopaque_cqi_py_results_schema.json   |  6 +++++-
 web/app/templates/query_results/inspect.html.j2      | 12 ++++++++----
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/web/app/static/js/modules/corpus_analysis/client/Client.js b/web/app/static/js/modules/corpus_analysis/client/Client.js
index 57148af1..14c82392 100644
--- a/web/app/static/js/modules/corpus_analysis/client/Client.js
+++ b/web/app/static/js/modules/corpus_analysis/client/Client.js
@@ -10,7 +10,8 @@ class Client {
   constructor({corpusId = null,
                socket = null,
                logging = true,
-               dynamicMode = true} = {}) {
+               dynamicMode = true,
+               fullContext = null} = {}) {
     this.corpusId = corpusId;
     this.dynamicMode = dynamicMode;
     this.logging = logging;
@@ -18,6 +19,7 @@ class Client {
     this.socket = socket;
     this.eventListeners = {};
     this.isBusy = false;
+    this.fullContext = fullContext;
     /**
      * Disables all console logging.
      * This is global. So every other log message in every other Class or
diff --git a/web/app/static/js/modules/corpus_analysis/view/ResultsView.js b/web/app/static/js/modules/corpus_analysis/view/ResultsView.js
index 386a12c3..0da1a86e 100644
--- a/web/app/static/js/modules/corpus_analysis/view/ResultsView.js
+++ b/web/app/static/js/modules/corpus_analysis/view/ResultsView.js
@@ -735,7 +735,9 @@ class ResultsList extends List {
     addToSubResultsBtn.setAttribute("class", classes + ` add`
                                 );
     addToSubResultsBtn.innerHTML = '<i class="material-icons add-btn">add</i>';
-    aCellElement.appendChild(inspectBtn);
+    if (client.dynamicMode || client.fullContext) {
+      aCellElement.appendChild(inspectBtn);
+    }
     if (client.dynamicMode) {
       aCellElement.appendChild(addToSubResultsBtn);
     }
diff --git a/web/app/static/json_schema/nopaque_cqi_py_results_schema.json b/web/app/static/json_schema/nopaque_cqi_py_results_schema.json
index 7d6b5801..63576d9c 100644
--- a/web/app/static/json_schema/nopaque_cqi_py_results_schema.json
+++ b/web/app/static/json_schema/nopaque_cqi_py_results_schema.json
@@ -73,6 +73,9 @@
                 "corpus_cqpserver_version": {
                     "type": "string"
                 },
+                "fullContext": {
+                    "type": "boolean"
+                },
                 "cpos_ranges": {
                     "type": "boolean"
                 }
@@ -95,7 +98,8 @@
                 "match_count",
                 "matches",
                 "query",
-                "text_lookup"
+                "text_lookup",
+                "fullContext"
             ],
             "title": "NopaqueCQIPYResults"
         },
diff --git a/web/app/templates/query_results/inspect.html.j2 b/web/app/templates/query_results/inspect.html.j2
index abe65194..2075c145 100644
--- a/web/app/templates/query_results/inspect.html.j2
+++ b/web/app/templates/query_results/inspect.html.j2
@@ -40,7 +40,8 @@
         {% include 'interactions/analysis.html.j2' %}
         {% include 'interactions/cite.html.j2' %}
         <div class="hide">
-          {# Hide those because they are not needed when inspecting results #}
+          {# Hide those because they are not needed when inspecting results.
+          But some of their elements are being asked for by the client. #}
           {% include 'interactions/export.html.j2' %}
           {% include 'interactions/create.html.j2' %}
         </div>
@@ -109,9 +110,6 @@ import {
  * Asynchronus and event driven code.
  */
 document.addEventListener("DOMContentLoaded", () => {
-  // Initialize the client with dynamicMode set to false.
-  const client = new Client({'logging': true,
-                             'dynamicMode': false});
   /**
    * Initializing the results object as a model holding all the data of a
    * query. Also holds the metadata of one query and results data.
@@ -124,6 +122,10 @@ document.addEventListener("DOMContentLoaded", () => {
   const resultsJson = {{ query_result_file_content|tojson|safe }};
   // Import metadata from DB passed to this view
   const metaDataJson = {{ query_metadata|tojson|safe }};
+  // Initialize the client with dynamicMode set to false.
+  const client = new Client({'logging': true,
+                             'dynamicMode': false,
+                             'fullContext': metaDataJson.fullContext});
     /**
    * Register needed listeners and their callbacks. But we will
    * just call the attached callbacks manually. Because dynamicMode is false.
@@ -161,6 +163,7 @@ document.addEventListener("DOMContentLoaded", () => {
     '#display-options-form-result_context',
     '#display-options-form-results_per_page',
     '#full-results-create',
+    '#full-results-export',
     '#inspect-results-export',
     '#meta-data-modal-content',
     ['#meta-data-modal', {
@@ -173,6 +176,7 @@ document.addEventListener("DOMContentLoaded", () => {
     '#query-results-table',
     '#show-meta-data',
     '#sub-results-create',
+    '#sub-results-export',
   ]);
   // Hide buttons which are not needed when just inspecting results
   resultsList.inspectResultsExport.classList.add('hide');
-- 
GitLab