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 b1378831..6fc440f9 100644 --- a/web/app/static/js/modules/corpus_analysis/view/ResultsView.js +++ b/web/app/static/js/modules/corpus_analysis/view/ResultsView.js @@ -47,18 +47,13 @@ class ResultsList extends List { * expert view. Collected here to delete later on. */ this.currentExpertTokenElements = {}; - /** - * Holds True/false for check buttons used to add matches to sub-results. - * If checked, it is True. If unchecked, it is false. Buttons for this - * have the class add. The ittle round check buttons to add matches to sub - * results. - */ - this.addToSubResultsStatus = {}; /** - * If a check button is pressed its corresponding data_index is saved in - * this set. The set is shown to the user. + * Holds True/false for check buttons used to add matches to sub-results. + * If checked, it is True. If unchecked, it is false. Buttons for this + * have the class add. The ittle round check buttons to add matches to sub + * results. Key is match index. Value is true or false as mentioned above. */ - this.addToSubResultsIdsToShow = new Set(); + this.subResultsIndexes = {}; // ViewEventListeners listening for client notifications. this.notificationListeners = {}; this.knownHTMLElements = new Set(); @@ -78,6 +73,7 @@ class ResultsList extends List { resetFields() { this.addToSubResultsIdsToShow = new Set(); this.addToSubResultsStatus = {}; + this.subResultsIndexes = {}; } @@ -231,32 +227,37 @@ class ResultsList extends List { * removes it. */ addToSubResults(dataIndex, client, tableCall=true) { - if (!this.addToSubResultsStatus[dataIndex] - || this.addToSubResultsStatus === undefined) { - // add button is activated because status is either false or undefined + let toShowArray; + dataIndex = parseInt(dataIndex); + if (!this.subResultsIndexes[dataIndex] + || this.subResultsIndexes === undefined) { this.helperActivateAddBtn(event.target); - this.addToSubResultsStatus[dataIndex] = true; + this.subResultsIndexes[dataIndex] = true; + toShowArray = Object.keys(this.subResultsIndexes).map(index => parseInt(index)); // Add 1 because indexes are zero based. User sees 1 based numbering. - this.addToSubResultsIdsToShow.add(dataIndex + 1); + toShowArray = toShowArray.map(index => index + 1); // Allways sort the shown indexes for the user if new match is added. - this.subResultsMatchIds.textContent = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); - M.textareaAutoResize(this.subResultsMatchIds); - this.nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length; - } else if (this.addToSubResultsStatus[dataIndex]) { + toShowArray = toShowArray.sort(function(a, b){return a-b}); + this.subResultsIndexesDisplay.textContent = toShowArray.join(', '); + M.textareaAutoResize(this.subResultsIndexesDisplay); + this.nrMarkedMatches.textContent = Object.keys(this.subResultsIndexes).length; + } else if (this.subResultsIndexes[dataIndex]) { // add button is deactivated because status is true this.helperDeactivateAddBtn(event.target); - this.addToSubResultsStatus[dataIndex] = false; + delete this.subResultsIndexes[dataIndex]; + toShowArray = Object.keys(this.subResultsIndexes).map(index => parseInt(index)); // Add 1 because indexes are zero based. User sees 1 based numbering. - this.addToSubResultsIdsToShow.delete(dataIndex + 1); + toShowArray = toShowArray.map(index => index + 1); // Allways sort the shown indexes for the user if new match is added. - this.subResultsMatchIds.textContent = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); - this.nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length; - M.textareaAutoResize(this.subResultsMatchIds); + toShowArray = toShowArray.sort(function(a, b){return a-b}); + this.subResultsIndexesDisplay.textContent = toShowArray.join(', '); + this.nrMarkedMatches.textContent = Object.keys(this.subResultsIndexes).length; + M.textareaAutoResize(this.subResultsIndexesDisplay); } // Toggles create button according to the number of ids in addToSubResultsIdsToShow - if ([...this.addToSubResultsIdsToShow].length > 0 && !client.isBusy) { + if (Object.keys(this.subResultsIndexes).length > 0 && !client.isBusy) { this.subResultsCreate.classList.toggle('disabled', false); - } else if ([...this.addToSubResultsIdsToShow].length === 0) { + } else if (Object.keys(this.subResultsIndexes).length === 0) { this.subResultsCreate.classList.toggle('disabled', true); } /** @@ -338,7 +339,7 @@ class ResultsList extends List { if (client.dynamicMode) { // Notify Client to get results from server. this.notifyClient('get-results', {resultsType: 'inspect-results', - dataIndexes: [dataIndex], + dataIndexes: dataIndex, resultsList: this}); } else { // Gather results data from already present data. @@ -362,9 +363,9 @@ class ResultsList extends List { * Checks if the match has or has not been added to sub results yet. * Sets the color and status of the button accordingly. */ - if (this.addToSubResultsStatus[dataIndex[0]]) { + if (this.subResultsIndexes[dataIndex[0]]) { this.helperActivateAddBtn(addToSubResultsIdsBtn.firstElementChild); - } else if (!this.addToSubResultsStatus[dataIndex[0]]) { + } else if (!this.subResultsIndexes[dataIndex[0]]) { this.helperDeactivateAddBtn(addToSubResultsIdsBtn.firstElementChild); } this.createInspectMenu.innerHTML = ''; diff --git a/web/app/static/js/modules/corpus_analysis/view/callbacks.js b/web/app/static/js/modules/corpus_analysis/view/callbacks.js index eeb71f0d..786712e6 100644 --- a/web/app/static/js/modules/corpus_analysis/view/callbacks.js +++ b/web/app/static/js/modules/corpus_analysis/view/callbacks.js @@ -17,7 +17,7 @@ function disableElementsGeneralCallback(resultsList, detail) { function enableElementsGeneralCallback(resultsList, detail) { if (!detail.client.isBusy) { resultsList.fullResultsCreate.classList.toggle('disabled', false); - if (resultsList.addToSubResultsIdsToShow.size > 0) { + if (Object.keys(resultsList.subResultsIndexes).length > 0) { resultsList.subResultsCreate.classList.toggle('disabled', false); } resultsList.toggleInspectButtons(detail.client); @@ -80,7 +80,7 @@ function queryDataPreparingCallback(resultsList, detail) { '#query-results-user-feedback', '#query-progress-bar', '#query-results-create', - '#sub-results-match-ids', + '#sub-results-indexes-display', '#nr-marked-matches', ]); // show or enable some things for the user @@ -96,7 +96,7 @@ function queryDataPreparingCallback(resultsList, detail) { resultsList.textLookupTitles.textContent = ''; resultsList.textLookupCount.textContent = 0; resultsList.nrMarkedMatches.textContent = 0; - resultsList.subResultsMatchIds.textContent = ''; + resultsList.subResultsIndexesDisplay.textContent = ''; resultsList.resetFields(); } @@ -226,7 +226,7 @@ function resultsDataRecievedCallback(resultsList, detail) { resultsList.subResultsProgressBar.classList.toggle('hide', true); } } else if (detail.type ==='inspect-results') { - if (resultsList.addToSubResultsIdsToShow.size === 0) { + if (Object.keys(resultsList.subResultsIndexes).length === 0) { /** * Prevent create sub results button from being activated if it is disabled * and no matches have been marked by the user for sub results creation. diff --git a/web/app/templates/interactions/create.html.j2 b/web/app/templates/interactions/create.html.j2 index d2c8a798..4d4172b0 100644 --- a/web/app/templates/interactions/create.html.j2 +++ b/web/app/templates/interactions/create.html.j2 @@ -14,7 +14,7 @@ results.-->

matches added for sub-results:

-