From 10ac3de62d442aaadd45ce40f2cf3f4d41d498e5 Mon Sep 17 00:00:00 2001 From: Ash Monty Date: Thu, 9 Jun 2022 15:42:30 +0200 Subject: [PATCH] feat: add global completion percentage in home --- public/assets/js/progress-charts.js | 4 ++- src/routers/home.js | 42 ++++++++++++++++++++++++- views/partials/progress-list.handlebars | 6 ++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/public/assets/js/progress-charts.js b/public/assets/js/progress-charts.js index a85ec22..cca71f3 100644 --- a/public/assets/js/progress-charts.js +++ b/public/assets/js/progress-charts.js @@ -2,10 +2,12 @@ document.querySelectorAll('.feature-list-wrapper').forEach(progressListElement => { // Find and generate all relevant data + const percentageOverride = progressListElement.querySelector('canvas.percentage-chart').dataset.percentageoverride; const allFeatureNodes = progressListElement.querySelectorAll('.feature'); const allDoneFeatureNodes = progressListElement.querySelectorAll('.feature .done'); - const progressPercentage = Math.round(Math.min((allDoneFeatureNodes.length / allFeatureNodes.length) * 100, 100)); + // Use percentage override data attribute if present, else calculate + const progressPercentage = Math.round(percentageOverride) || Math.round(Math.min((allDoneFeatureNodes.length / allFeatureNodes.length) * 100, 100)); const remainingPercentage = 100 - progressPercentage; // Set inner paragraph diff --git a/src/routers/home.js b/src/routers/home.js index 0cde004..121d58a 100644 --- a/src/routers/home.js +++ b/src/routers/home.js @@ -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(), diff --git a/views/partials/progress-list.handlebars b/views/partials/progress-list.handlebars index 7d06b36..a6ab725 100644 --- a/views/partials/progress-list.handlebars +++ b/views/partials/progress-list.handlebars @@ -3,12 +3,12 @@

{{ data.percent }}

- +
-
+ {{#if data.title}}

{{ data.title }}

{{#if data.id}}{{#if (lookup boards data.id)}}{{#with (lookup boards data.id) as | board |}} {{#each board.github_links}} @@ -20,7 +20,7 @@
{{/each}} {{/with}}{{/if}}{{/if}} -
+
{{/if}}
{{#each data.progress.completed}}