Skip to content

Commit

Permalink
Add stats to about page
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jan 15, 2016
1 parent a6c4ed7 commit 918ea56
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
37 changes: 37 additions & 0 deletions server/boot/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import dedent from 'dedent';
import moment from 'moment';

import { observeMethod } from '../utils/rx';

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

export default function about(app) {
const router = app.loopback.Router();
const User = app.models.User;
const userCount$ = observeMethod(User, 'count');

function showAbout(req, res, next) {
const daysRunning = moment().diff(new Date('10/15/2014'), 'days');

userCount$()
.map(camperCount => numberWithCommas(camperCount))
.doOnNext(camperCount => {
res.render('resources/about', {
camperCount,
daysRunning,
title: dedent`
About our Open Source Community, our social media presence,
and how to contact us`.split('\n').join(' '),
globalCompletedCount: numberWithCommas(
5612952 + (Math.floor((Date.now() - 1446268581061) / 2000))
)
});
})
.subscribe(() => {}, next);
}

router.get('/about', showAbout);
app.use(router);
}
8 changes: 0 additions & 8 deletions server/boot/randomAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = function(app) {
router.get('/labs', showLabs);
router.get('/stories', showTestimonials);
router.get('/all-stories', showAllTestimonials);
router.get('/about', showAbout);
router.get('/terms', terms);
router.get('/privacy', privacy);
router.get('/code-of-conduct', codeOfConduct);
Expand Down Expand Up @@ -198,13 +197,6 @@ module.exports = function(app) {
});
}

function showAbout(req, res) {
res.render('resources/about', {
title: 'About our Open Source Community, our social media presence, ' +
'and how to contact us'
});
}

function terms(req, res) {
res.render('resources/terms-of-service', {
title: 'Terms of Service'
Expand Down
1 change: 1 addition & 0 deletions server/boot/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ module.exports = function(app) {
req.flash('errors', {
msg: `404: We couldn't find path ${ path }`
});
console.log('404');
return res.redirect('/');
}
profileUser = profileUser.toJSON();
Expand Down
19 changes: 19 additions & 0 deletions server/views/resources/about.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ block content
br
| who learn to code and help nonprofits.
.spacer
.row
.col-xs-12.col-sm-10.col-sm-offset-1.col-md-6.col-md-offset-3
h2
table.population-table.img-center
tr
td Established: 
td
span.text-primary #{daysRunning} 
| days ago
tr
td Population:   
td
span.text-primary #{camperCount} 
| campers
tr
td Completed:   
td
span.text-primary #{globalCompletedCount} 
| challenges

.row
.col-xs-12.col-sm-10.col-sm-offset-1.col-md-6.col-md-offset-3
Expand Down

0 comments on commit 918ea56

Please sign in to comment.