aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-07-31 15:23:53 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-07-31 15:23:53 +0200
commita9c832b003daa70ee78cacecc518cebdf4071ca1 (patch)
tree75978d446f22730fc859a24e999108ebdd461359
parent614817541a79ec0bbc90f8d6133db408b95dac35 (diff)
Add MAVO version
-rw-r--r--lib/getMeetingpointData.js18
-rw-r--r--lib/getURLOfUsers.js6
-rw-r--r--package.json3
-rw-r--r--public/javascripts/featureDetect.js6
-rw-r--r--public/javascripts/schedule.js6
-rw-r--r--routes/index.js11
-rw-r--r--views/index.jade4
-rw-r--r--views/redirect.jade2
8 files changed, 45 insertions, 11 deletions
diff --git a/lib/getMeetingpointData.js b/lib/getMeetingpointData.js
index 94cf36c..ea0f4de 100644
--- a/lib/getMeetingpointData.js
+++ b/lib/getMeetingpointData.js
@@ -13,7 +13,13 @@ function getUsers (page) {
const regexs = [/var classes = \[(.+)\];/, /var teachers = \[(.+)\];/, /var rooms = \[(.+)\];/, /var students = \[(.+)\];/]
const items = regexs.map(function (regex) {
- return script.match(regex)[1].split(',').map(function (item) {
+ const match = script.match(regex)
+
+ if (!match) {
+ return []
+ }
+
+ return match[1].split(',').map(function (item) {
return item.replace(/"/g, '')
})
})
@@ -59,9 +65,17 @@ function getValidWeekNumbers(page) {
function requestData() {
lastUpdate = new Date()
- return request(`http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm`, { timeout: 5000 }).then((response) => {
+ const url = process.env.SCHOOL_LEVEL === 'mavo'
+ ? 'http://www.meetingpointmco.nl/Roosters-AL/TOSweb/dagroosters/frames/navbar.htm'
+ : 'http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm';
+
+ console.log(url);
+
+ return request(url, { timeout: 5000 }).then((response) => {
const page = cheerio.load(response.body)
+ console.log('hey')
const users = getUsers(page)
+ console.log(users);
const validWeekNumbers = getValidWeekNumbers(page)
meetingpointData = { users, validWeekNumbers }
diff --git a/lib/getURLOfUsers.js b/lib/getURLOfUsers.js
index 8590ee4..528620f 100644
--- a/lib/getURLOfUsers.js
+++ b/lib/getURLOfUsers.js
@@ -33,7 +33,11 @@ function getWeek () {
}
function getURLOfUsers (weekOffset, type, id) {
- return `http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/` +
+ const baseUrl = process.env.SCHOOL_LEVEL === 'mavo'
+ ? 'http://www.meetingpointmco.nl/Roosters-AL/TOSweb'
+ : 'http://www.meetingpointmco.nl/Roosters-AL/doc'
+
+ return `${baseUrl}/dagroosters/` +
`${getWeek() + weekOffset}/${type}/${type}${leftPad(id, 5, '0')}.htm`
}
diff --git a/package.json b/package.json
index f67f30d..9b3250b 100644
--- a/package.json
+++ b/package.json
@@ -5,10 +5,12 @@
"private": true,
"scripts": {
"start": "node ./bin/www",
+ "start-mavo": "SCHOOL_LEVEL=mavo node ./bin/www",
"setup": "npm install && bower install --allow-root",
"build-dev": "browserify -d -t [ babelify --presets [ es2015 ] ] -e ./public/javascripts/main.js > ./public/javascripts/bundle.js",
"watch": "watchify -v -d -t [ babelify --presets [ es2015 ] ] -e ./public/javascripts/main.js -o ./public/javascripts/bundle.js",
"build": "browserify -t [ babelify --presets [ es2015 ] ] -e ./public/javascripts/main.js | uglifyjs -cm > ./public/javascripts/bundle.js",
+ "build-mavo": "browserify -t [ envify --SCHOOL_LEVEL mavo ] -t [ babelify --presets [ es2015 ] ] -e ./public/javascripts/main.js | uglifyjs -cm > ./public/javascripts/bundle.js",
"postinstall": "bower install --allow-root"
},
"dependencies": {
@@ -21,6 +23,7 @@
"debug": "~2.2.0",
"diacritics": "^1.2.3",
"encoding": "^0.1.12",
+ "envify": "^4.1.0",
"express": "^4.13.4",
"flexibility": "^2.0.1",
"fuzzy": "^0.1.1",
diff --git a/public/javascripts/featureDetect.js b/public/javascripts/featureDetect.js
index 3a072a1..af3ada2 100644
--- a/public/javascripts/featureDetect.js
+++ b/public/javascripts/featureDetect.js
@@ -12,7 +12,11 @@ self._shouldCheck = function () {
}
self._redirect = function () {
- window.location.href = 'http://www.meetingpointmco.nl/Roosters-AL/doc/'
+ if (process.env.SCHOOL_LEVEL === 'mavo') {
+ window.location.href = 'http://www.meetingpointmco.nl/Roosters-AL/TOSweb/'
+ } else {
+ window.location.href = 'http://www.meetingpointmco.nl/Roosters-AL/doc/'
+ }
}
self.check = function () {
diff --git a/public/javascripts/schedule.js b/public/javascripts/schedule.js
index bf87af5..1a2e62f 100644
--- a/public/javascripts/schedule.js
+++ b/public/javascripts/schedule.js
@@ -46,7 +46,11 @@ self._handleError = function (event) {
self._getURLOfUsers = function (week, type, index) {
const id = index + 1
- return '//' + window.location.host + '/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2F' +
+ const meetingpointProxyUrl = process.env.SCHOOL_LEVEL === 'mavo'
+ ? '/meetingpointProxy/Roosters-AL%2FTOSweb%2Fdagroosters%2F'
+ : '/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2F'
+
+ return '//' + window.location.host + meetingpointProxyUrl +
leftPad(week, 2, '0') + '%2F' + type + '%2F' + type + leftPad(id, 5, '0') + '.htm'
}
diff --git a/routes/index.js b/routes/index.js
index d496b3c..223d97f 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -6,6 +6,10 @@ const getMeetingpointData = require('../lib/getMeetingpointData')
/* GET home page. */
router.get('/', function (req, res, next) {
+ const baseMeetingpointUrl = process.env.SCHOOL_LEVEL === 'mavo'
+ ? 'http://www.meetingpointmco.nl/Roosters-AL/TOSweb'
+ : 'http://www.meetingpointmco.nl/Roosters-AL/doc';
+
getMeetingpointData().then(data => {
let flags = []
if (req.query.nfd != null) {
@@ -15,11 +19,12 @@ router.get('/', function (req, res, next) {
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)}`
- res.render('index', { flagsStr, usersStr, validWeekNumbersStr })
+ res.render('index', { baseMeetingpointUrl, flagsStr, usersStr, validWeekNumbersStr })
}).catch(function () {
console.error('Unable to get user info, emergency redirect!')
- // res.redirect('http://www.meetingpointmco.nl/Roosters-AL/doc/')
- res.render('redirect')
+ res.render('redirect', {
+ baseMeetingpointUrl,
+ })
})
})
diff --git a/views/index.jade b/views/index.jade
index fa5bf55..eb38e74 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -22,9 +22,9 @@ block content
i.material-icons &#xE5D4;
ul.mdl-menu.mdl-menu--bottom-right.mdl-js-menu.mdl-js-ripple-effect(for='overflow-button')
- a(href='http://www.meetingpointmco.nl/Roosters-AL/doc/basisroosters/default.htm')
+ a(href='#{baseMeetingpointUrl}/basisroosters/default.htm')
li.mdl-menu__item Basis rooster gebruiken
- a(href='http://www.meetingpointmco.nl/Roosters-AL/doc/')
+ a(href='#{baseMeetingpointUrl}/')
li.mdl-menu__item Oud rooster gebruiken
a(href='javascript:window.print()').print-page
li.mdl-menu__item.mdl-menu__item--full-bleed-divider#print-page Pagina printen
diff --git a/views/redirect.jade b/views/redirect.jade
index e895456..31b2322 100644
--- a/views/redirect.jade
+++ b/views/redirect.jade
@@ -43,5 +43,5 @@ block content
img(src='/icons/mml-logo.png')
h1 Er is iets mis gegaan tijdens het ophalen van de benodigde informatie
h2 Je kunt proberen door te gaan naar het oude rooster of Magister
- a(href='http://www.meetingpointmco.nl/Roosters-AL/doc/') Oud rooster
+ a(href=baseMeetingpointUrl) Oud rooster
a(href='http://msa.magister.net/') Magister