Skip to content

Commit

Permalink
dynamic percentage of fields that have state ok for contributor page #…
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Oct 6, 2023
1 parent 27891e7 commit 2a8893b
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions dataedit/static/peer_review/opr_contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function peerReview(config) {
selectNextField();
renderSummaryPageFields();
updateTabProgressIndicatorClasses();
updatePercentageDisplay();
}

/**
Expand Down Expand Up @@ -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;
}
}



Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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);
}


/**
Expand Down

0 comments on commit 2a8893b

Please sign in to comment.