forked from DGNum/gestioCOF
kfet_open uses moment.js
This commit is contained in:
parent
15873085e1
commit
5c6a73c597
5 changed files with 11 additions and 20 deletions
|
@ -22,6 +22,6 @@ def kfet_open(request):
|
|||
kfet_force_close = KFET_FORCE_CLOSE()
|
||||
return {
|
||||
'kfet_open': kfet_open,
|
||||
'kfet_open_date': kfet_open_date,
|
||||
'kfet_open_date': kfet_open_date.isoformat(),
|
||||
'kfet_force_close': kfet_force_close,
|
||||
}
|
||||
|
|
|
@ -56,18 +56,8 @@ function kfet_open(init_date, init_status, init_force_close, force_close_url, fo
|
|||
});
|
||||
}
|
||||
|
||||
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 kfet_open_min() {
|
||||
return moment().diff(kfet_open_date, 'minute')
|
||||
}
|
||||
function do_kfet_close() {
|
||||
kfet_open_bullet.css({'background-color': closed_color});
|
||||
|
@ -85,7 +75,7 @@ function kfet_open(init_date, init_status, init_force_close, force_close_url, fo
|
|||
open_status.html("?????");
|
||||
}
|
||||
function update_open() {
|
||||
var nb_min = nb_min_diff();
|
||||
var nb_min = kfet_open_min();
|
||||
console.log("K-Fêt ouverte : " + (kfet_open&&(!force_close)));
|
||||
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
|
||||
if (force_close) {
|
||||
|
@ -121,7 +111,7 @@ function kfet_open(init_date, init_status, init_force_close, force_close_url, fo
|
|||
if (data['door_action']) {
|
||||
console.log("* Message reçu de la part de la porte.");
|
||||
|
||||
kfet_open_date = new Date(data['door_action']['kfet_open_date']);
|
||||
kfet_open_date = moment.utc(data['door_action']['kfet_open_date']);
|
||||
kfet_open = data['door_action']['kfet_open'];
|
||||
|
||||
update_open();
|
||||
|
|
|
@ -21,13 +21,17 @@
|
|||
<script type="text/javascript" src="{% static 'kfet/js/kfet_open.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/reconnecting-websocket.js' %}"></script>
|
||||
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment-fr.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment-timezone-with-data-2010-2020.js' %}"></script>
|
||||
|
||||
{# K-Fêt open #}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#genericteam').on('click', function () {
|
||||
setTimeout(function () { location.reload() }, 1000);
|
||||
});
|
||||
init_date = new Date("{{ kfet_open_date.isoformat }}");
|
||||
init_date = moment.utc("{{ kfet_open_date }}");
|
||||
init_status = {{ kfet_open | yesno:"true,false"}};
|
||||
init_force_close = {{ kfet_force_close | yesno:"true,false"}};
|
||||
force_close_url = "{% url 'kfet.force_close' %}?close";
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
<script type="text/javascript" src="{% static 'kfet/js/js.cookie.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/jquery-ui.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/jquery-confirm.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment-fr.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/moment-timezone-with-data-2010-2020.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/history.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class UpdateKfetOpen(View):
|
|||
websocket_data = {
|
||||
'door_action': {
|
||||
'kfet_open': is_open,
|
||||
'kfet_open_date': timezone.now(),
|
||||
'kfet_open_date': timezone.now().isoformat(),
|
||||
},
|
||||
}
|
||||
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
|
||||
|
|
Loading…
Reference in a new issue