This commit is contained in:
nicco
2017-12-25 00:50:54 +01:00
parent 1f6dffc690
commit 7ec7eb5b4b
41 changed files with 576 additions and 2 deletions

18
app/res/js/main.js Normal file
View File

@@ -0,0 +1,18 @@
'use strict'
const S = {
stations: [33000312, 33000311],
url: 'https://webapi.vvo-online.de/dm'
}
function parseTime(str) {
if (str === undefined)
return
if (str instanceof Date)
return str
return new Date(parseInt(str.slice(6, -2).split('+')[0]))
}
new Vue({
el: '#app'
})

60
app/res/js/vendor/fittext.js vendored Normal file
View File

@@ -0,0 +1,60 @@
/*!
* FitText.js 1.0 jQuery free version
*
* Copyright 2011, Dave Rupert http://daverupert.com
* Released under the WTFPL license
* http://sam.zoy.org/wtfpl/
* Modified by Slawomir Kolodziej http://slawekk.info
*
* Date: Tue Aug 09 2011 10:45:54 GMT+0200 (CEST)
*/
(function () {
var addEvent = function (el, type, fn) {
if (el.addEventListener)
el.addEventListener(type, fn, false);
else
el.attachEvent('on' + type, fn);
};
var extend = function (obj, ext) {
for (var key in ext)
if (ext.hasOwnProperty(key))
obj[key] = ext[key];
return obj;
};
window.fitText = function (el, kompressor, options) {
var settings = extend({
'minFontSize': -1 / 0,
'maxFontSize': 1 / 0
}, options);
var fit = function (el) {
var compressor = kompressor || 1;
var resizer = function () {
el.style.fontSize = Math.max(Math.min(el.clientWidth / (compressor * 10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)) + 'px';
};
// Call once to set.
resizer();
// Bind events
// If you have any js library which support Events, replace this part
// and remove addEvent function (or use original jQuery version)
addEvent(window, 'resize', resizer);
addEvent(window, 'orientationchange', resizer);
};
if (el.length)
for (var i = 0; i < el.length; i++)
fit(el[i]);
else
fit(el);
// return set of elements
return el;
};
})();

6
app/res/js/vendor/vue.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,29 @@
Vue.component('dvb-date', {
template: `<div id="date">{{cur}}</div>`,
data() {
return {
hz: 3,
cur: '...',
}
},
methods: {
update() {
this.cur = new Date().toLocaleDateString('de-DE', {
weekday: 'short',
year: 'numeric',
month: 'numeric',
day: 'numeric'
})
},
startWatcher() {
this.update()
this.watcherId = setInterval(this.update, this.hz * 1000)
},
stopWatcher() {
clearInterval(this.watcherId)
},
},
mounted() {
this.startWatcher()
},
})

View File

@@ -0,0 +1,86 @@
Vue.component('dvb-line', {
template: '#tmpl-dvb-line',
data() {
return {
hz: 30,
departures: null,
directions: {},
stopName: '',
lineNumber: ''
}
},
props: {
stopId: Number,
line: Number
},
filters: {
formatTime(d) {
if (d === undefined) return
d = this.parseTime(d)
let
h = d.getHours(),
m = d.getMinutes()
h = h < 10 ? `0${h}` : h
m = m < 10 ? `0${m}` : m
return `${h}:${m}`
},
timeInterval(a, b) {
a = this.parseTime(a)
b = this.parseTime(b)
return ((b - a) / 1000 / 60) | 0
}
},
methods: {
startWatcher() {
this.update()
this.watcherId = setInterval(this.update, 1000 * this.hz)
},
stopWatcher() {
clearInterval(this.watcherId)
},
update() {
console.log('Updating...')
fetch('https://webapi.vvo-online.de/dm', {
mode: 'cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({
'stopid': this.stopId
})
})
.then(res => res.json())
.then(res => {
this.stopName = res.Name
this.departures = res.Departures.filter(departure => departure.LineName === this.line)
this.formatDirections()
})
},
formatDirections() {
// Reset names & data
this.directions = {}
for (var i of this.departures) {
// Initial directions if null
if (!(i.Direction in this.directions))
this.directions[i.Direction] = []
// Inset departure into array
this.directions[i.Direction].push(i)
}
this.directions = Object.keys(this.directions)
.sort().reduce((a, v) => {
a[v] = this.directions[v];
return a;
}, {});
},
},
created() {
this.lineNumber = this.line
this.stopId = this.stopId
this.startWatcher()
},
})

View File

@@ -0,0 +1,31 @@
Vue.component('dvb-time', {
template: `<div id="time">{{cur}}</div>`,
data() {
return {
hz: 0.5,
cur: '...',
}
},
methods: {
update() {
this.cur = new Date().toLocaleDateString('de-DE', {
formatMatcher: 'best fit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
.split(',')[1]
.trim()
},
startWatcher() {
this.update()
this.watcherId = setInterval(this.update, this.hz * 1000)
},
stopWatcher() {
clearInterval(this.watcherId)
},
},
mounted() {
this.startWatcher()
},
})

View File

@@ -0,0 +1,63 @@
Vue.component('dvb-weather', {
template: '#tmpl-dvb-weather',
props: {
offset: ['Number']
},
data() {
return {
hz: 10,
cur: '...',
images: {
'sunny': 11,
'rain': 4,
'snow': 6,
'clouds': 10,
'storm': 1,
'': 9,
},
states: {
'fog': 2,
'wind': 3,
'frosty': 8,
'wet': 12,
'cold': 7,
},
static: {
'0': {
image: 11,
temp: '23'
},
'14400': {
image: 4,
temp: '11'
},
'28800': {
image: 6,
temp: '-1'
},
'43200': {
image: 1,
temp: '7'
},
}
}
},
methods: {
startWatcher() {
this.update()
this.watcherId = setInterval(this.update, this.hz * 1000)
},
stopWatcher() {
clearInterval(this.watcherId)
},
update() {},
},
created() {
this.startWatcher()
},
mounted() {
const data = this.static[this.offset]
this.$el.style.backgroundImage = `url('res/img/${data.image}.png')`
this.cur = data.temp
},
})