guest_worker/www/worker_specs/script.js

74 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-11-01 18:30:50 +01:00
// DOM STUFF ///////////////////////////////////////////////////////////////////
2020-01-13 16:13:42 +01:00
var app = new Vue({
el: '#wrapper',
data: {
message: 'Hello Vue!',
hits: {
}
},
2020-01-22 16:04:13 +01:00
methods: {
formatPrice(value) {
let val = (value/1).toFixed(2).replace('.', ',')
return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".")
},
duration(date1, date2){
let s1 = Date.parse(date1) / 1000;
let s2 = Date.parse(date2) / 1000;
let interval = s1 - s2;
let minutes = Math.floor(interval / 60);
let seconds = interval % 60;
let o = `${seconds}`;
if( minutes > 0) {
o = `${minutes}` + o;
}
return o;
}
}
2020-01-13 16:13:42 +01:00
// watch: {
// hits: {
// deep: true
// }
// }
2019-11-01 18:30:50 +01:00
})
// SOCKET STUFF ////////////////////////////////////////////////////////////////
let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws')
ws.addEventListener('open', () => {
// ws.send('hi server')
})
ws.addEventListener('message', (event) => {
console.log('message: ' + event.data)
2020-01-13 16:13:42 +01:00
let hits = JSON.parse(event.data)
let a = {};
for(let hitid in app.hits) {
a[hitid] = app.hits[hitid];
2019-11-01 18:30:50 +01:00
}
2020-01-13 16:13:42 +01:00
for(let hit of hits){
a[hit.id] = hit;
2019-11-01 18:56:00 +01:00
}
2020-01-13 16:13:42 +01:00
app.hits = a;
2019-11-01 18:30:50 +01:00
})
// ANIMATION STUFF /////////////////////////////////////////////////////////////
2020-01-13 16:13:42 +01:00
//
//function update(step){
//
// if(!hit_finished) elapsed_time = `${new Date((Date.now() - request_time)).format('MM"m "ss"s"')}`
// if(hit_started){
// divs['elapsed_time'].innerHTML = elapsed_time
// }else{
// divs['elapsed_time'].innerHTML = `—`
// }
//}