From 2a8893b4e5dd3bfebbf7d732f4d0521dc9140b87 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 6 Oct 2023 18:33:51 +0200 Subject: [PATCH] dynamic percentage of fields that have state ok for contributor page #1247 --- .../static/peer_review/opr_contributor.js | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/dataedit/static/peer_review/opr_contributor.js b/dataedit/static/peer_review/opr_contributor.js index 65c0ff7d2..5d27d94cf 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(); } /** @@ -332,9 +333,19 @@ 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; + } +} @@ -705,23 +716,6 @@ 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']; @@ -753,6 +747,23 @@ window.addEventListener('DOMContentLoaded', function() { updatePercentageDisplay() ; }); +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() { + const percentage = calculateOkPercentage(state_dict); + document.getElementById("percentageDisplay").textContent = percentage.toFixed(2); +} /**