Rework query_results/inspect template to load listeners from view listeners.

This commit is contained in:
Stephan Porada 2020-10-08 09:25:06 +02:00
parent 20074ebeae
commit 5961a3f843
2 changed files with 43 additions and 20 deletions

View File

@ -247,7 +247,7 @@ document.addEventListener("DOMContentLoaded", () => {
'#sub-results-export', '#sub-results-export',
'#export-full-inspect-context', '#export-full-inspect-context',
]); ]);
let args = [resultsList, results, client] let args = [resultsList, results, client];
const listenForPageNavigation = new ViewEventListener('page-navigation', const listenForPageNavigation = new ViewEventListener('page-navigation',
pageNavigation, pageNavigation,
args); args);
@ -284,7 +284,7 @@ document.addEventListener("DOMContentLoaded", () => {
const listenForExportSingleMatch = new ViewEventListener('export-single-match', const listenForExportSingleMatch = new ViewEventListener('export-single-match',
exportSingleMatch, exportSingleMatch,
args); args);
// Set and load define listeners // Set and load defined listeners
resultsList.setViewEventListeners([ resultsList.setViewEventListeners([
listenForClientNotification, listenForClientNotification,
listenForPageNavigation, listenForPageNavigation,

View File

@ -100,20 +100,19 @@ import {
} from '../../static/js/modules/corpus_analysis/view/ResultsView.js'; } from '../../static/js/modules/corpus_analysis/view/ResultsView.js';
// Import listener which will be registered to the ViewEventListener class. // Import listener which will be registered to the ViewEventListener class.
import { import {
// listener listening for client dispatched 'notify-vie' custom event.
recieveClientNotification, recieveClientNotification,
} from '../../static/js/modules/corpus_analysis/view/listeners.js'; // vanilla javascript Event listeners which are listening for button clicks.
import {
scrollToTop,
} from '../../static/js/modules/corpus_analysis/view/scrollToTop.js'
// vanilla javascript Event listeners which are listening for button clicks etc
import {
pageNavigation, pageNavigation,
expertModeSwitch, expertModeSwitch,
actionButtons, actionButtons,
displayOptions, displayOptions,
showMetaData, showMetaData,
showCorpusFiles, showCorpusFiles,
} from '../../static/js/modules/corpus_analysis/view/eventListeners.js'; } from '../../static/js/modules/corpus_analysis/view/listeners.js';
import {
scrollToTop,
} from '../../static/js/modules/corpus_analysis/view/scrollToTop.js'
/** /**
* Second Phase: * Second Phase:
* Asynchronus and event driven code. * Asynchronus and event driven code.
@ -162,9 +161,11 @@ document.addEventListener("DOMContentLoaded", () => {
*/ */
const listenForClientNotification = new ViewEventListener('notify-view', const listenForClientNotification = new ViewEventListener('notify-view',
recieveClientNotification); recieveClientNotification);
resultsList.setViewEventListeners([listenForClientNotification]); /**
resultsList.loadViewEventListeners(); * Register vanilla Javascript events to the resultList listening for button
// Get all needed HTMLElements for the following event listeners. * clicks etc. done by the user.
* Get all needed HTMLElements for those event listeners before.
*/
resultsList.getHTMLElements([ resultsList.getHTMLElements([
'.add-btn', '.add-btn',
'.pagination', '.pagination',
@ -196,6 +197,36 @@ document.addEventListener("DOMContentLoaded", () => {
'#sub-results-create', '#sub-results-create',
'#sub-results-export', '#sub-results-export',
]); ]);
let args = [resultsList, results, client];
const listenForPageNavigation = new ViewEventListener('page-navigation',
pageNavigation,
args);
const listenForExpertModeSwitch = new ViewEventListener('expert-mode',
expertModeSwitch,
args);
const listenForActionButtons = new ViewEventListener('action-buttons',
actionButtons,
args);
const listenForDisplayOptions = new ViewEventListener('display-otions',
displayOptions,
args);
const listenForShowMetaData = new ViewEventListener('show-meta-data',
showMetaData,
args);
const listenForShowCorpusFiles = new ViewEventListener('show-corpus-files',
showCorpusFiles,
args);
// Set and load defined listeners
resultsList.setViewEventListeners([
listenForClientNotification,
listenForPageNavigation,
listenForExpertModeSwitch,
listenForActionButtons,
listenForDisplayOptions,
listenForShowMetaData,
listenForShowCorpusFiles,
]);
resultsList.loadViewEventListeners();
// Hide buttons which are not needed when just inspecting results // Hide buttons which are not needed when just inspecting results
resultsList.inspectResultsExport.classList.add('hide'); resultsList.inspectResultsExport.classList.add('hide');
// Execute client event listener callbacks manually because dynamicMode is false // Execute client event listener callbacks manually because dynamicMode is false
@ -203,14 +234,6 @@ document.addEventListener("DOMContentLoaded", () => {
// Save meta data to results after the init callback from line above // Save meta data to results after the init callback from line above
results.metaData = metaDataJson; results.metaData = metaDataJson;
client.eventListeners['corpus_analysis_query_results'].executeCallbacks([resultsJson]); client.eventListeners['corpus_analysis_query_results'].executeCallbacks([resultsJson]);
// Call the vanilla event listeners listening for clicks etc. from the user.
pageNavigation(resultsList, results, client);
expertModeSwitch(resultsList, results);
actionButtons(resultsList, results, client);
displayOptions(resultsList, results, client);
showMetaData(resultsList, results);
showCorpusFiles(resultsList, results);
// Enable scroll to Top functionality. // Enable scroll to Top functionality.
scrollToTop('#headline', '#menu-scroll-to-top-div'); scrollToTop('#headline', '#menu-scroll-to-top-div');
}); });