ls-vertretungsplan-desktop

UNOFFICIAL Desktop App for the schedule of Lornsenschule, Schleswig
git clone git://archive.git.mtrnord.blog/MTRNord/ls-vertretungsplan-desktop.git
Log | Files | Refs | README

commit ec1a3ef49f1b90f0f4f3a40e00ab85372c9419b8
parent cf3c01162115522fc0a15c663c9c3460416c1f56
Author: Marcel Radzio <Marcel Radzio>
Date:   Fri,  2 Sep 2016 13:37:31 +0200

Update API and add it. .codeclimate.yml is nnow fixed. Cache added

Diffstat:
M.codeclimate.yml | 5+++--
MREADME.md | 7+++----
Mapp/index.html | 113+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mapp/main.js | 11+++++------
Mapp/package.json | 3++-
5 files changed, 72 insertions(+), 67 deletions(-)

diff --git a/.codeclimate.yml b/.codeclimate.yml @@ -12,7 +12,8 @@ engines: fixme: enabled: true ratings: - paths: [] -exclude_paths: + paths: + - app/** +exclude_paths: - "app/js/**" - "app/css/**" diff --git a/README.md b/README.md @@ -1,12 +1,12 @@ # ls-vertretungsplan-desktop UNOFFICIAL Desktop App for the schedule of Lornsenschule, Schleswig -# NOT WORKING FOR YOU YET!!!!!! -This Desktop App uses an API by @johan12345 that is NOT managed by me! I don't have the right to use it here so I don't provide the link to it or an compiled version of it. +# Info about the API +This Desktop App uses an API by @johan12345 that is NOT managed by me. I am allowed to use it and to have it in the Git Source. To see the APP made by @johan12345 take a look at https://ls.vertretungsplan.me # How to Build (If you find the URL to the API ^^) 1. Clone the Repository 2. Run `npm install` 3. If You use Windows run `build.cmd` otherwise go to 4 -4. Everybody else go into the app directory and run `npm install` and now run `node build.js` in the root -\ No newline at end of file +4. Everybody else go into the app directory and run `npm install` and now run `node build.js` in the root diff --git a/app/index.html b/app/index.html @@ -32,27 +32,31 @@ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script> + /* + Refresh Button Snippets: + var remote = require('electron').remote + remote.getCurrentWindow().reload() + */ window.$ = window.jQuery = require('./js/jquery-3.1.0.min.js'); - var request = require("request") - //<!-- http://THIS_IS_AN_SECRET_DOMAIN --> - var url = "http://THIS_IS_AN_SECRET_DOMAIN/vertretungsplan?" + - "school=Schleswig_Lornsenschule" + - "&v=1337" + var request = require('request') + , cachedRequest = require('cached-request')(request) + , cacheDirectory = "cache"; + var url = "https://api.vertretungsplan.me/" + + "v2/" + + "substitutionschedules/" + + "Schleswig_Lornsenschule/" + + "schulervertretungsplan" + + "?client=desktop_marcel" - if (typeof jQuery == 'undefined') { - console.warn("JQUERY NOT LOADED!!!"); - } - - request({ + cachedRequest({ url: url, - json: true + json: true, + ttl: 1800000 }, function (error, response, body) { - if (!error && response.statusCode === 200) { - //var lsJson = JSON.parse(body); - document.all.school.innerHTML = body.schoolName + ' Vertretungsplan'; // Print the json response - for (var key in body.tage) { - if (body.tage.hasOwnProperty(key)) { + document.all.school.innerHTML = body.schoolId.replace(/_/g, ' ') + ' Vertretungsplan'; // Print the json response + for (var key in body.days) { + if (body.days.hasOwnProperty(key)) { ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // // @@ -61,49 +65,50 @@ // // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// - if (key == 1) { - classes = body.tage[key].klassen - for (var key in classes) { - if (classes.hasOwnProperty(key)) { - klassen = classes[key] - klasse = klassen.klasse - $("#vertretungen").append('<h3>' + klasse + '</h3>') - representations = classes[key].vertretung - for (var key in representations) { - if (representations.hasOwnProperty(key)) { - representations_details = representations[key] - var reg = new RegExp('[-]'); - lesson = representations_details.lesson - representation_type = representations_details.type - text = representations_details.text - if (representation_type == "Vertretung") { + if (key == 0) { + date = body.days[key].dateString + substitutions = body.days[key].substitutions + substitutions.sort(function(a, b){ + if (a.classes < b.classes) return -1; + if (b.classes < a.classes) return 1; + return 0; + }) + for (var key in substitutions) { + if (substitutions.hasOwnProperty(key)) { + klasse = substitutions[key].classes + if ($("#klasse").attr("klasse") != klasse) { + $("#vertretungen").append('<h3 id="klasse" klasse="' + klasse + '">' + klasse + '</h3>') + } + var reg = new RegExp('[-]'); + lesson = substitutions[key].lesson + substitutions_type = substitutions[key].type + text = substitutions[key].text + if (substitutions_type == "Vertretung") { + if (lesson.match(reg)) { + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + }else{ + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + } + }else{ + if (substitutions_type == "Betreuung") { + if (lesson.match(reg)) { + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + }else{ + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + } + }else{ + if (substitutions_type == "Unterricht geändert") { if (lesson.match(reg)) { - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #FFA000; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') }else{ - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #FFA000; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') } }else{ - if (representation_type == "Betreuung") { + if (substitutions_type == "Lehrertausch") { if (lesson.match(reg)) { - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #9C27B0; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') }else{ - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #2196F3; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') - } - }else{ - if (representation_type == "Unterricht geändert") { - if (lesson.match(reg)) { - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #FFA000; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') - }else{ - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #FFA000; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') - } - }else{ - if (representation_type == "Lehrertausch") { - if (lesson.match(reg)) { - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #9C27B0; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 300%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') - }else{ - $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #9C27B0; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + representation_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') - } - } + $("#vertretungen").append('<div class="card card-block" style="height: 10%; background-color: #9C27B0; color: #fff">' + '<div class="row">' + '<div class="col-md-4" style="position: relative; margin: 0;"><p style="font-size: 350%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">' + lesson + '</p></div>' + '<div class="col-md-8"><h4>' + substitutions_type + '</h4></br><h7>' + text + '</h7></div>' + '</div>' + '</div>') } } } @@ -113,7 +118,7 @@ } } } - } + } }else{ $("#Main").append('<p class="bg-danger">Scheinbar geht dein Internet nicht :/</p>') } diff --git a/app/main.js b/app/main.js @@ -7,9 +7,9 @@ let win function update () { var feedUrl = 'https://ls-desktop.herokuapp.com/update/win32/:' + app.getVersion(); autoUpdater.setFeedURL(feedUrl); - + autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) { - + var index = dialog.showMessageBox(mainWindow, { type: 'info', buttons: [i18n.__('Restart'), i18n.__('Later')], @@ -17,11 +17,11 @@ function update () { message: i18n.__('The new version has been downloaded. Please restart the application to apply the updates.'), detail: releaseName + "\n\n" + releaseNotes }); - + if (index === 1) { return; } - + quitAndUpdate(); }); } @@ -69,4 +69,4 @@ app.on('activate', () => { }) // In this file you can include the rest of your app's specific main process -// code. You can also put them in separate files and require them here. -\ No newline at end of file +// code. You can also put them in separate files and require them here. diff --git a/app/package.json b/app/package.json @@ -1,11 +1,12 @@ { "name": "ls_vertretungsplan_desktop", - "version": "0.0.2", + "version": "0.0.3", "description": "Eine Anwendung die den Vertretungsplan auf dem Desktop anzeigt", "main": "./main.js", "author": "Marcel Radzio <info@nordgedanken.de>", "license": "", "dependencies": { + "cached-request": "^1.0.0", "request": "^2.69.0" } }