Browse Source

Inicio do update dinamico do painel

Websocket_painel
AlGouvea 3 years ago
parent
commit
a4c072a406
  1. 6
      frontend/src/__apps/painel/main.js
  2. 3
      sapl/painel/consumers.py
  3. 1
      sapl/painel/tasks.py
  4. 4
      sapl/painel/views.py

6
frontend/src/__apps/painel/main.js

@ -247,6 +247,12 @@ const v = new Vue({ // eslint-disable-line
created () { created () {
socket.onopen = function (e) { socket.onopen = function (e) {
console.log('Connection established') 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 const _this = this

3
sapl/painel/consumers.py

@ -14,6 +14,9 @@ class PainelConsumer(AsyncJsonWebsocketConsumer):
async def disconnect(self, code): async def disconnect(self, code):
await self.channel_layer.group_discard('painel', self.channel_name) 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): async def send_data(self, event):
new_data = event['message'] new_data = event['message']

1
sapl/painel/tasks.py

@ -7,5 +7,4 @@ channel_layer = get_channel_layer()
def get_dados_painel_final(id): def get_dados_painel_final(id):
json_data = views.get_dados_painel(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}) async_to_sync(channel_layer.group_send)('painel', {'type':'send_data', 'message': json_data})

4
sapl/painel/views.py

@ -183,7 +183,7 @@ def sessao_votacao(context, context_vars):
context, context_vars = votacao(context, context_vars) context, context_vars = votacao(context, context_vars)
else: else:
context.update({'error_message': errors_msgs[erro]}) context.update({'error_message': errors_msgs[erro]})
tasks.get_dados_painel_final(pk)
return context, context_vars return context, context_vars
@ -303,6 +303,7 @@ def painel_view(request, pk):
context = {'head_title': str( context = {'head_title': str(
_('Painel Plenário')), 'sessao_id': pk, 'utc_offset': utc_offset} _('Painel Plenário')), 'sessao_id': pk, 'utc_offset': utc_offset}
return render(request, 'painel/index.html', context) 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)) ". Erro ao obter cronometro. Retornado como vazio. " + str(e))
cronometro = '' cronometro = ''
sessao.save() sessao.save()
tasks.get_dados_painel_final(pk)
return JsonResponse({}) return JsonResponse({})

Loading…
Cancel
Save