Simplify addToSubResults().

This commit is contained in:
Stephan Porada 2020-09-24 16:13:16 +02:00
parent 3cb71c2acb
commit 28213574f4
3 changed files with 35 additions and 34 deletions

View File

@ -47,18 +47,13 @@ class ResultsList extends List {
* expert view. Collected here to delete later on. * expert view. Collected here to delete later on.
*/ */
this.currentExpertTokenElements = {}; 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 * Holds True/false for check buttons used to add matches to sub-results.
* this set. The set is shown to the user. * 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. // ViewEventListeners listening for client notifications.
this.notificationListeners = {}; this.notificationListeners = {};
this.knownHTMLElements = new Set(); this.knownHTMLElements = new Set();
@ -78,6 +73,7 @@ class ResultsList extends List {
resetFields() { resetFields() {
this.addToSubResultsIdsToShow = new Set(); this.addToSubResultsIdsToShow = new Set();
this.addToSubResultsStatus = {}; this.addToSubResultsStatus = {};
this.subResultsIndexes = {};
} }
@ -231,32 +227,37 @@ class ResultsList extends List {
* removes it. * removes it.
*/ */
addToSubResults(dataIndex, client, tableCall=true) { addToSubResults(dataIndex, client, tableCall=true) {
if (!this.addToSubResultsStatus[dataIndex] let toShowArray;
|| this.addToSubResultsStatus === undefined) { dataIndex = parseInt(dataIndex);
// add button is activated because status is either false or undefined if (!this.subResultsIndexes[dataIndex]
|| this.subResultsIndexes === undefined) {
this.helperActivateAddBtn(event.target); 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. // 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. // 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(", "); toShowArray = toShowArray.sort(function(a, b){return a-b});
M.textareaAutoResize(this.subResultsMatchIds); this.subResultsIndexesDisplay.textContent = toShowArray.join(', ');
this.nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length; M.textareaAutoResize(this.subResultsIndexesDisplay);
} else if (this.addToSubResultsStatus[dataIndex]) { this.nrMarkedMatches.textContent = Object.keys(this.subResultsIndexes).length;
} else if (this.subResultsIndexes[dataIndex]) {
// add button is deactivated because status is true // add button is deactivated because status is true
this.helperDeactivateAddBtn(event.target); 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. // 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. // 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(", "); toShowArray = toShowArray.sort(function(a, b){return a-b});
this.nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length; this.subResultsIndexesDisplay.textContent = toShowArray.join(', ');
M.textareaAutoResize(this.subResultsMatchIds); this.nrMarkedMatches.textContent = Object.keys(this.subResultsIndexes).length;
M.textareaAutoResize(this.subResultsIndexesDisplay);
} }
// Toggles create button according to the number of ids in addToSubResultsIdsToShow // 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); 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); this.subResultsCreate.classList.toggle('disabled', true);
} }
/** /**
@ -338,7 +339,7 @@ class ResultsList extends List {
if (client.dynamicMode) { if (client.dynamicMode) {
// Notify Client to get results from server. // Notify Client to get results from server.
this.notifyClient('get-results', {resultsType: 'inspect-results', this.notifyClient('get-results', {resultsType: 'inspect-results',
dataIndexes: [dataIndex], dataIndexes: dataIndex,
resultsList: this}); resultsList: this});
} else { } else {
// Gather results data from already present data. // 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. * Checks if the match has or has not been added to sub results yet.
* Sets the color and status of the button accordingly. * Sets the color and status of the button accordingly.
*/ */
if (this.addToSubResultsStatus[dataIndex[0]]) { if (this.subResultsIndexes[dataIndex[0]]) {
this.helperActivateAddBtn(addToSubResultsIdsBtn.firstElementChild); this.helperActivateAddBtn(addToSubResultsIdsBtn.firstElementChild);
} else if (!this.addToSubResultsStatus[dataIndex[0]]) { } else if (!this.subResultsIndexes[dataIndex[0]]) {
this.helperDeactivateAddBtn(addToSubResultsIdsBtn.firstElementChild); this.helperDeactivateAddBtn(addToSubResultsIdsBtn.firstElementChild);
} }
this.createInspectMenu.innerHTML = ''; this.createInspectMenu.innerHTML = '';

View File

@ -17,7 +17,7 @@ function disableElementsGeneralCallback(resultsList, detail) {
function enableElementsGeneralCallback(resultsList, detail) { function enableElementsGeneralCallback(resultsList, detail) {
if (!detail.client.isBusy) { if (!detail.client.isBusy) {
resultsList.fullResultsCreate.classList.toggle('disabled', false); 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.subResultsCreate.classList.toggle('disabled', false);
} }
resultsList.toggleInspectButtons(detail.client); resultsList.toggleInspectButtons(detail.client);
@ -80,7 +80,7 @@ function queryDataPreparingCallback(resultsList, detail) {
'#query-results-user-feedback', '#query-results-user-feedback',
'#query-progress-bar', '#query-progress-bar',
'#query-results-create', '#query-results-create',
'#sub-results-match-ids', '#sub-results-indexes-display',
'#nr-marked-matches', '#nr-marked-matches',
]); ]);
// show or enable some things for the user // show or enable some things for the user
@ -96,7 +96,7 @@ function queryDataPreparingCallback(resultsList, detail) {
resultsList.textLookupTitles.textContent = ''; resultsList.textLookupTitles.textContent = '';
resultsList.textLookupCount.textContent = 0; resultsList.textLookupCount.textContent = 0;
resultsList.nrMarkedMatches.textContent = 0; resultsList.nrMarkedMatches.textContent = 0;
resultsList.subResultsMatchIds.textContent = ''; resultsList.subResultsIndexesDisplay.textContent = '';
resultsList.resetFields(); resultsList.resetFields();
} }
@ -226,7 +226,7 @@ function resultsDataRecievedCallback(resultsList, detail) {
resultsList.subResultsProgressBar.classList.toggle('hide', true); resultsList.subResultsProgressBar.classList.toggle('hide', true);
} }
} else if (detail.type ==='inspect-results') { } 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 * 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. * and no matches have been marked by the user for sub results creation.

View File

@ -14,7 +14,7 @@ results.-->
<div class="col s12"> <div class="col s12">
<div class="input-field"> <div class="input-field">
<p><span id="nr-marked-matches"></span> matches added for sub-results:</p> <p><span id="nr-marked-matches"></span> matches added for sub-results:</p>
<textarea id="sub-results-match-ids" <textarea id="sub-results-indexes-display"
class="materialize-textarea" class="materialize-textarea"
disabled> disabled>
</textarea> </textarea>