adding course count to app and template schools page
authorSeth Woodworth <seth@sethish.com>
Mon, 23 Jan 2012 00:44:05 +0000 (19:44 -0500)
committerSeth Woodworth <seth@sethish.com>
Mon, 23 Jan 2012 00:44:05 +0000 (19:44 -0500)
app.js
public/index.html

diff --git a/app.js b/app.js
index fef3b7f78d5bafe0967c251ed01fa64644b30026..da9ed2ca5f39410b475ad703d4977c45ee0286bc 100644 (file)
--- 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;
+                    })
+                });
                } 
        });
       });
index 38a74eb218be18b1f1461245ef13be804be65b37..e964aa53f33a340c7ed0c2330a6a5a4895405dd7 100644 (file)
                             <div class="text-pair">
                                 <span class="school_name">${name}</span>
                                 <!-- <h4>${description}</h4>-->
-                                <span class="number_of_courses">12 Courses, </span>
+                                <span class="number_of_courses">${courses} Courses, </span>
                                 <span class="number_of_notes">27 Notes</span>
                             </div>
                         </a>