diff --git a/cof/settings_dev.py b/cof/settings_dev.py
index f6521222..4d604cac 100644
--- a/cof/settings_dev.py
+++ b/cof/settings_dev.py
@@ -83,6 +83,7 @@ TEMPLATES = [
'django.core.context_processors.static',
'gestioncof.shared.context_processor',
'kfet.context_processors.auth',
+ 'kfet.context_processors.kfet_open',
],
},
},
diff --git a/kfet/consumers.py b/kfet/consumers.py
index dcd69bdf..72e3b21e 100644
--- a/kfet/consumers.py
+++ b/kfet/consumers.py
@@ -24,3 +24,21 @@ class KPsul(JsonWebsocketConsumer):
def disconnect(self, message, **kwargs):
pass
+
+class KfetOpen(JsonWebsocketConsumer):
+
+ # Set to True if you want them, else leave out
+ strict_ordering = False
+ slight_ordering = False
+
+ def connection_groups(self, **kwargs):
+ return ['kfet.is_open']
+
+ def connect(self, message, **kwargs):
+ pass
+
+ def receive(self, content, **kwargs):
+ pass
+
+ def disconnect(self, message, **kwargs):
+ pass
diff --git a/kfet/context_processors.py b/kfet/context_processors.py
index ef4f2e64..f3b8f76f 100644
--- a/kfet/context_processors.py
+++ b/kfet/context_processors.py
@@ -5,6 +5,8 @@ from __future__ import (absolute_import, division,
from builtins import *
from django.contrib.auth.context_processors import PermWrapper
+from .views import KFET_OPEN
+
def auth(request):
if hasattr(request, 'real_user'):
@@ -13,3 +15,11 @@ def auth(request):
'perms': PermWrapper(request.real_user),
}
return {}
+
+
+def kfet_open(resquest):
+ (kfet_open, kfet_open_date) = KFET_OPEN()
+ return {
+ 'kfet_open': kfet_open,
+ 'kfet_open_date': kfet_open_date,
+ }
diff --git a/kfet/routing.py b/kfet/routing.py
index 5ea343cb..5db0101f 100644
--- a/kfet/routing.py
+++ b/kfet/routing.py
@@ -9,4 +9,5 @@ from kfet import consumers
channel_routing = [
route_class(consumers.KPsul, path=r"^/ws/k-fet/k-psul/$"),
+ route_class(consumers.KfetOpen, path=r"^/ws/k-fet/is_open/$"),
]
diff --git a/kfet/static/kfet/css/nav.css b/kfet/static/kfet/css/nav.css
index 5ffc7b24..9e2c5462 100644
--- a/kfet/static/kfet/css/nav.css
+++ b/kfet/static/kfet/css/nav.css
@@ -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;
}
diff --git a/kfet/static/kfet/js/kfet_open.js b/kfet/static/kfet/js/kfet_open.js
new file mode 100644
index 00000000..9f5e4c22
--- /dev/null
+++ b/kfet/static/kfet/js/kfet_open.js
@@ -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();
+ }
+}
diff --git a/kfet/templates/kfet/base.html b/kfet/templates/kfet/base.html
index 173a5fb7..7587cb7b 100644
--- a/kfet/templates/kfet/base.html
+++ b/kfet/templates/kfet/base.html
@@ -18,6 +18,8 @@
+
+
{% block extra_head %}{% endblock %}
diff --git a/kfet/templates/kfet/base_nav.html b/kfet/templates/kfet/base_nav.html
index b5c98375..d884d110 100644
--- a/kfet/templates/kfet/base_nav.html
+++ b/kfet/templates/kfet/base_nav.html
@@ -12,6 +12,7 @@
+