From a4c072a4067fe3c8ec3a91e6cc54d177093acb9a Mon Sep 17 00:00:00 2001 From: AlGouvea Date: Mon, 4 Oct 2021 12:07:59 -0300 Subject: [PATCH] Inicio do update dinamico do painel --- frontend/src/__apps/painel/main.js | 6 ++++++ sapl/painel/consumers.py | 3 +++ sapl/painel/tasks.py | 1 - sapl/painel/views.py | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/__apps/painel/main.js b/frontend/src/__apps/painel/main.js index df2e4879a..f605da4d9 100644 --- a/frontend/src/__apps/painel/main.js +++ b/frontend/src/__apps/painel/main.js @@ -247,6 +247,12 @@ const v = new Vue({ // eslint-disable-line created () { socket.onopen = function (e) { console.log('Connection established') + + // Pedir os dados uma vez + const id = window.location.href.slice(-3) + console.log(id) + + socket.send(id) } const _this = this diff --git a/sapl/painel/consumers.py b/sapl/painel/consumers.py index 0970b319b..ca3482caf 100644 --- a/sapl/painel/consumers.py +++ b/sapl/painel/consumers.py @@ -14,6 +14,9 @@ class PainelConsumer(AsyncJsonWebsocketConsumer): async def disconnect(self, code): await self.channel_layer.group_discard('painel', self.channel_name) + async def receive (self, text_data): + json_data = views.get_dados_painel(text_data) + await self.send(json.dumps(json_data)) async def send_data(self, event): new_data = event['message'] diff --git a/sapl/painel/tasks.py b/sapl/painel/tasks.py index a7c3b1649..6c72fba4c 100644 --- a/sapl/painel/tasks.py +++ b/sapl/painel/tasks.py @@ -7,5 +7,4 @@ channel_layer = get_channel_layer() def get_dados_painel_final(id): json_data = views.get_dados_painel(id) - print(json_data) async_to_sync(channel_layer.group_send)('painel', {'type':'send_data', 'message': json_data}) diff --git a/sapl/painel/views.py b/sapl/painel/views.py index ecb87a517..61199a16c 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -183,7 +183,7 @@ def sessao_votacao(context, context_vars): context, context_vars = votacao(context, context_vars) else: context.update({'error_message': errors_msgs[erro]}) - + tasks.get_dados_painel_final(pk) return context, context_vars @@ -303,6 +303,7 @@ def painel_view(request, pk): context = {'head_title': str( _('Painel Plenário')), 'sessao_id': pk, 'utc_offset': utc_offset} + return render(request, 'painel/index.html', context) @@ -365,7 +366,6 @@ def get_cronometro_status(request, name): ". Erro ao obter cronometro. Retornado como vazio. " + str(e)) cronometro = '' sessao.save() - tasks.get_dados_painel_final(pk) return JsonResponse({})