Skip to content

Commit

Permalink
Merge pull request freeCodeCamp#4120 from terakilobyte/newFlags
Browse files Browse the repository at this point in the history
Adds 'new' callouts to top level challenge blocks
  • Loading branch information
ltegman committed Nov 3, 2015
2 parents 13ce0cc + 502f7f8 commit 0e4f85e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
25 changes: 20 additions & 5 deletions server/boot/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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
Expand All @@ -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 || '???'
Expand Down
12 changes: 12 additions & 0 deletions server/views/challengeMap/show.jade
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,31 @@ 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
.progress-bar(role='progressbar', aria-valuenow=(challengeBlock.completed), aria-valuemin='0', aria-valuemax='100', style='width: ' + challengeBlock.completed + '%;')
.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
Expand Down

0 comments on commit 0e4f85e

Please sign in to comment.