| 
									
										
										
										
											2016-02-22 23:00:59 -08:00
										 |  |  | import { Observable } from 'rx'; | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  | import dedent from 'dedent'; | 
					
						
							|  |  |  | import moment from 'moment'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 14:45:09 -07:00
										 |  |  | import { timeCache, observeMethod } from '../utils/rx'; | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function numberWithCommas(x) { | 
					
						
							|  |  |  |   return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 14:45:09 -07:00
										 |  |  | // userCount(where: Object) => Observable[Number]
 | 
					
						
							|  |  |  | // getCertCount(userCount: userCount, cert: String) => Observable[Number]
 | 
					
						
							|  |  |  | function getCertCount(userCount, cert) { | 
					
						
							|  |  |  |   return userCount({ [cert]: true }) | 
					
						
							|  |  |  |     // using This-Bind operator
 | 
					
						
							|  |  |  |     ::timeCache(2, 'hours'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  | function getAllThreeCertsCount(userCount) { | 
					
						
							| 
									
										
										
										
											2016-04-26 23:22:45 -07:00
										 |  |  |   return userCount({ | 
					
						
							|  |  |  |     isFrontEndCert: true, | 
					
						
							|  |  |  |     isDataVisCert: true, | 
					
						
							|  |  |  |     isBackEndCert: true | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  |     ::timeCache(2, 'hours'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  | export default function about(app) { | 
					
						
							|  |  |  |   const router = app.loopback.Router(); | 
					
						
							|  |  |  |   const User = app.models.User; | 
					
						
							| 
									
										
										
										
											2016-04-05 14:45:09 -07:00
										 |  |  |   const userCount = observeMethod(User, 'count'); | 
					
						
							|  |  |  |   const frontEndCount$ = getCertCount(userCount, 'isFrontEndCert'); | 
					
						
							|  |  |  |   const dataVisCount$ = getCertCount(userCount, 'isDataVisCert'); | 
					
						
							|  |  |  |   const backEndCount$ = getCertCount(userCount, 'isBackEndCert'); | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  |   const allThreeCount$ = getAllThreeCertsCount(userCount); | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function showAbout(req, res, next) { | 
					
						
							|  |  |  |     const daysRunning = moment().diff(new Date('10/15/2014'), 'days'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-22 23:00:59 -08:00
										 |  |  |     Observable.combineLatest( | 
					
						
							| 
									
										
										
										
											2016-04-05 14:45:09 -07:00
										 |  |  |       frontEndCount$, | 
					
						
							|  |  |  |       dataVisCount$, | 
					
						
							|  |  |  |       backEndCount$, | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  |       allThreeCount$, | 
					
						
							|  |  |  |       ( | 
					
						
							|  |  |  |         frontEndCount = 0, | 
					
						
							|  |  |  |         dataVisCount = 0, | 
					
						
							|  |  |  |         backEndCount = 0, | 
					
						
							|  |  |  |         allThreeCount = 0 | 
					
						
							|  |  |  |       ) => ({ | 
					
						
							| 
									
										
										
										
											2016-02-22 23:00:59 -08:00
										 |  |  |         frontEndCount, | 
					
						
							|  |  |  |         dataVisCount, | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  |         backEndCount, | 
					
						
							|  |  |  |         allThreeCount | 
					
						
							| 
									
										
										
										
											2016-02-22 23:00:59 -08:00
										 |  |  |       }) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-04-26 23:22:45 -07:00
										 |  |  |       .doOnNext(({ | 
					
						
							|  |  |  |         frontEndCount, | 
					
						
							|  |  |  |         dataVisCount, | 
					
						
							|  |  |  |         backEndCount, | 
					
						
							|  |  |  |         allThreeCount | 
					
						
							|  |  |  |       }) => { | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  |         res.render('resources/about', { | 
					
						
							| 
									
										
										
										
											2016-04-05 21:41:27 -07:00
										 |  |  |           frontEndCount: numberWithCommas(frontEndCount), | 
					
						
							|  |  |  |           dataVisCount: numberWithCommas(dataVisCount), | 
					
						
							|  |  |  |           backEndCount: numberWithCommas(backEndCount), | 
					
						
							| 
									
										
										
										
											2016-04-25 16:57:30 -07:00
										 |  |  |           allThreeCount: numberWithCommas(allThreeCount), | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  |           daysRunning, | 
					
						
							|  |  |  |           title: dedent`
 | 
					
						
							|  |  |  |             About our Open Source Community, our social media presence, | 
					
						
							| 
									
										
										
										
											2016-02-22 22:28:32 -08:00
										 |  |  |             and how to contact us | 
					
						
							|  |  |  |           `.split('\n').join(' '),
 | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  |           globalCompletedCount: numberWithCommas( | 
					
						
							| 
									
										
										
										
											2016-02-22 22:28:32 -08:00
										 |  |  |             5612952 + (Math.floor((Date.now() - 1446268581061) / 1800)) | 
					
						
							| 
									
										
										
										
											2016-02-22 22:15:14 -08:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2016-02-22 22:32:50 -08:00
										 |  |  |           globalPledgedAmount: numberWithCommas(Math.floor( | 
					
						
							|  |  |  |             28000 + | 
					
						
							|  |  |  |             ((Date.now() - 1456207176902) / (2629746000 / 2000) * 8.30) | 
					
						
							|  |  |  |           )) | 
					
						
							| 
									
										
										
										
											2016-01-15 00:10:13 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .subscribe(() => {}, next); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   router.get('/about', showAbout); | 
					
						
							|  |  |  |   app.use(router); | 
					
						
							|  |  |  | } |