Skip to content

Commit

Permalink
finished views
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 6, 2014
1 parent fba1322 commit 18f5f2b
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/controllers/students.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

var Student = require('../models/student');

exports.index = function(req, res){
Student.findAll(function(students){
res.render('students/index', {students:students});
});
};

exports.show = function(req, res){
Student.findById(req.params.id, function(student){
res.render('students/show', {student:student});
});
};

exports.addTest = function(req, res){
res.render('students/addtest', {id:req.params.id});
};

exports.init = function(req, res){
res.render('students/new');
};

exports.create = function(req, res){
var s = new Student(req.body);
s.save(function(){
res.redirect('/students');
});
};

exports.update = function(req, res){
Student.findById(req.params.id, function(student){
student.addTest(req.body, function(){
res.redirect('/students/' + req.params.id);
});
});
};
16 changes: 16 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var port = process.env.PORT;
var db = process.env.DB;

var express = require('express');
var app = express();

require('./lib/config')(app);
require('./lib/pipeline')(app, express);
require('./lib/mongodb')(db);

app.listen(port, function(){
console.log('Express Ready:', port);
});

25 changes: 25 additions & 0 deletions app/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
nav ul {
list-style-type: none;
}

nav li {
display: inline-block;
margin: 0 10px;
}

table {
text-align: center;
border-collapse: collapse;
}

td, th {
min-width: 50px;
padding: 5px;
border: 2px solid black;
}

.testscore {
width: 20px;
margin: 5px;
display: inline-block;
}
8 changes: 8 additions & 0 deletions app/views/students/addtest.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends ../shared/template
block content
h1 Adding test score
form(method='post' action='/students/#{id}/test')
label Score
input(type="number", name="score")
button Add test

26 changes: 26 additions & 0 deletions app/views/students/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends ../shared/template
block content
h1 View students
table#students
thead
tr
th Name
th Average
th Letter
th Suspended
th Honor Roll
tbody
each student in students
tr
td(style="background-color:#{student.color}"): a(href="/students/#{student._id}")= student.name
td(style="background-color:#{student.getColor(student.avg())};")= student.avg().toFixed(1)
td(style="background-color:#{student.getColor(student.avg())};")= student.letter()
-console.log(student.isSuspended);
if student.isSuspended()
td(style="background-color:red") Yes
else
td(style="background-color:green") No
if student.onHonorRoll()
td(style="background-color:green") Yes
else
td(style="background-color:red") No
11 changes: 11 additions & 0 deletions app/views/students/new.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends ../shared/template
block content
h1 Add a new student
form(method="post", action="/students/new")
label Name
input(type='text', name='name', placeholder='e.g. Bob Boberson')
br
label Color
input(type='color', name='color')
br
button Submit
27 changes: 27 additions & 0 deletions app/views/students/show.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends ../shared/template
block content
h1 View Student
table
tbody
tr
td(colspan='2')= student.name
tr
td Avg:
td= student.avg().toFixed(2)
tr
td Letter
td= student.letter()
tr
td Suspended
td= student.isSuspended()
tr
td Honor Roll
td= student.onHonorRoll()
tr
td(colspan='2')
form(method='get', action='/students/#{student._id}/test')
button Add Test
#test
each test in student.tests
.testscore(style='height:#{test}px;background-color:#{student.getColor(test)};')

0 comments on commit 18f5f2b

Please sign in to comment.