From e00bfab629d57bedf871ef30a5bc8d37f212a434 Mon Sep 17 00:00:00 2001 From: Gustavo274 Date: Wed, 6 Oct 2021 10:56:54 -0300 Subject: [PATCH] Websocket cronometro funcionando p1 --- frontend/src/__apps/painel/main.js | 10 ++++- sapl/painel/urls.py | 4 +- sapl/painel/views.py | 29 ++++++++------- .../migrations/0057_auto_20211006_0917.py | 37 +++++++++++++++++++ .../migrations/0058_auto_20211006_0930.py | 34 +++++++++++++++++ .../migrations/0059_auto_20211006_0935.py | 22 +++++++++++ .../migrations/0060_auto_20211006_1006.py | 28 ++++++++++++++ sapl/sessao/models.py | 16 +++++++- sapl/sessao/views.py | 1 - sapl/templates/sessao/painel.html | 26 +++++++++---- 10 files changed, 181 insertions(+), 26 deletions(-) create mode 100644 sapl/sessao/migrations/0057_auto_20211006_0917.py create mode 100644 sapl/sessao/migrations/0058_auto_20211006_0930.py create mode 100644 sapl/sessao/migrations/0059_auto_20211006_0935.py create mode 100644 sapl/sessao/migrations/0060_auto_20211006_1006.py diff --git a/frontend/src/__apps/painel/main.js b/frontend/src/__apps/painel/main.js index 8a9d34ef1..3ebe82563 100644 --- a/frontend/src/__apps/painel/main.js +++ b/frontend/src/__apps/painel/main.js @@ -47,7 +47,8 @@ const v = new Vue({ // eslint-disable-line tipo_resultado: '', tipo_votacao: '', teste: null, - running: 0 + running: 0, + status_cronometro_discurso: '' } }, methods: { @@ -113,6 +114,7 @@ const v = new Vue({ // eslint-disable-line this.sessao_plenaria_hora_inicio = 'Hora Início: ' + objeto.sessao_plenaria_hora_inicio this.sessao_solene = objeto.sessao_solene this.sessao_solene_tema = objeto.sessao_solene_tema + this.status_cronometro_discurso = objeto.status_cronometro this.presentes = objeto.presentes this.presentes.forEach(parlamentar => { @@ -170,6 +172,12 @@ const v = new Vue({ // eslint-disable-line res = new Date(temp - this.cronometro_consideracoes) this.cronometro_consideracoes = this.formatTime(res) } + if (this.status_cronometro_discurso === 'I') { + this.start(1) + console.log(cronometroStart) + } else if (this.status_cronometro_discurso === 'S') { + this.stop(1) + } }, formatTime (time) { var tempo = '00:' + time.getMinutes().toLocaleString('en-US', { diff --git a/sapl/painel/urls.py b/sapl/painel/urls.py index 71b6573cf..c1ac7ac41 100644 --- a/sapl/painel/urls.py +++ b/sapl/painel/urls.py @@ -3,7 +3,7 @@ from django.conf.urls import url from django.urls import path from .apps import AppConfig -from .views import (cronometro_painel, get_dados_painel, painel_mensagem_view, +from .views import (cronometro_painel, get_cronometro_status, get_dados_painel, painel_mensagem_view, painel_parlamentar_view, painel_view, painel_votacao_view, switch_painel, verifica_painel, votante_view) @@ -18,6 +18,8 @@ urlpatterns = [ name='painel_parlamentar'), url(r'^painel/switch-painel$', switch_painel, name="switch_painel"), + url(r'^painel/get-cronometro-status$', get_cronometro_status, + name="get_cronometro_status"), url(r'^painel/votacao$', painel_votacao_view, name='painel_votacao'), url(r'^painel/verifica-painel$', verifica_painel, name="verifica_painel"), diff --git a/sapl/painel/views.py b/sapl/painel/views.py index 61199a16c..6741cbaba 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -352,20 +352,23 @@ def cronometro_painel(request): return HttpResponse({}) -def get_cronometro_status(request, name): +@user_passes_test(check_permission) +def get_cronometro_status(request): pk = request.POST['pk_sessao'] sessao = SessaoPlenaria.objects.get(id=pk) - logger = logging.getLogger(__name__) - username = request.user.username - try: - logger.debug("user=" + username + ". Tentando obter cronometro.") - cronometro = request.session[name] - sessao.status_cronometro = cronometro - except KeyError as e: - logger.error("user=" + username + - ". Erro ao obter cronometro. Retornado como vazio. " + str(e)) - cronometro = '' - sessao.save() + ligado = json.loads(request.POST['ligado']) + tipo = json.loads(request.POST['teste']) + + + if ligado: + if tipo == 1: + sessao.status_cronometro_discurso = 'I' + sessao.save() + else: + if tipo == 1: + sessao.status_cronometro_discurso = 'S' + sessao.save() + tasks.get_dados_painel_final(pk) return JsonResponse({}) @@ -590,7 +593,7 @@ def get_dados_painel(pk): 'sessao_solene': sessao.tipo.nome == "Solene", 'sessao_finalizada': sessao.finalizada, 'tema_solene': sessao.tema_solene, - 'status_cronometro': sessao.status_cronometro, + 'status_cronometro': sessao.status_cronometro_discurso, 'cronometro_aparte': get_cronometro_value('aparte'), 'cronometro_discurso': get_cronometro_value('discurso'), 'cronometro_ordem': get_cronometro_value('ordem'), diff --git a/sapl/sessao/migrations/0057_auto_20211006_0917.py b/sapl/sessao/migrations/0057_auto_20211006_0917.py new file mode 100644 index 000000000..5a70f06f9 --- /dev/null +++ b/sapl/sessao/migrations/0057_auto_20211006_0917.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.24 on 2021-10-06 12:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0056_sessaoplenaria_status_cronometro'), + ] + + operations = [ + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro', + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_aparte', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro aparte'), + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_consideracoes_finais', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro consideracoes finais'), + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_discurso', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro discurso'), + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_ordem_do_dia', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro ordem do dia'), + ), + ] diff --git a/sapl/sessao/migrations/0058_auto_20211006_0930.py b/sapl/sessao/migrations/0058_auto_20211006_0930.py new file mode 100644 index 000000000..5ee0a7c1d --- /dev/null +++ b/sapl/sessao/migrations/0058_auto_20211006_0930.py @@ -0,0 +1,34 @@ +# Generated by Django 2.2.24 on 2021-10-06 12:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0057_auto_20211006_0917'), + ] + + operations = [ + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro_aparte', + ), + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro_consideracoes_finais', + ), + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro_discurso', + ), + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro_ordem_do_dia', + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro painel'), + ), + ] diff --git a/sapl/sessao/migrations/0059_auto_20211006_0935.py b/sapl/sessao/migrations/0059_auto_20211006_0935.py new file mode 100644 index 000000000..0cc131f21 --- /dev/null +++ b/sapl/sessao/migrations/0059_auto_20211006_0935.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.24 on 2021-10-06 12:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0058_auto_20211006_0930'), + ] + + operations = [ + migrations.RemoveField( + model_name='sessaoplenaria', + name='status_cronometro', + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_discurso', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro discurso'), + ), + ] diff --git a/sapl/sessao/migrations/0060_auto_20211006_1006.py b/sapl/sessao/migrations/0060_auto_20211006_1006.py new file mode 100644 index 000000000..8abcf20c4 --- /dev/null +++ b/sapl/sessao/migrations/0060_auto_20211006_1006.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.24 on 2021-10-06 13:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0059_auto_20211006_0935'), + ] + + operations = [ + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_aparte', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro discurso'), + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_consideracoes_finais', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro discurso'), + ), + migrations.AddField( + model_name='sessaoplenaria', + name='status_cronometro_ordem_do_dia', + field=models.CharField(default='S', max_length=1, verbose_name='Status do cronômetro discurso'), + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 559b6d262..a77e16144 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -157,9 +157,21 @@ class SessaoPlenaria(models.Model): painel_aberto = models.BooleanField(blank=True, default=False, verbose_name=_('Painel está aberto?')) - status_cronometro = models.CharField( + status_cronometro_discurso = models.CharField( max_length=1, - verbose_name=_('Status do cronômetro painel'), + verbose_name=_('Status do cronômetro discurso'), + default='S') + status_cronometro_aparte = models.CharField( + max_length=1, + verbose_name=_('Status do cronômetro discurso'), + default='S') + status_cronometro_ordem_do_dia = models.CharField( + max_length=1, + verbose_name=_('Status do cronômetro discurso'), + default='S') + status_cronometro_consideracoes_finais = models.CharField( + max_length=1, + verbose_name=_('Status do cronômetro discurso'), default='S') tipo = models.ForeignKey(TipoSessaoPlenaria, on_delete=models.PROTECT, diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 12512bbfc..bc69b3029 100755 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -2,7 +2,6 @@ import logging from collections import OrderedDict from re import sub -from sapl.painel.views import get_cronometro_status from django.contrib import messages from django.contrib.auth.decorators import permission_required diff --git a/sapl/templates/sessao/painel.html b/sapl/templates/sessao/painel.html index 44f345a75..d2b773e1d 100644 --- a/sapl/templates/sessao/painel.html +++ b/sapl/templates/sessao/painel.html @@ -35,7 +35,8 @@
-
+
+
@@ -148,22 +149,20 @@ $(function() { $('#discursoStart').click(function() { - if ($('#discursoStart').text() == 'Iniciar'){ - $.get('/painel/cronometro', { tipo: 'discurso', action: 'start' } ); $('#discursoReset').hide(); - $('#discurso').runner('start'); - $('#discursoStart').text('Parar'); + $('#discurso').runner('start'); - } else { + }); + + $('#discursoStop').click(function() { $.get('/painel/cronometro', { tipo: 'discurso', action: 'stop' } ); $('#discursoReset').show(); $('#discurso').runner('stop'); - $('#discursoStart').text('Iniciar'); - } + }); $('#discursoReset').click(function() { @@ -356,6 +355,17 @@ function switch_painel(aberto) { } } +function switch_cronometro(ligado, teste){ + var pk_sessao = {{root_pk}}; + + $.ajax({ + data: {pk_sessao: pk_sessao, ligado: ligado, teste: teste}, + type: 'POST', + url: "{% url 'sapl.painel:get_cronometro_status' %}", + headers: {'X-CSRFToken': getCookie('csrftoken')}, + }); +} + $(document).ready(function(){ var pk_sessao = {{root_pk}}; var botao_abrir = $('#id_abrir_painel');