From 532825827f517c766ade6e7422f6832e72a0745a Mon Sep 17 00:00:00 2001 From: user Date: Fri, 6 Oct 2023 17:44:39 +0200 Subject: [PATCH 01/11] static percentage of fields that have state ok for contributor page#1247 --- .../static/peer_review/opr_contributor.js | 29 +++++++++++++++++-- .../templates/dataedit/opr_contributor.html | 4 +-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dataedit/static/peer_review/opr_contributor.js b/dataedit/static/peer_review/opr_contributor.js index c84cef122..7a16b915c 100644 --- a/dataedit/static/peer_review/opr_contributor.js +++ b/dataedit/static/peer_review/opr_contributor.js @@ -256,7 +256,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); @@ -336,6 +335,10 @@ function selectState(state) { // eslint-disable-line no-unused-vars } + + + + /** * Renders fields on the Summary page, sorted by review state */ @@ -614,6 +617,7 @@ function saveEntrances() { selectNextField(); renderSummaryPageFields(); updateTabProgressIndicatorClasses(); + updatePercentageDisplay(); } /** @@ -701,6 +705,23 @@ function updateTabProgressIndicatorClasses() { } } +function calculateOkPercentage(stateDict) { + let totalCount = Object.keys(stateDict).length; + let okCount = 0; + + for (let key in stateDict) { + if (stateDict[key] === 'ok') { + okCount++; + } + } + + return (okCount / totalCount) * 100; +} + +function updatePercentageDisplay() { + document.getElementById('percentageDisplay').textContent = calculateOkPercentage(state_dict).toFixed(2); +} + function updateTabClasses() { const tabNames = ['general', 'spatiotemporal', 'source', 'license', 'contributor', 'resource']; @@ -727,7 +748,11 @@ function updateTabClasses() { } } } -window.addEventListener('DOMContentLoaded', updateTabClasses); +window.addEventListener('DOMContentLoaded', function() { + updateTabClasses(); + updatePercentageDisplay(); +}); + /** diff --git a/dataedit/templates/dataedit/opr_contributor.html b/dataedit/templates/dataedit/opr_contributor.html index 791d73b66..5bf62b87a 100644 --- a/dataedit/templates/dataedit/opr_contributor.html +++ b/dataedit/templates/dataedit/opr_contributor.html @@ -46,7 +46,9 @@

+
+

Fields with "OK" state: %