From eb3f993b3b032a1cb463ccdd012b5ed4325c9e4f Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Sun, 12 Jul 2015 12:57:45 -0700 Subject: [PATCH] update split field guide view into categories --- server/boot/fieldGuide.js | 26 +++++++++++++++++++++- server/utils/index.js | 3 ++- server/views/field-guide/all-articles.jade | 4 +++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/boot/fieldGuide.js b/server/boot/fieldGuide.js index 91e6ff927c..62a5a61fbd 100644 --- a/server/boot/fieldGuide.js +++ b/server/boot/fieldGuide.js @@ -88,9 +88,33 @@ module.exports = function(app) { completedFieldGuides = req.user.completedFieldGuides; } + // order here determine order on page + const categories = [ + 'orientation', + 'FYI', + 'outreach', + 'contact' + ]; + + // produces an array of arrays of field guides ordered by the above + // i.e. [[...orientFieldGuides][...FYIfieldGuides]...] + const orderFieldGuides = categories + .reduce((ordered, category) => { + + const fieldGuidesForCategory = allFieldGuideNamesAndIds + .filter(fieldGuide => { + return category === fieldGuide.category; + }); + + return ordered.concat([fieldGuidesForCategory]); + }, []); + res.render('field-guide/all-articles', { + // leaving this property as legacy. allFieldGuideNamesAndIds: allFieldGuideNamesAndIds, - completedFieldGuides: completedFieldGuides + completedFieldGuides: completedFieldGuides, + categories: categories, + fieldGuides: orderFieldGuides }); } diff --git a/server/utils/index.js b/server/utils/index.js index 9f2ff3dcc9..b7c7be34dc 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -181,7 +181,8 @@ module.exports = { return { name: elem.name, dashedName: elem.dashedName, - id: elem.id + id: elem.id, + category: elem.category }; }); return allFieldGuideNames; diff --git a/server/views/field-guide/all-articles.jade b/server/views/field-guide/all-articles.jade index 882bccd44a..309bde7be6 100644 --- a/server/views/field-guide/all-articles.jade +++ b/server/views/field-guide/all-articles.jade @@ -9,9 +9,11 @@ block content .panel-body .col-xs-12.col-md-10.col-md-offset-1 .col-xs-12.no-right-padding + each category, index in categories + h2.text-center= category.charAt(0).toUpperCase() + category.slice(1) h3 ol - each fieldGuide in allFieldGuideNamesAndIds + each fieldGuide in fieldGuides[index] if completedFieldGuides.indexOf(fieldGuide.id) > -1 .row .hidden-xs.col-sm-3.col-md-2.text-primary.ion-checkmark-circled.padded-ionic-icon.text-center