kfetOpen bullet working

This commit is contained in:
Qwann 2017-02-11 00:29:12 +01:00
parent 4808650fa0
commit f87f1ceff1
10 changed files with 121 additions and 6 deletions

View file

@ -14,7 +14,7 @@ nav {
}
nav .navbar-brand {
padding:3px 25px;
padding:3px 15px 3px 25px;
}
nav .navbar-brand img {
@ -44,6 +44,24 @@ nav a {
background-color:#C8102E;
}
#kfet-open {
font-weight: bold;
font-size: 14px;
width:10px;
height:10px;
text-transform: uppercase;
border-radius: 50%;
background-color: white;
display: inline-block;
}
#kfet-open-wrapper {
padding-top: 18px;
margin: 0px 10px;
display: inline-block;
line-height: 10px;
}
.dropdown-menu {
padding:0;
}

View file

@ -0,0 +1,54 @@
function kfet_open(init_date, init_satus) {
// VARIABLES
var kfet_open_bullet = $('#kfet-open');
var open_color = "#73C252";
var closed_color = "#B42B26";
var unknown_color = "#ECD03E";
var kfet_open_date = init_date;
var kfet_open = init_status;
// INITIALISAITION
update_open_bullet();
// FONCTIONS
function nb_min_diff() {
var date_now = new Date();
// On calcule le nb de minutes depuis le dernier
// envoi d'information
tmp = date_now - kfet_open_date;
tmp = Math.floor(tmp/1000); // Nombre de secondes entre les 2 dates
diff_sec = tmp % 60; // Extraction du nombre de secondes
tmp = Math.floor((tmp-diff_sec)/60); // Nombre de minutes (partie entière)
return tmp;
}
function update_open_bullet() {
nb_min = nb_min_diff();
console.log("K-Fêt ouverte : " + kfet_open);
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
if (nb_min > 5) {
kfet_open_bullet.css({'background-color': unknown_color});
} else if (kfet_open){
kfet_open_bullet.css({'background-color': open_color});
} else {
kfet_open_bullet.css({'background-color': closed_color});
}
}
// SYNCHRONIZATION
websocket_msg_default = {'last_op': 0}
var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws';
var location_host = window.location.host;
var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host;
var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/is_open/");
socket.onmessage = function(e) {
var data = $.extend({}, websocket_msg_default, JSON.parse(e.data));
console.log("Message reçu de la part de la porte.");
kfet_open_date = new Date(data['kfet_open_date']);
kfet_open = data['kfet_open'];
update_open_bullet();
}
}