From: Seth Woodworth Date: Mon, 23 Jan 2012 00:44:05 +0000 (-0500) Subject: adding course count to app and template schools page X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d6cdfdf0dc6e760086c3b943f5cdf79a4b1b07c0;p=oweals%2Ffinalsclub.git adding course count to app and template schools page --- diff --git a/app.js b/app.js index fef3b7f..da9ed2c 100644 --- a/app.js +++ b/app.js @@ -563,16 +563,28 @@ app.get( '/schools', checkAjax, loadUser, function( req, res ) { // XXX mongoose's documentation on sort is extremely poor, tread carefully School.find( {} ).sort( 'name', '1' ).run( function( err, schools ) { if( schools ) { - // If schools are found, loop through them gathering any courses that are // associated with them and then render the page with that information. var schools_todo = schools.length; - schools.each(function (school) { + schools.map(function (school) { + sys.puts("making course query"); Course.find( { 'school': school.id } ).run(function (err, courses) { school.courses_length = courses.length schools_todo -= 1; if (schools_todo <= 0) { - sendJson(res, { 'user': user.sanitized, 'schools': schools }); + sendJson(res, { 'user': user.sanitized, 'schools': schools.map( function(s) { + sys.puts("here"); + var school = { + _id: s._id, + name: s.name, + description: s.description, + url: s.url, + slug: s.slug, + courses: s.courses_length + }; + return school; + }) + }); } }); }); diff --git a/public/index.html b/public/index.html index 38a74eb..e964aa5 100644 --- a/public/index.html +++ b/public/index.html @@ -170,7 +170,7 @@
${name} - 12 Courses, + ${courses} Courses, 27 Notes