Added a classlist page for getting a list with all your classmates.

This commit is contained in:
Bram van der Veen 2015-07-22 12:41:09 +02:00
parent d63eabbaeb
commit f34acd3912
7 changed files with 39 additions and 9 deletions

View file

@ -59,6 +59,7 @@ function logout(req, res) {
}
function is(req, res, next) {
console.log('Checked auth stats');
var cookies = qs.parse((req.headers.cookie || '').replace(/\s/g, ''), ';', '=');
if (!cookies.username || !cookies.password) {next(); return;}

View file

@ -24,7 +24,7 @@ function get(req, res, next, search) {
res.render('not_found');
}
else {
req.found = database_entry;
req.match = database_entry;
res.render('multiple_found', req);
}
});
@ -34,7 +34,7 @@ function api(req, callback) {
var index = database.collection('index');
var query = RegExp(req.query.name, 'i');
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}]}).toArray(function (err, database_entry) {
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}, {group: query}]}).toArray(function (err, database_entry) {
if (err) callback({'error': err});
else {
for (entry of database_entry) {entry.url = make_url(req, entry)}
@ -43,6 +43,21 @@ function api(req, callback) {
});
}
function list(req, res, next, list) {
var index = database.collection('index');
var query = RegExp(list, 'i');
console.log(list);
index.find({group: list}).toArray(function (err, database_entry) {
if (err) {req.error = err; next();}
else {
req.match = database_entry;
next();
}
});
}
//Function for making a link out of the given database_entry.
function make_url(req, database_entry) {
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster';
@ -82,7 +97,7 @@ function easter(search) {
return null;
}
module.exports = {'get': get, 'api': api};
module.exports = {'get': get, 'api': api, 'list': list};
//Testing function, if test is passed in the command line will execute a test.
if (process.argv[2] == "test") {

View file

@ -23,6 +23,9 @@ html
a(href="/rooster/#{headers.user.id}") Jouw Rooster
li
a(href=headers.user.url, target="_blank") Andere roostersite
li |
li
a(href="/klassenlijst/#{headers.user.group}") Jouw Klassenlijst
ul.right
li

6
resources/jade/list.jade Normal file
View file

@ -0,0 +1,6 @@
//- list.jade
include header
div=JSON.stringify(match, null, 2)
include links

View file

@ -4,7 +4,7 @@ include search
.container
ul.found
for entry in found
for entry in match
li
a(href='/rooster/' + entry.name)=entry.name

View file

@ -1,3 +1,3 @@
//- search.jade
input.search(type="text", name="searchterm", placeholder="Je naam, id, klassennaam, docentencode, lokaalcode", value=match ? ((match.first_name || match.name) + '\'s rooster') : '')
input.search(type="text", name="searchterm", placeholder="Je naam, id, klassennaam, docentencode, lokaalcode", value=path.split('/')[1] == 'klassenlijst' ? 'Leerlingen van ' + match[0].group : match ? ((match.first_name || match.name) + '\'s rooster') : '')
button.search Zoeken

13
web.js
View file

@ -22,9 +22,6 @@ app.use('/css', less(__dirname + '/resources/less'));
app.use('/js', express.static(__dirname + '/resources/js'));
app.use('/other', express.static(__dirname + '/resources/other'));
//Other things that need to be setup
// app.use(body_parser);
app.get('/', auth.is, function (req, res) {
req.links = config().links;
res.render('homepage', req);
@ -54,6 +51,15 @@ app.param('search', function (req, res) {
res.render('schedule', req);
});
app.param('list', lookup.list);
app.get('/klassenlijst/:list',[auth.is, function (req, res) {
console.log('did the list');
req.links = config().links;
req.times = config().hour_times;
res.render('multiple_found', req);
}]);
app.listen(config().web_port);
plugins();
@ -66,5 +72,4 @@ function plugins() {
var app = require(app)(config().web_port + (1 + plugin.indexOf(plugins_directory)));
}
}
}