Adds 'new' callouts to top level challenge block links if all challenges

all challenges in that block are new.
This commit is contained in:
terakilobyte
2015-11-01 19:36:28 -08:00
parent c30f7f0795
commit 502f7f83ba
2 changed files with 32 additions and 5 deletions

View File

@ -517,6 +517,24 @@ module.exports = function(app) {
}
function challengeMap({ user = {} }, res, next) {
// small helper function to determine whether to mark something as new
function shouldShowNew(element, block) {
if (element) {
return (typeof element.releasedOn !== 'undefined' &&
moment(element.releasedOn, 'MMM MMMM DD, YYYY')
.diff(moment(), 'days') >= -30);
} else if (block) {
const newCount = block.reduce((sum, { markNew }) => {
if (markNew) {
return sum + 1;
}
return sum;
}, 0);
return newCount / block.length * 100 === 100;
}
}
let lastCompleted;
const daysRunning = moment().diff(new Date('10/15/2014'), 'days');
@ -537,11 +555,7 @@ module.exports = function(app) {
if (completedChallenges.indexOf(challenge.id) !== -1) {
challenge.completed = true;
}
if (typeof challenge.releasedOn !== 'undefined' &&
moment(challenge.releasedOn, 'MMM MMMM DD, YYYY').diff(moment(),
'days') >= -30) {
challenge.markNew = true;
}
challenge.markNew = shouldShowNew(challenge);
return challenge;
})
// group challenges by block | returns a stream of observables
@ -561,6 +575,7 @@ module.exports = function(app) {
isBeta,
name: blockArray[0].block,
dashedName: dasherize(blockArray[0].block),
markNew: shouldShowNew(null, blockArray),
challenges: blockArray,
completed: completedCount / blockArray.length * 100,
time: blockArray[0] && blockArray[0].time || '???'

View File

@ -53,6 +53,10 @@ block content
.col-xs-12.col-sm-9.col-md-10
li.map-p.faded.negative-10
a(href='#' + challengeBlock.dashedName)= challengeBlock.name
if challengeBlock.markNew
span.text-danger.small    
strong
em NEW
else
.hidden-xs.col-sm-3.col-md-2
.progress.progress-bar-padding.text-center.thin-progress-bar
@ -60,12 +64,20 @@ block content
.col-xs-12.col-sm-9.col-md-10
li.map-p.negative-10
a(href='#' + challengeBlock.dashedName)= challengeBlock.name
if challengeBlock.markNew
span.text-danger.small    
strong
em NEW
else
.hidden-xs.col-sm-3.col-md-2
span.negative-10
.col-xs-12.col-sm-9.col-md-10
li.map-p.negative-10
a(href='#' + challengeBlock.dashedName)= challengeBlock.name
if challengeBlock.markNew
span.text-danger.small    
strong
em NEW
.row
.col-xs-12.col-sm-8.col-sm-offset-2.negative-28