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 5e2c626c..bd4f92bc 100644 --- a/web/app/static/js/modules/corpus_analysis/client/Client.js +++ b/web/app/static/js/modules/corpus_analysis/client/Client.js @@ -69,11 +69,14 @@ class Client { * The detail object can hold any type of data the View needs to know about * to represent those to the user. */ - notifyView(caseIdentifier, detailObject={}) { + notifyView(caseIdentifier, detailObject={}, notificationType='info', + raiseModalFeedback=true) { detailObject.caseIdentifier = caseIdentifier; detailObject.client = this; + detailObject.notificationType = notificationType; + detailObject.raiseModalFeedback = raiseModalFeedback; const event = new CustomEvent('notify-view', { detail: detailObject }); - console.info('Client dispatching Notification with detail object in details:', + console[notificationType]('Client dispatching Notification with detail object in details:', detailObject); document.dispatchEvent(event); } diff --git a/web/app/static/js/modules/corpus_analysis/client/listeners.js b/web/app/static/js/modules/corpus_analysis/client/listeners.js index 32aefce0..ceae01ba 100644 --- a/web/app/static/js/modules/corpus_analysis/client/listeners.js +++ b/web/app/static/js/modules/corpus_analysis/client/listeners.js @@ -31,9 +31,9 @@ function recieveConnected(type, client) { client.getMetaData(); } else { let errorText = `Error ${response.code} - ${response.msg}`; - console.group('Connection failed!') + console.group('Connection failed!'); console.error(`corpus_analysis_init: ${errorText}`); - client.notifyView('connecting-failed', { msg: errorText }); + client.notifyView('client-failed', { msg: errorText }, 'error'); console.groupEnd(); } }); @@ -58,11 +58,12 @@ function recieveMetaData(type, client) { client.eventListeners[type].executeCallbacks([response.payload]); console.groupEnd(); } else { + let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.group('Failed to recieve meta data.'); console.error('corpus_analysis_meta_data: Client failed to recieve', 'meta data via socket.on'); - let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.error(`corpus_analysis_meta_data: ${errorText}`); + client.notifyView('client-failed', { msg: errorText }, 'error'); console.groupEnd(); } }); @@ -89,13 +90,17 @@ function recieveQueryStatus(type, client) { client.eventListeners[type].executeCallbacks([response.payload]); console.groupEnd(); } else { + let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.group('corpus_analysis_query: Client failed recieving', 'query process status via socket.on'); - let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; if (response.payload.code == 1281) { errorText += ' - Invalid Query'; + console.error(`corpus_analysis_query: ${errorText}`); + client.notifyView('client-failed', { msg: errorText }, 'error', false); + } else { + console.error(`corpus_analysis_query: ${errorText}`); + client.notifyView('client-failed', { msg: errorText }, 'error'); } - console.error(`corpus_analysis_query: ${errorText}`); console.groupEnd(); } }); @@ -121,10 +126,11 @@ function recieveQueryData(type, client) { console.info('Added chunk data to results.data.'); console.groupEnd(); } else { + let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.group('corpus_analysis_query_results: Client failed recieving', 'the results via socket.on'); - let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.error(`corpus_analysis_query: ${errorText}`); + client.notifyView('client-failed', { msg: errorText }, 'error'); console.groupEnd(); } }); @@ -150,11 +156,12 @@ function recieveResultsData(type, client) { response.type]); console.groupEnd(); } else { + let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.group('Failed to recieve results data.'); console.error('corpus_analysis_inspect_match: Client failed to recieve', 'results data via socket.on'); - let errorText = `Error ${response.payload.code} - ${response.payload.msg}`; console.error(`corpus_analysis_inspect_match: ${errorText}`); + client.notifyView('client-failed', { msg: errorText }, 'error'); console.groupEnd(); } }); @@ -178,7 +185,7 @@ function recieveViewNotification(type, client) { default: console.error('Recieved unkown notification case identifier from View'); // do something to not crash the analysis session? - // maybe unnecessary + // maybe unnecessary? } }); } 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 ffedce8b..3981716e 100644 --- a/web/app/static/js/modules/corpus_analysis/view/ResultsView.js +++ b/web/app/static/js/modules/corpus_analysis/view/ResultsView.js @@ -54,6 +54,7 @@ class ResultsList extends List { this.addToSubResultsIdsToShow = new Set(); // If check button is pressed its corresponding data_index is saved in this set. The set is shown to the user. // notification listeners listening for client notifications (or other in the future?) this.notificationListeners = {}; + this.knownHTMLElements = new Set(); } /** @@ -84,23 +85,44 @@ class ResultsList extends List { */ getHTMLElements(arrayOfSelectors) { for (let selector of arrayOfSelectors) { - let element; - let elements; - if (selector.startsWith('#')) { - element = document.querySelector(selector); - } else { - elements = document.querySelectorAll(selector); - elements = [...elements]; + // Check if identified Element should be initialized as a modal. + let modalInit = false; + let options; + if (Array.isArray(selector)) { + selector = selector[0]; + modalInit = true; + options = selector[1]; } - let cleanKey = []; - selector = selector.replace(/_/g, '-'); - selector.match(/\w+/g).forEach((word) => { - let tmp = word[0].toUpperCase() + word.slice(1); - cleanKey.push(tmp); - }); - cleanKey[0] = cleanKey[0].toLowerCase(); - cleanKey = cleanKey.join(''); - this[cleanKey] = element ? element: elements; + // Check if the current selector has already been used. + if (this.knownHTMLElements.has(selector)) { + continue; + } else { + // Get element or elements. + let element; + let elements; + if (selector.startsWith('#')) { + element = document.querySelector(selector); + } else { + elements = document.querySelectorAll(selector); + elements = [...elements]; + } + // Create valid javascript instance field name. + let cleanKey = []; + selector = selector.replace(/_/g, '-'); + selector.match(/\w+/g).forEach((word) => { + let tmp = word[0].toUpperCase() + word.slice(1); + cleanKey.push(tmp); + }); + cleanKey[0] = cleanKey[0].toLowerCase(); + cleanKey = cleanKey.join(''); + this[cleanKey] = element ? element: elements; + // Initialize current element as modal if true. + if (modalInit) { + this[cleanKey] = M.Modal.init(this[cleanKey], options); + } + } + // Add current selector to knwonHTMLElements. + this.knownHTMLElements.add(selector); } } @@ -294,59 +316,16 @@ class ResultsList extends List { } // ### functions to inspect imported Matches - // This function creates an object that is similar to the object that is - // being recieved as an answere to the getMatchWithContext Method, which is - // triggering an socket.io event. - // It is used as an input for show match context in the context of imported - // results to be able to inspect matches. - createFakeResponse() { - contextModal.open(); - // match nr for user to display derived from data_index - let contextMatchNrElement = document.getElementById("context-match-nr"); - contextMatchNrElement.textContent = this.contextId + 1; - let cpos_lookup; - let fake_response = {}; - let contextResultsElement; - // function to create one match object from entire imported results - // that is passed into the results.jsList.showMatchContext() function - fake_response["payload"] = {}; - let dataIndex = event.target.closest("tr").dataset.index; - this.contextId = dataIndex; - fake_response.payload["matches"] = [results.data.matches[dataIndex]]; - contextResultsElement = document.getElementById("context-results"); - contextResultsElement.innerHTML = ""; - let {lc, c, rc} = this.helperCreateCpos(results.data.cpos_ranges, - fake_response.payload.matches[0]); - cpos_lookup = {}; - for (let cpos of lc) { - cpos_lookup[cpos] = results.data.cpos_lookup[cpos]; - } - for (let cpos of c) { - cpos_lookup[cpos] = results.data.cpos_lookup[cpos]; - } - for (let cpos of rc) { - cpos_lookup[cpos] = results.data.cpos_lookup[cpos]; - } - fake_response.payload["cpos_lookup"] = cpos_lookup - fake_response.payload["cpos_ranges"] = results.data.cpos_ranges; - fake_response.payload["query"] = results.data.query; - fake_response.payload["context_id"] = dataIndex + 1; - fake_response.payload["match_count"] = fake_response.payload.matches.length - fake_response.payload["corpus_type"] = "inspect-result" - return fake_response - } - // gets result cpos infos for dataIndexes (use list of length 1 for one match) to send back to // the server inspect(client, results, dataIndex, type) { // initialize context modal this.getHTMLElements([ - '#context-modal', + ['#context-modal', true], '#context-results', '#create-inspect-menu', '#create-from-inspect', ]); - this.contextModal = M.Modal.init(this.contextModal); // get result infos from server and show them in context modal this.contextId = dataIndex[0]; this.contextResults.innerHTML = ""; // clear it from old inspects @@ -552,9 +531,6 @@ class ResultsList extends List { toHideArray = []; toShowArray = array; } - // console.log(array); - // console.log("#######"); - // console.log(toHideArray); for (let s of toHideArray) { s.classList.add("hide"); } @@ -786,7 +762,7 @@ class ResultsList extends List {
Meta data Description | +Meta Data Description | Value |
---|