guest_worker/www/worker_specs/script.js
2020-01-22 16:04:13 +01:00

73 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// DOM STUFF ///////////////////////////////////////////////////////////////////
var app = new Vue({
el: '#wrapper',
data: {
message: 'Hello Vue!',
hits: {
}
},
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;
}
}
// watch: {
// hits: {
// deep: true
// }
// }
})
// 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)
let hits = JSON.parse(event.data)
let a = {};
for(let hitid in app.hits) {
a[hitid] = app.hits[hitid];
}
for(let hit of hits){
a[hit.id] = hit;
}
app.hits = a;
})
// ANIMATION STUFF /////////////////////////////////////////////////////////////
//
//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 = `—`
// }
//}