mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-26 10:36:39 -05:00
feat: add global completion percentage in home
This commit is contained in:
@@ -34,9 +34,49 @@ router.get('/', async (request, response) => {
|
||||
second: specialThanksSecondRow.concat(specialThanksSecondRow).concat(specialThanksSecondRow)
|
||||
};
|
||||
|
||||
// Progress
|
||||
|
||||
// Creates an object to hold the total progress
|
||||
const totalProgress = {
|
||||
title: null,
|
||||
_calc: {
|
||||
percentageSum: 0
|
||||
},
|
||||
percent: 0,
|
||||
progress: {
|
||||
not_started: [],
|
||||
started: [],
|
||||
completed: []
|
||||
}
|
||||
};
|
||||
|
||||
// Calculates individual completion percentages and progress states
|
||||
cache.sections.forEach(section => {
|
||||
const { not_started, started, completed } = section.progress;
|
||||
|
||||
const sectionCompletionPercentage = completed.length / (completed.length + started.length + not_started.length);
|
||||
totalProgress._calc.percentageSum += sectionCompletionPercentage;
|
||||
|
||||
const sectionTitle = `${section.title} [${Math.round(sectionCompletionPercentage * 100)}%]`;
|
||||
|
||||
if (completed !== [] && started + not_started === []) {
|
||||
// if all the section tasks have been completed, push to completed
|
||||
totalProgress.progress.completed.push(sectionTitle);
|
||||
} else if (not_started !== [] && started + completed === []) {
|
||||
// if none the section tasks have been completed or started, push to not started
|
||||
totalProgress.progress.not_started.push(sectionTitle);
|
||||
} else {
|
||||
// for all other combos, push to started
|
||||
totalProgress.progress.started.push(sectionTitle);
|
||||
}
|
||||
});
|
||||
|
||||
// Calculates global completion percentage
|
||||
totalProgress.percent = Math.round(totalProgress._calc.percentageSum / cache.sections.length * 100);
|
||||
|
||||
response.render('home', {
|
||||
layout: 'main',
|
||||
featuredFeatureList: cache.sections[0],
|
||||
featuredFeatureList: totalProgress,
|
||||
boards,
|
||||
locale,
|
||||
localeString: reqLocale.toString(),
|
||||
|
||||
Reference in New Issue
Block a user