This commit is contained in:
Joe Reeve
2015-11-07 14:39:44 +00:00
parent 1765a42699
commit 78b893b5f7
17 changed files with 64 additions and 62 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
<script type="text/ractive" id="home"><div class="row">
<script type="text/ractive" id="parent"><div class="row">
<div class="col s12 m6 offset-m3">
<div class="card">
<div class="card-content">
+2 -2
View File
@@ -1,3 +1,3 @@
Ractive.components.home = Ractive.extend({
template:'#home'
Ractive.components.student = Ractive.extend({
template:'#student'
});
+2 -2
View File
@@ -12,11 +12,11 @@
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<script src='index.js'></script>
<script src='/index.js'></script>
</head>
<body>
<script type="text/ractive" id="home"><div class="row">
<script type="text/ractive" id="parent"><div class="row">
<div class="col s12 m6 offset-m3">
<div class="card">
<div class="card-content">
+4 -4
View File
@@ -1,13 +1,13 @@
$(document).ready(function(){
Ractive.components.home = Ractive.extend({
template:'#home'
Ractive.components.student = Ractive.extend({
template:'#student'
});
$.getJSON('/sample', function(res){
$.getJSON('/data/'+location.pathname.split('/').slice(3).join('/'), function(res){
var ractive = new Ractive.components.home({
var ractive = new Ractive.components[location.pathname.split('/')[2]]({
el:'#load',
data:res
});
+5 -2
View File
@@ -1,10 +1,13 @@
$(document).ready(function(){
@@include('components.js')
Ractive.components.home = Ractive.extend({
template:'#home'
});
$.getJSON('/sample', function(res){
var ractive = new Ractive.components.home({
var ractive = new Ractive.components[location.pathname.split('/')[1]]({
el:'#load',
data:res
});
+1 -1
View File
@@ -7,7 +7,7 @@ $(document).ready(function(){
$.getJSON('/sample', function(res){
var ractive = new Ractive.components.home({
var ractive = new Ractive.components[location.pathname.split('/')[1]]({
el:'#load',
data:res
});
-3
View File
@@ -1,3 +0,0 @@
Ractive.components.home = Ractive.extend({
template:'#home'
});
+3
View File
@@ -0,0 +1,3 @@
Ractive.components.student = Ractive.extend({
template:'#student'
});
+1 -1
View File
@@ -12,7 +12,7 @@
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<script src='index.js'></script>
<script src='/index.js'></script>
</head>
<body>
+20
View File
@@ -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
});
-24
View File
@@ -1,24 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RCard</title>
<script src='http://cdn.ractivejs.org/latest/ractive.js'></script>
<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<script src='index.js'></script>
</head>
<body>
@@include('components.html')
<div id='load'></div>
</body>
</html>
-20
View File
@@ -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
});
View File
+25 -2
View File
@@ -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);