From e49ead52389b977a7effa2e854d42b33986aec32 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 19 Aug 2024 18:07:41 +0200 Subject: [PATCH] Fix the bug that causes the same field to be displayed twice #1798 --- .../static/peer_review/opr_contributor.js | 20 +++++++---- dataedit/static/peer_review/opr_reviewer.js | 36 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/dataedit/static/peer_review/opr_contributor.js b/dataedit/static/peer_review/opr_contributor.js index c3ceda330..e2c5b9d6d 100644 --- a/dataedit/static/peer_review/opr_contributor.js +++ b/dataedit/static/peer_review/opr_contributor.js @@ -351,6 +351,8 @@ function renderSummaryPageFields() { const missingFields = []; const emptyFields = []; + const processedFields = new Set(); + if (state_dict && Object.keys(state_dict).length > 0) { const fields = document.querySelectorAll('.field'); for (let field of fields) { @@ -359,10 +361,13 @@ function renderSummaryPageFields() { const fieldState = getFieldState(field_id); const fieldCategory = field.getAttribute('data-category'); const fieldName = field_id.split('.').pop(); + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; if (isEmptyValue(fieldValue)) { emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" }); + processedFields.add(uniqueFieldIdentifier); } else if (fieldState === 'ok') { acceptedFields.push({ fieldName, fieldValue, fieldCategory }); + processedFields.add(uniqueFieldIdentifier); } } } @@ -374,6 +379,12 @@ function renderSummaryPageFields() { const isRejected = review.fieldReview.some((fieldReview) => fieldReview.state === 'rejected'); const fieldCategory = review.category; const fieldName = review.key.split('.').pop(); + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; + + if (processedFields.has(uniqueFieldIdentifier)) { + continue; // Skipp fields that have already been processed from state_dict + } + if (isEmptyValue(fieldValue)) { emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" }); @@ -400,11 +411,13 @@ function renderSummaryPageFields() { const fieldState = getFieldState(field_id); const fieldCategory = field.getAttribute('data-category'); const fieldName = field_id.split('.').pop(); + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; - if (isEmptyValue(fieldValue)) { + if (isEmptyValue(fieldValue) && !processedFields.has(uniqueFieldIdentifier)) { emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" }); } else if (!found && fieldState !== 'ok') { missingFields.push({ fieldName, fieldValue, fieldCategory }); + processedFields.add(uniqueFieldIdentifier); } } } @@ -742,8 +755,6 @@ window.addEventListener('DOMContentLoaded', updateTabClasses); /** * Hide and show revier controles once the user clicks the summary tab */ -console.log('Script is running...'); - document.addEventListener('DOMContentLoaded', function() { // console.log('DOM fully loaded and parsed'); @@ -756,9 +767,6 @@ document.addEventListener('DOMContentLoaded', function() { ]; const reviewContent = document.querySelector(".review__content"); - console.log('Summary Tab:', summaryTab); - console.log('Other Tabs:', otherTabs); - console.log('Review Content:', reviewContent); if (summaryTab && reviewContent) { summaryTab.addEventListener('click', function() { diff --git a/dataedit/static/peer_review/opr_reviewer.js b/dataedit/static/peer_review/opr_reviewer.js index 059e395a3..29f9bb180 100644 --- a/dataedit/static/peer_review/opr_reviewer.js +++ b/dataedit/static/peer_review/opr_reviewer.js @@ -424,6 +424,8 @@ function renderSummaryPageFields() { const missingFields = []; const emptyFields = []; + const processedFields = new Set(); + if (state_dict && Object.keys(state_dict).length > 0) { const fields = document.querySelectorAll('.field'); for (let field of fields) { @@ -432,15 +434,16 @@ function renderSummaryPageFields() { const fieldState = getFieldState(field_id); const fieldCategory = field.getAttribute('data-category'); const fieldName = field_id.split('.').pop(); + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; if (isEmptyValue(fieldValue)) { emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" }); } else if (fieldState === 'ok') { acceptedFields.push({ fieldName, fieldValue, fieldCategory }); - } else if (fieldState === 'suggestion') { - suggestingFields.push({ fieldName, fieldValue, fieldCategory }); - } else if (fieldState === 'rejected') { - rejectedFields.push({ fieldName, fieldValue, fieldCategory }); + processedFields.add(uniqueFieldIdentifier); + } else { + missingFields.push({ fieldName, fieldValue, fieldCategory }); + processedFields.add(uniqueFieldIdentifier); } } } @@ -451,7 +454,11 @@ function renderSummaryPageFields() { const fieldState = review.fieldReview.state; const fieldCategory = review.category; const fieldName = review.key.split('.').pop(); + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; + if (processedFields.has(uniqueFieldIdentifier)) { + continue; // Skipp fields that have already been processed from state_dict + } if (isEmptyValue(fieldValue)) { emptyFields.push({ fieldName, fieldValue, fieldCategory: "emptyFields" }); @@ -480,13 +487,15 @@ function renderSummaryPageFields() { const fieldState = getFieldState(field_id); const fieldCategory = field.getAttribute('data-category'); const fieldName = field_id.split('.').pop(); - if (!found && fieldState !== 'ok' && !isEmptyValue(fieldValue)) { + const uniqueFieldIdentifier = `${fieldName}-${fieldCategory}`; + + if (!found && fieldState !== 'ok' && !isEmptyValue(fieldValue) && !processedFields.has(uniqueFieldIdentifier)) { missingFields.push({ fieldName, fieldValue, fieldCategory }); + processedFields.add(uniqueFieldIdentifier); } } } - // Display fields on the Summary page const summaryContainer = document.getElementById("summary"); @@ -495,6 +504,7 @@ function renderSummaryPageFields() { summaryContainer.firstChild.remove(); } } + function generateTable(data) { let table = document.createElement('table'); table.className = 'table review-summary'; @@ -539,15 +549,14 @@ function renderSummaryPageFields() { return table; } - - function updateSummaryTable() { + function updateSummaryTable() { clearSummaryTable(); let allData = []; - allData.push(...missingFields.map((item) => ({...item, fieldStatus: 'Missing'}))); - allData.push(...acceptedFields.map((item) => ({...item, fieldStatus: 'Accepted'}))); - allData.push(...suggestingFields.map((item) => ({...item, fieldStatus: 'Suggested'}))); - allData.push(...rejectedFields.map((item) => ({...item, fieldStatus: 'Rejected'}))); - allData.push(...emptyFields.map((item) => ({...item, fieldStatus: 'Empty'}))); + allData.push(...missingFields.map((item) => ({ ...item, fieldStatus: 'Missing' }))); + allData.push(...acceptedFields.map((item) => ({ ...item, fieldStatus: 'Accepted' }))); + allData.push(...suggestingFields.map((item) => ({ ...item, fieldStatus: 'Suggested' }))); + allData.push(...rejectedFields.map((item) => ({ ...item, fieldStatus: 'Rejected' }))); + allData.push(...emptyFields.map((item) => ({ ...item, fieldStatus: 'Empty' }))); let table = generateTable(allData); summaryContainer.appendChild(table); @@ -557,6 +566,7 @@ function renderSummaryPageFields() { updateTabProgressIndicatorClasses(); } + /** * Creates an HTML list of fields with their categories * @param {Array} fields Array of field objects