diff --git a/dataedit/static/peer_review/opr_contributor.js b/dataedit/static/peer_review/opr_contributor.js index c3ceda330..3f7834b2b 100644 --- a/dataedit/static/peer_review/opr_contributor.js +++ b/dataedit/static/peer_review/opr_contributor.js @@ -132,6 +132,7 @@ function peerReview(config) { selectNextField(); renderSummaryPageFields(); updateTabProgressIndicatorClasses(); + updatePercentageDisplay(); } /** @@ -260,7 +261,6 @@ function clearInputFields() { function switchCategoryTab(category) { const currentTab = document.querySelector('.tab-pane.active'); // Get the currently active tab const tabIdForCategory = getCategoryToTabIdMapping()[category]; - console.log("tabID", tabIdForCategory); if (currentTab.getAttribute('id') !== tabIdForCategory) { // The clicked field does not belong to the current tab, switch to the next tab const targetTab = document.getElementById(tabIdForCategory); @@ -337,8 +337,25 @@ function selectField(fieldList, field) { */ function selectState(state) { // eslint-disable-line no-unused-vars selectedState = state; + updateClientStateDict(fieldKey = selectedField, state = state); } +function updateClientStateDict(fieldKey, state) { + state_dict = state_dict ?? {}; + if (fieldKey in state_dict) { + // console.log(`Der Schlüssel '${fieldKey}' ist vorhanden.`); + state_dict[fieldKey] = state; + } else { + // console.log(`Der Schlüssel '${fieldKey}' ist nicht vorhanden.`); + state_dict[fieldKey] = state; + } +} + + + + + + /** * Renders fields on the Summary page, sorted by review state */ @@ -621,6 +638,7 @@ function saveEntrances() { selectNextField(); renderSummaryPageFields(); updateTabProgressIndicatorClasses(); + updatePercentageDisplay() ; } /** @@ -736,7 +754,32 @@ function updateTabClasses() { } } } -window.addEventListener('DOMContentLoaded', updateTabClasses); +window.addEventListener('DOMContentLoaded', function() { + updateTabClasses(); + updatePercentageDisplay() ; +}); + +function calculateOkPercentage(stateDict) { + let totalCount = 0; + let okCount = 0; + + for (let key in stateDict) { + let fieldValue = $(document.getElementById(`field_${key}`)).find('.value').text().replace(/\s+/g, ' ').trim(); + if (!isEmptyValue(fieldValue)) { + totalCount++; + if (stateDict[key] === "ok") { + okCount++; + } + } + } + + return totalCount === 0 ? 0 : (okCount / totalCount) * 100; +} + +function updatePercentageDisplay() { + const percentage = calculateOkPercentage(state_dict); + document.getElementById("percentageDisplay").textContent = percentage.toFixed(2); +} /** diff --git a/dataedit/static/peer_review/opr_reviewer.js b/dataedit/static/peer_review/opr_reviewer.js index 33f8f538f..b8927551b 100644 --- a/dataedit/static/peer_review/opr_reviewer.js +++ b/dataedit/static/peer_review/opr_reviewer.js @@ -140,7 +140,7 @@ function peerReview(config) { selectNextField(); renderSummaryPageFields(); updateTabProgressIndicatorClasses(); - // updatePercentageDisplay(); + updatePercentageDisplay(); if (state_dict) { check_if_review_finished(); } @@ -555,6 +555,7 @@ function renderSummaryPageFields() { updateSummaryTable(); updateTabProgressIndicatorClasses(); + updatePercentageDisplay(); } /** @@ -722,8 +723,9 @@ function saveEntrances() { renderSummaryPageFields(); updateTabProgressIndicatorClasses(); - // updatePercentageDisplay(); + updatePercentageDisplay(); } + function getFieldState(fieldKey) { if (state_dict && state_dict[fieldKey] !== undefined) { return state_dict[fieldKey]; @@ -918,29 +920,34 @@ function updateTabClasses() { window.addEventListener('DOMContentLoaded', function() { - updateTabClasses(); - // updatePercentageDisplay() ; + updateTabClasses(); + updatePercentageDisplay() ; + updateTabClasses(); }); + function getTotalFieldCount() { var allFields = makeFieldList(); return allFields.length; } - function calculateOkPercentage(stateDict) { - let totalCount = getTotalFieldCount(); + let totalCount = 0; let okCount = 0; for (let key in stateDict) { - if (stateDict[key] === "ok") { - okCount++; + let fieldValue = $(document.getElementById(`field_${key}`)).find('.value').text().replace(/\s+/g, ' ').trim(); + if (!isEmptyValue(fieldValue)) { + totalCount++; + if (stateDict[key] === "ok") { + okCount++; + } } } - let percentage = (okCount / totalCount) * 100; + let percentage = totalCount === 0 ? 0 : (okCount / totalCount) * 100; return percentage.toFixed(2); } diff --git a/dataedit/templates/dataedit/opr_contributor.html b/dataedit/templates/dataedit/opr_contributor.html index 683ce9a00..897977d05 100644 --- a/dataedit/templates/dataedit/opr_contributor.html +++ b/dataedit/templates/dataedit/opr_contributor.html @@ -46,7 +46,9 @@
Fields with "OK" state: %