From e85f232334d0e8dbc5106fab8dc54ffa5aa9e86e Mon Sep 17 00:00:00 2001 From: AlGouvea Date: Mon, 27 Sep 2021 10:57:29 -0300 Subject: [PATCH] =?UTF-8?q?Dados=20da=20sess=C3=A3o=20obtidos=20pelo=20Web?= =?UTF-8?q?Socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/__apps/painel/main.js | 10 +++++----- sapl/painel/consumers.py | 23 +++-------------------- sapl/painel/urls.py | 3 +-- sapl/painel/views.py | 28 +++++++++++----------------- 4 files changed, 20 insertions(+), 44 deletions(-) diff --git a/frontend/src/__apps/painel/main.js b/frontend/src/__apps/painel/main.js index 6d9c6ef72..52cda6163 100644 --- a/frontend/src/__apps/painel/main.js +++ b/frontend/src/__apps/painel/main.js @@ -249,15 +249,15 @@ const v = new Vue({ // eslint-disable-line this.clockRunning(crono) }, 100) }, - foi: function foi () { - socket.send('Teste de entrada') + call_data: function call_data () { + socket.send('Calling Data...') }, pollData () { this.fetchData() this.polling = setInterval(() => { // console.info('Fetching data from backend') - this.foi() - }, 30000) + this.call_data() + }, 300) } }, beforeDestroy () { @@ -271,7 +271,7 @@ const v = new Vue({ // eslint-disable-line socket.onmessage = function (e) { this.teste = JSON.parse(e.data) - console.log(this.teste.sessao_plenaria) + console.log('Data Received...') } socket.onclose = function (e) { diff --git a/sapl/painel/consumers.py b/sapl/painel/consumers.py index 91a437dfa..ff546241c 100644 --- a/sapl/painel/consumers.py +++ b/sapl/painel/consumers.py @@ -2,10 +2,7 @@ import json import requests from asgiref.sync import async_to_sync from channels.generic.websocket import AsyncJsonWebsocketConsumer -from sapl.sessao.models import (ExpedienteMateria, OradorExpediente, OrdemDia, - PresencaOrdemDia, RegistroVotacao, - SessaoPlenaria, SessaoPlenariaPresenca, - VotoParlamentar, RegistroLeitura) +from sapl.painel import views class PainelConsumer(AsyncJsonWebsocketConsumer): @@ -14,29 +11,15 @@ class PainelConsumer(AsyncJsonWebsocketConsumer): await self.accept() async def disconnect(self, close_code): - print('Disconectado:', close_code) + print('Desconectado:', close_code) pass - async def join_group(self): - print('Group') - await self.channel_layer.group_add('painel', self.channel_name) - async def receive(self, text_data): - print('Received Message:' + text_data) await self.send_data(786) async def send_data(self, id): - sessao = SessaoPlenaria.objects.get(id=id) + response = views.get_dados_painel(id) - response = { - 'sessao_plenaria': str(sessao), - 'sessao_plenaria_data': sessao.data_inicio.strftime('%d/%m/%Y'), - 'sessao_plenaria_hora_inicio': sessao.hora_inicio, - 'sessao_solene': sessao.tipo.nome == "Solene", - 'sessao_finalizada': sessao.finalizada, - 'tema_solene': sessao.tema_solene, - 'status_painel': sessao.painel_aberto, - } await self.send_json(response) \ No newline at end of file diff --git a/sapl/painel/urls.py b/sapl/painel/urls.py index 51b660e9b..71b6573cf 100644 --- a/sapl/painel/urls.py +++ b/sapl/painel/urls.py @@ -5,7 +5,7 @@ from django.urls import path from .apps import AppConfig from .views import (cronometro_painel, get_dados_painel, painel_mensagem_view, painel_parlamentar_view, painel_view, painel_votacao_view, - switch_painel, verifica_painel, votante_view, room) + switch_painel, verifica_painel, votante_view) app_name = AppConfig.name @@ -26,5 +26,4 @@ urlpatterns = [ url(r'^voto-individual/$', votante_view, name='voto_individual'), - path(r'chat/', room, name='room'), ] diff --git a/sapl/painel/views.py b/sapl/painel/views.py index eb31fa1d5..77bd16b7e 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -348,7 +348,7 @@ def cronometro_painel(request): return HttpResponse({}) -def get_cronometro_status(request, name): +def get_cronometro_status(name): logger = logging.getLogger(__name__) username = request.user.username try: @@ -361,7 +361,7 @@ def get_cronometro_status(request, name): return cronometro -def get_cronometro_value(request, name): +def get_cronometro_value(name): if name == 'discurso': result = ConfiguracoesAplicacao.objects.first().cronometro_discurso if name == 'aparte': @@ -562,8 +562,8 @@ def get_votos(response, materia): return response -@user_passes_test(check_permission) -def get_dados_painel(request, pk): +#@user_passes_test(check_permission) +def get_dados_painel(pk): sessao = SessaoPlenaria.objects.get(id=pk) casa = CasaLegislativa.objects.first() @@ -582,15 +582,15 @@ def get_dados_painel(request, pk): 'sessao_solene': sessao.tipo.nome == "Solene", 'sessao_finalizada': sessao.finalizada, 'tema_solene': sessao.tema_solene, - 'status_cronometro_discurso': get_cronometro_status(request, 'discurso'), - 'cronometro_aparte': get_cronometro_value(request, 'aparte'), - 'cronometro_discurso': get_cronometro_value(request, 'discurso'), - 'cronometro_ordem': get_cronometro_value(request, 'ordem'), - 'cronometro_consideracoes': get_cronometro_value(request, 'consideracoes'), + #'status_cronometro_discurso': get_cronometro_status(request, 'discurso'), + 'cronometro_aparte': get_cronometro_value('aparte'), + 'cronometro_discurso': get_cronometro_value('discurso'), + 'cronometro_ordem': get_cronometro_value('ordem'), + 'cronometro_consideracoes': get_cronometro_value('consideracoes'), 'status_painel': sessao.painel_aberto, 'brasao': brasao } - + return response ordem_dia = get_materia_aberta(pk) expediente = get_materia_expediente_aberta(pk) @@ -642,10 +642,4 @@ def get_dados_painel(request, pk): ordem_expediente)) # Retorna que não há nenhuma matéria já votada ou aberta - return response_nenhuma_materia(get_presentes(pk, response, None)) - - -def room(request): - return render(request, 'painel/room.html', { - 'room_name': 'chat' - }) \ No newline at end of file + return response_nenhuma_materia(get_presentes(pk, response, None)) \ No newline at end of file