2014-12-23 16:48:28 +00:00
var User = require ( '../models/User' ) ,
resources = require ( './resources.json' ) ,
questions = resources . questions ,
2014-12-26 08:05:00 +00:00
steps = resources . steps ,
2014-12-26 20:15:24 +00:00
secrets = require ( './../config/secrets' ) ,
Challenge = require ( './../models/Challenge' ) ,
2015-01-26 23:28:14 +00:00
bonfires = require ( '../seed_data/bonfires.json' ) ;
2015-02-02 07:35:27 +00:00
coursewares = require ( '../seed_data/coursewares.json' ) ;
2014-12-26 20:15:24 +00:00
Client = require ( 'node-rest-client' ) . Client ,
2015-01-27 07:51:59 +00:00
client = new Client ( ) ,
debug = require ( 'debug' ) ( 'freecc:cntr:bonfires' ) ;
2014-12-11 04:44:33 +00:00
2014-11-10 18:29:16 +00:00
/ * *
* GET /
* Resources .
* /
2014-12-26 08:05:00 +00:00
2014-12-23 16:48:28 +00:00
module . exports = {
2015-01-27 07:51:59 +00:00
privacy : function privacy ( req , res ) {
res . render ( 'resources/privacy' , {
title : 'Privacy'
} ) ;
} ,
stats : function stats ( req , res ) {
var date1 = new Date ( "10/15/2014" ) ;
var date2 = new Date ( ) ;
var timeDiff = Math . abs ( date2 . getTime ( ) - date1 . getTime ( ) ) ;
var daysRunning = Math . ceil ( timeDiff / ( 1000 * 3600 * 24 ) ) ;
client . get ( 'https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets . trello . key , function ( trello , response ) {
var nonprofitProjects = ( trello && trello . length ) || 15 ;
User . count ( { 'points' : { '$gt' : 2 } } , function ( err , c3 ) { if ( err ) { debug ( 'User err: ' , err ) ; next ( err ) ; }
User . count ( { 'points' : { '$gt' : 9 } } , function ( err , c10 ) { if ( err ) { debug ( 'User err: ' , err ) ; next ( err ) ; }
User . count ( { 'points' : { '$gt' : 29 } } , function ( err , c30 ) { if ( err ) { debug ( 'User err: ' , err ) ; next ( err ) ; }
User . count ( { 'points' : { '$gt' : 53 } } , function ( err , all ) { if ( err ) { debug ( 'User err: ' , err ) ; next ( err ) ; }
res . render ( 'resources/stats' , {
title : 'Free Code Camp Stats:' ,
daysRunning : daysRunning ,
nonprofitProjects : nonprofitProjects ,
c3 : c3 ,
c10 : c10 ,
c30 : c30 ,
all : all
} ) ;
} ) ;
} ) ;
} ) ;
2014-12-26 08:05:00 +00:00
} ) ;
} ) ;
2015-01-27 07:51:59 +00:00
} ,
deployAWebsite : function deployAWebsite ( req , res ) {
res . render ( 'resources/deploy-a-website' , {
title : 'Deploy a Dynamic Website in 7 Minutes'
} ) ;
} ,
2015-02-20 00:33:08 +00:00
chat : function chat ( req , res ) {
res . render ( 'resources/chat' , {
title : "Enter Free Code Camp's Chat Rooms"
} ) ;
} ,
2015-01-27 07:51:59 +00:00
nonprofitProjectInstructions : function nonprofitProjectInstructions ( req , res ) {
res . render ( 'resources/nonprofit-project-instructions' , {
title : 'Nonprofit Project Instructions'
} ) ;
} ,
gmailShortcuts : function gmailShortcuts ( req , res ) {
res . render ( 'resources/gmail-shortcuts' , {
title : 'These Gmail Shortcuts will save you Hours'
} ) ;
} ,
controlShortcuts : function controlShortcuts ( req , res ) {
res . render ( 'resources/control-shortcuts' , {
title : 'These Control Shortcuts will save you Hours'
} ) ;
} ,
chromebook : function chromebook ( req , res ) {
res . render ( 'resources/chromebook' , {
title : 'Win a Chromebook'
} ) ;
} ,
jqueryExercises : function jqueryExercises ( req , res ) {
res . render ( 'resources/jquery-exercises' , {
title : 'jQuery Exercises'
} ) ;
} ,
livePairProgramming : function ( req , res ) {
res . render ( 'resources/live-pair-programming' , {
title : 'Live Pair Programming'
} ) ;
2015-02-17 22:10:15 +00:00
} ,
installScreenHero : function ( req , res ) {
res . render ( 'resources/install-screenhero' , {
title : 'Install ScreenHero'
} ) ;
2015-01-27 07:51:59 +00:00
} ,
javaScriptInYourInbox : function ( req , res ) {
res . render ( 'resources/javascript-in-your-inbox' , {
title : 'JavaScript in your Inbox'
} ) ;
} ,
2015-02-17 07:35:02 +00:00
githubCalls : function ( req , res ) {
var githubHeaders = { headers : { 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36' } , port : 80 } ;
client . get ( 'https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets . github . clientID + '&client_secret=' + secrets . github . clientSecret , githubHeaders , function ( pulls , res3 ) {
2015-02-17 21:31:59 +00:00
pulls = pulls ? Object . keys ( JSON . parse ( pulls ) ) . length : "Can't connect to github" ;
2015-02-17 07:35:02 +00:00
client . get ( 'https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets . github . clientID + '&client_secret=' + secrets . github . clientSecret , githubHeaders , function ( issues , res4 ) {
issues = ( ( pulls === parseInt ( pulls ) ) && issues ) ? Object . keys ( JSON . parse ( issues ) ) . length - pulls : "Can't connect to GitHub" ;
res . send ( { "issues" : issues , "pulls" : pulls } ) ;
} ) ;
} ) ;
} ,
trelloCalls : function ( req , res ) {
client . get ( 'https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets . trello . key , function ( trello , res2 ) {
2015-02-17 23:35:16 +00:00
trello = trello ? ( JSON . parse ( trello ) ) . length : "Can't connect to to Trello" ;
2015-02-17 07:35:02 +00:00
res . send ( { "trello" : trello } ) ;
} ) ;
} ,
bloggerCalls : function ( req , res ) {
client . get ( 'https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets . blogger . key , function ( blog , res5 ) {
var blog = blog . length > 100 ? JSON . parse ( blog ) : "" ;
2015-02-17 23:35:16 +00:00
res . send ( {
blog1Title : blog ? blog [ "items" ] [ 0 ] [ "title" ] : "Can't connect to Blogger" ,
blog1Link : blog ? blog [ "items" ] [ 0 ] [ "url" ] : "http://blog.freecodecamp.com" ,
blog2Title : blog ? blog [ "items" ] [ 1 ] [ "title" ] : "Can't connect to Blogger" ,
blog2Link : blog ? blog [ "items" ] [ 1 ] [ "url" ] : "http://blog.freecodecamp.com" ,
blog3Title : blog ? blog [ "items" ] [ 2 ] [ "title" ] : "Can't connect to Blogger" ,
blog3Link : blog ? blog [ "items" ] [ 2 ] [ "url" ] : "http://blog.freecodecamp.com" ,
blog4Title : blog ? blog [ "items" ] [ 3 ] [ "title" ] : "Can't connect to Blogger" ,
blog4Link : blog ? blog [ "items" ] [ 3 ] [ "url" ] : "http://blog.freecodecamp.com" ,
blog5Title : blog ? blog [ "items" ] [ 4 ] [ "title" ] : "Can't connect to Blogger" ,
blog5Link : blog ? blog [ "items" ] [ 4 ] [ "url" ] : "http://blog.freecodecamp.com"
} ) ;
2015-02-17 07:35:02 +00:00
} ) ;
} ,
2015-01-27 07:51:59 +00:00
about : function ( req , res ) {
var date1 = new Date ( "10/15/2014" ) ;
var date2 = new Date ( ) ;
var timeDiff = Math . abs ( date2 . getTime ( ) - date1 . getTime ( ) ) ;
var daysRunning = Math . ceil ( timeDiff / ( 1000 * 3600 * 24 ) ) ;
2015-02-17 07:35:02 +00:00
var announcements = resources . announcements ;
2015-02-26 22:38:22 +00:00
function numberWithCommas ( x ) {
return x . toString ( ) . replace ( /\B(?=(\d{3})+(?!\d))/g , "," ) ;
}
2015-02-19 06:58:10 +00:00
User . count ( { } , function ( err , c3 ) {
2015-02-17 07:35:02 +00:00
if ( err ) {
debug ( 'User err: ' , err ) ;
next ( err ) ;
}
2015-02-19 06:58:10 +00:00
User . count ( { 'points' : { '$gt' : 53 } } , function ( err , all ) {
2015-02-17 07:35:02 +00:00
if ( err ) {
debug ( 'User err: ' , err ) ;
next ( err ) ;
}
2015-02-26 22:38:22 +00:00
2015-02-19 06:58:10 +00:00
res . render ( 'resources/learn-to-code' , {
title : 'About Free Code Camp and Our Team of Volunteers' ,
daysRunning : daysRunning ,
2015-02-26 22:38:22 +00:00
c3 : numberWithCommas ( c3 ) ,
2015-02-19 06:58:10 +00:00
all : all ,
announcements : announcements
2015-01-13 05:28:58 +00:00
} ) ;
2015-01-07 07:08:54 +00:00
} ) ;
} ) ;
2015-01-27 07:51:59 +00:00
} ,
2015-01-25 15:02:41 +00:00
randomPhrase : function ( ) {
var phrases = resources . phrases ;
return phrases [ Math . floor ( Math . random ( ) * phrases . length ) ] ;
} ,
randomVerb : function ( ) {
var verbs = resources . verbs ;
return verbs [ Math . floor ( Math . random ( ) * verbs . length ) ] ;
} ,
randomCompliment : function ( ) {
var compliments = resources . compliments ;
return compliments [ Math . floor ( Math . random ( ) * compliments . length ) ] ;
2015-01-26 23:28:14 +00:00
} ,
numberOfBonfires : function ( ) {
return bonfires . length - 1 ;
2015-01-27 06:22:02 +00:00
} ,
allBonfireIds : function ( ) {
return bonfires . map ( function ( elem ) {
2015-01-27 08:29:17 +00:00
return {
_id : elem . _id ,
difficulty : elem . difficulty
}
} )
. sort ( function ( a , b ) {
return a . difficulty - b . difficulty ;
} )
. map ( function ( elem ) {
2015-01-27 06:22:02 +00:00
return elem . _id ;
2015-02-01 22:22:34 +00:00
} ) ;
} ,
allBonfireNames : function ( ) {
return bonfires . map ( function ( elem ) {
return {
name : elem . name ,
difficulty : elem . difficulty
}
2015-01-27 06:22:02 +00:00
} )
2015-02-01 22:22:34 +00:00
. sort ( function ( a , b ) {
return a . difficulty - b . difficulty ;
} )
. map ( function ( elem ) {
return elem . name ;
} ) ;
2015-02-02 07:35:27 +00:00
} ,
allCoursewareIds : function ( ) {
return coursewares . map ( function ( elem ) {
return {
_id : elem . _id ,
difficulty : elem . difficulty
}
} )
. sort ( function ( a , b ) {
return a . difficulty - b . difficulty ;
} )
. map ( function ( elem ) {
return elem . _id ;
} ) ;
} ,
allCoursewareNames : function ( ) {
return coursewares . map ( function ( elem ) {
return {
name : elem . name ,
difficulty : elem . difficulty
}
} )
. sort ( function ( a , b ) {
return a . difficulty - b . difficulty ;
} )
. map ( function ( elem ) {
return elem . name ;
} ) ;
2015-02-07 00:55:48 +00:00
} ,
whichEnvironment : function ( ) {
return process . env . NODE _ENV ;
2015-01-25 15:02:41 +00:00
}
2015-02-02 07:35:27 +00:00
2014-12-23 16:48:28 +00:00
} ;
2014-11-12 01:52:03 +00:00