From 78b893b5f793b541ced8980f798572a849abcd8d Mon Sep 17 00:00:00 2001 From: Joe Reeve Date: Sat, 7 Nov 2015 14:39:44 +0000 Subject: [PATCH] test --- build/components.html | 2 +- build/components.js | 4 +-- build/index.html | 4 +-- build/index.js | 8 +++--- client/teacher.js => build/parent copy.js | 7 +++-- build/parent.js | 2 +- client/components/home/home.js | 3 --- client/{ => components/parent}/parent.css | 0 .../{home/home.html => parent/parent.html} | 0 client/components/parent/parent.js | 3 +++ .../{components/home/home.css => index.css} | 0 client/{teacher.html => index.html} | 2 +- client/index.js | 20 ++++++++++++++ client/parent.html | 24 ----------------- client/parent.js | 20 -------------- client/teacher.css | 0 server/app.js | 27 +++++++++++++++++-- 17 files changed, 64 insertions(+), 62 deletions(-) rename client/teacher.js => build/parent copy.js (51%) delete mode 100644 client/components/home/home.js rename client/{ => components/parent}/parent.css (100%) rename client/components/{home/home.html => parent/parent.html} (100%) create mode 100644 client/components/parent/parent.js rename client/{components/home/home.css => index.css} (100%) rename client/{teacher.html => index.html} (94%) create mode 100644 client/index.js delete mode 100644 client/parent.html delete mode 100644 client/parent.js delete mode 100644 client/teacher.css diff --git a/build/components.html b/build/components.html index 634812d..86f96c4 100644 --- a/build/components.html +++ b/build/components.html @@ -1,4 +1,4 @@ - - + - - + diff --git a/client/index.js b/client/index.js new file mode 100644 index 0000000..8d9e001 --- /dev/null +++ b/client/index.js @@ -0,0 +1,20 @@ +$(document).ready(function(){ + + @@include('components.js') + + $.getJSON('/data/'+location.pathname.split('/').slice(3).join('/'), function(res){ + + var ractive = new Ractive.components[location.pathname.split('/')[2]]({ + el:'#load', + data:res + }); + + }); + + + //Code below here + + + + + }); diff --git a/client/parent.html b/client/parent.html deleted file mode 100644 index d484511..0000000 --- a/client/parent.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - RCard - - - - - - - - - - - - - - @@include('components.html') - -
- - - diff --git a/client/parent.js b/client/parent.js deleted file mode 100644 index 5261092..0000000 --- a/client/parent.js +++ /dev/null @@ -1,20 +0,0 @@ -$(document).ready(function(){ - - @@include('components.js') - - $.getJSON('/sample', function(res){ - - var ractive = new Ractive.components.home({ - el:'#load', - data:res - }); - - }); - - - //Code below here - - - - - }); diff --git a/client/teacher.css b/client/teacher.css deleted file mode 100644 index e69de29..0000000 diff --git a/server/app.js b/server/app.js index a14e571..5216af9 100644 --- a/server/app.js +++ b/server/app.js @@ -3,8 +3,12 @@ var express = require('express'); var app = express(); app.use(express.static('../build')) -app.get('/', function(req, res){ - res.send(fs.readFileSync('../build/index.html')); +var mongojs = require('mongojs'); + +var db = mongojs('test', ['class', 'student']); + +app.get('/view/:viewType/:dataType/:id', function(req, res){ + res.send(fs.readFileSync('../build/index.html', 'utf8')); }); app.get('/sample', function(req, res){ @@ -14,5 +18,24 @@ app.get('/sample', function(req, res){ }); }); +app.get('/data/:type/:id', function(req, res){ + if(req.params.type === 'class') { + db.class.findOne({_id: mongojs.ObjectId(req.params.id)}, function(err, classDoc){ + if(err) + throw new Error('Error finding class'); + db.student.find({class:req.params.id}, function(err, students){ + res.send({ + class:classDoc, + students:students + }); + }); + }); + } else if(req.params.type === 'student') { + db.student.find({_id:mongojs.ObjectId(req.params.id)}, function(err, student){ + res.send(student); + }); + } +}); + app.listen(1337);