aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/index.jade3
-rw-r--r--src/server/lib/getMeetingpointData.js30
-rw-r--r--src/server/routes/index.js14
3 files changed, 33 insertions, 14 deletions
diff --git a/src/client/views/index.jade b/src/client/views/index.jade
index 9e9d713..89a2256 100644
--- a/src/client/views/index.jade
+++ b/src/client/views/index.jade
@@ -8,5 +8,8 @@ block content
block scripts
script.
+ !{flagsStr}
!{usersStr}
+ !{dailyScheduleWeeksStr}
+ !{basisScheduleWeeksStr}
script(src='/bundle.js')
diff --git a/src/server/lib/getMeetingpointData.js b/src/server/lib/getMeetingpointData.js
index b2225f4..0272398 100644
--- a/src/server/lib/getMeetingpointData.js
+++ b/src/server/lib/getMeetingpointData.js
@@ -1,5 +1,3 @@
-
-
const Promise = require('bluebird');
const cheerio = require('cheerio');
const _ = require('lodash');
@@ -41,22 +39,34 @@ function getUsers(page) {
return _.flatten([classes, teachers, rooms, students]);
}
-function getValidWeekNumbers(page) {
+function getWeeks(page) {
const weekSelector = page('select[name="week"]');
- const weekNumbers = _.map(weekSelector.children(), option => parseInt(option.attribs.value, 10));
+ const weeks = _.map(weekSelector.children(), option => ({
+ id: cheerio(option).attr('value'),
+ text: cheerio(option).text(),
+ }));
- return weekNumbers;
+ return weeks;
}
function requestData() {
lastUpdate = new Date();
- return request('http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm', { timeout: 5000 }).then((response) => {
- const page = cheerio.load(response.body);
- const users = getUsers(page);
- const validWeekNumbers = getValidWeekNumbers(page);
+ const requests = [
+ request('http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm', { timeout: 5000 }),
+ request('http://www.meetingpointmco.nl/Roosters-AL/doc/basisroosters/frames/navbar.htm', { timeout: 5000 }),
+ ];
+
+ return Promise.all(requests).then(([dailyScheduleResponse, basisScheduleResponse]) => {
+ const dailySchedulePage = cheerio.load(dailyScheduleResponse.body);
+ const basisSchedulePage = cheerio.load(basisScheduleResponse.body);
+ const users = getUsers(dailySchedulePage);
+ const dailyScheduleWeeks = getWeeks(dailySchedulePage);
+ const basisScheduleWeeks = getWeeks(basisSchedulePage);
+
+ meetingpointData = { users, dailyScheduleWeeks, basisScheduleWeeks };
- meetingpointData = { users, validWeekNumbers };
+ console.log(meetingpointData);
return meetingpointData;
});
diff --git a/src/server/routes/index.js b/src/server/routes/index.js
index 7e97fea..d58962d 100644
--- a/src/server/routes/index.js
+++ b/src/server/routes/index.js
@@ -5,7 +5,7 @@ const getMeetingpointData = require('../lib/getMeetingpointData');
/* GET home page. */
router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], (req, res) => {
- getMeetingpointData().then((data) => {
+ getMeetingpointData().then(({ users, dailyScheduleWeeks, basisScheduleWeeks }) => {
const isBeta = process.env.BETA === '1';
const flags = [];
@@ -17,10 +17,16 @@ router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], (req, res) => {
}
const flagsStr = `var FLAGS = ${JSON.stringify(flags)};`;
- const usersStr = `var USERS = ${JSON.stringify(data.users)};`;
- const validWeekNumbersStr = `var VALID_WEEK_NUMBERS = ${JSON.stringify(data.validWeekNumbers)}`;
+ const usersStr = `var USERS = ${JSON.stringify(users)};`;
+ const dailyScheduleWeeksStr = `var DAGROOSTER_WEEKS = ${JSON.stringify(dailyScheduleWeeks)}`;
+ const basisScheduleWeeksStr = `var BASISROOSTER_WEEKS = ${JSON.stringify(basisScheduleWeeks)}`;
- res.render('index', { flagsStr, usersStr, validWeekNumbersStr });
+ res.render('index', {
+ flagsStr,
+ usersStr,
+ dailyScheduleWeeksStr,
+ basisScheduleWeeksStr,
+ });
}).catch(() => {
console.error('Unable to get user info, emergency redirect!');
res.render('redirect');