force close working

This commit is contained in:
Qwann 2017-03-09 15:05:47 +01:00
parent 5694e4b9bc
commit 8e7b9e2fd3
7 changed files with 112 additions and 48 deletions

View file

@ -593,7 +593,8 @@ class GlobalPermissions(models.Model):
('order_to_inventory', "Générer un inventaire à partir d'une commande"),
('edit_balance_account', "Modifier la balance d'un compte"),
('change_account_password', "Modifier le mot de passe d'une personne de l'équipe"),
('special_add_account', "Créer un compte avec une balance initiale")
('special_add_account', "Créer un compte avec une balance initiale"),
('can_close_kfet', "Peut fermer manuelement la K-Fêt"),
)

View file

@ -1,7 +1,8 @@
function kfet_open(init_date, init_satus) {
function kfet_open(init_date, init_satus, init_force_close, force_close_url, force_open_url) {
// VARIABLES
var kfet_open_bullet = $('#kfet-open');
var open_status = $('#open_status');
var force_close_button = $('#force_close_button');
// bullet
var open_color = "#73C252";
var closed_color = "#B42B26";
@ -13,16 +14,25 @@ function kfet_open(init_date, init_satus) {
var kfet_open_date = init_date;
var kfet_open = init_status;
var force_close = init_force_close;
// EVENT
force_close_button.click(function() {
if (force_close) {
$.get(force_open_url, function(data) {});
} else {
$.get(force_close_url, function(data) {});
}
});
// INITIALISAITION
update_open_bullet();
update_open_status();
update_open();
update_force_button();
// On recherge toute les 30sec
// (dans le cas où le statut deviendrait inconn)
setInterval(function() {
update_open_bullet();
update_open_status();
update_open();
}, 30 * 1000); // 60 * 1000 milsec
// FONCTIONS
@ -39,31 +49,42 @@ function kfet_open(init_date, init_satus) {
return tmp;
}
function update_open_bullet() {
function do_kfet_close() {
kfet_open_bullet.css({'background-color': closed_color});
open_status.parent().css({'background-color': closed_color_status});
open_status.html("FERMÉE");
}
function do_kfet_open() {
kfet_open_bullet.css({'background-color': open_color});
open_status.parent().css({'background-color': open_color_status});
open_status.html("OUVERTE");
}
function do_kfet_unknown() {
kfet_open_bullet.css({'background-color': unknown_color});
open_status.parent().css({'background-color': unknown_color_status});
open_status.html("?????");
}
function update_open() {
nb_min = nb_min_diff();
console.log("BULLET | K-Fêt ouverte : " + kfet_open);
console.log("K-Fêt ouverte : " + (kfet_open&&(!force_close)));
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
if (nb_min > 15) {
kfet_open_bullet.css({'background-color': unknown_color});
} else if (kfet_open){
kfet_open_bullet.css({'background-color': open_color});
if (force_close) {
do_kfet_close();
} else {
kfet_open_bullet.css({'background-color': closed_color});
if (nb_min > 15) {
do_kfet_unknown();
} else if (kfet_open){
do_kfet_open();
} else {
do_kfet_close();
}
}
}
function update_open_status() {
nb_min = nb_min_diff();
console.log("STATUS | K-Fêt ouverte : " + kfet_open);
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
if (nb_min > 15) {
open_status.parent().css({'background-color': unknown_color});
open_status.html("?????");
} else if (kfet_open){
open_status.parent().css({'background-color': open_color});
open_status.html("OUVERTE");
function update_force_button() {
if (force_close) {
force_close_button.html('Réouvrir la K-Fêt');
} else {
open_status.parent().css({'background-color': closed_color});
open_status.html("FERMÉE");
force_close_button.html('Fermer manuellement');
}
}
// SYNCHRONIZATION
@ -76,12 +97,21 @@ function kfet_open(init_date, init_satus) {
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'];
if (data['door_action']) {
console.log("* Message reçu de la part de la porte.");
update_open_bullet();
update_open_status();
kfet_open_date = new Date(data['door_action']['kfet_open_date']);
kfet_open = data['door_action']['kfet_open'];
update_open();
}
if (data['force_action']) {
force_close = data['force_action']['force_close'];
console.log("* Message reçu de la part d'un-e utilisat-rice-eur. Close = " + force_close);
update_open();
update_force_button();
}
}
}

View file

@ -21,6 +21,26 @@
<script type="text/javascript" src="{% static 'kfet/js/kfet_open.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/reconnecting-websocket.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_status = {{ kfet_open | yesno:"true,false"}};
init_force_close = {{ kfet_force_close | yesno:"true,false"}};
force_close_url = "{% url 'kfet.force_close' %}?close";
force_open_url = "{% url 'kfet.force_close' %}";
kfet_open(init_date,
init_status,
init_force_close,
force_close_url,
force_open_url);
});
</script>
{% block extra_head %}{% endblock %}
{# Vieux IE pas comprendre HTML5 et Media Queries #}

View file

@ -57,15 +57,3 @@
</ul>
</div>
</nav>
<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_status = {{ kfet_open | yesno:"true,false"}};
kfet_open(init_date, init_status);
});
</script>

View file

@ -20,8 +20,8 @@
<div class="line line-big" id="open_status">?????</div>
</div>
<div class="buttons">
<a class="btn btn-primary btn-lg" href="#TODO">
Ouvrir manuellement
<a class="btn btn-primary btn-lg" id="force_close_button">
Fermer manuellement
</a>
</div>
</div>

View file

@ -211,7 +211,10 @@ urlpatterns = [
url('^kfet_open/$',
views.UpdateKfetOpen.as_view(),
name='kfet.settings.kfet_open'),
name='kfet.kfet_open'),
url('^force_close/$',
views.UpdateForceClose.as_view(),
name='kfet.force_close'),
# -----
# Transfers urls

View file

@ -94,15 +94,37 @@ class UpdateKfetOpen(View):
cache.set('KFET_OPEN_DATE', timezone.now())
# Websocket
websocket_data = {}
websocket_data['kfet_open'] = is_open
websocket_data['kfet_open_date'] = timezone.now()
websocket_data = {
'door_action': {
'kfet_open': is_open,
'kfet_open_date': timezone.now(),
},
}
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
(is_open_get, time) = KFET_OPEN()
return HttpResponse("%r at %s" % (is_open_get, time.isoformat()))
class UpdateForceClose(View):
def get(self, request, *args, **kwargs):
force_close = "close" in request.GET
cache.set('KFET_FORCE_CLOSE', force_close)
# Websocket
websocket_data = {
'force_action': {
'force_close': force_close,
},
}
consumers.KfetOpen.group_send('kfet.is_open', websocket_data)
force_close_get = KFET_FORCE_CLOSE()
time = timezone.now()
return HttpResponse("closed : %r at %s" % (force_close_get,
time.isoformat()))
@teamkfet_required
def login_genericteam(request):
# Check si besoin de déconnecter l'utilisateur de CAS