guest_worker/www/backend/script.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-22 13:36:52 +00:00
var app = new Vue({
el: '#wrapper',
data: {
hit: {}
},
})
var hits = {};
var hitIds = [];
// fetch ?all in database
let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws?all')
ws.addEventListener('open', () => {
// ws.send('hi server')
})
ws.addEventListener('message', (event) => {
console.log('message: ')
let load_hits = JSON.parse(event.data)
for(let hit of load_hits) {
console.log(hit);
hits[hit.id] = hit;
if(hit.scanned_at && hitIds.indexOf(hit.id) < 0){
// only add if indeed scanned
hitIds.push(hit.id);
}
}
})
var currentI = 0;
setInterval(function(e){
if(hitIds.length < 1) {
return;
}
currentI = (currentI + 1) % hitIds.length;
let currentHitId = hitIds[currentI];
console.log(currentHitId);
let hit = hits[currentHitId];
hit['visible'] = false;
app.hit['visible'] = false;
setTimeout(() => {
app.hit = hits[currentHitId]
}, 1000);
setTimeout(() => {
app.hit['visible'] = true;
let wrapperEl = document.getElementById("collaborators");
let innerEl = document.getElementById("collab_items");
2020-01-23 12:24:53 +00:00
let size = 80;
2020-01-22 13:36:52 +00:00
do {
innerEl.style.fontSize = size + "%";
size --;
2020-01-23 12:24:53 +00:00
} while(innerEl.clientHeight > wrapperEl.clientHeight && size > 27);
2020-01-22 13:36:52 +00:00
}, 1100);
2020-01-23 12:24:53 +00:00
}, 7000);