From ed93239c96f26738601cf10f4b301c9638205800 Mon Sep 17 00:00:00 2001 From: Cesar Augusto de Carvalho Date: Fri, 5 Jul 2019 10:49:42 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20#2749=20-=20Configurar=20cron=C3=B4metro?= =?UTF-8?q?=20-=20tempo=20de=20disparo=20e=20com=20que=20anteced=C3=AAncia?= =?UTF-8?q?=20(#2871)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #2828 - Adiciona tipo de cronômetro * Corrige migrações * Altera view do painel em Sessao * Cronometros da tela de sessao funcionando * Melhoria no Form de Cronometro * Muda nome do cronometro da ordem * Cria PainelConfig * Adiciona opção de tempo de disparo previo * Corrigido formato do cronometro * Disparo prévio do cronômetro configurável * Adiciona opção de duração do disparo * Fix verbose name * Remove migrations desnecessárias --- sapl/painel/forms.py | 10 +++- .../0003_auto_20190603_1033.py~HEAD | 48 ------------------- .../0004_auto_20190603_1033.py~HEAD | 25 ---------- .../migrations/0006_auto_20190612_1347.py | 25 ++++++++++ ...0007_painelconfig_tempo_disparo_termino.py | 20 ++++++++ sapl/painel/models.py | 16 +++++++ sapl/templates/painel/index.html | 34 +++++++++++-- sapl/templates/painel/layouts.yaml | 2 + sapl/templates/painel/painelconfig_form.html | 16 +++++++ sapl/templates/sessao/painel.html | 38 +++++++++++++-- 10 files changed, 154 insertions(+), 80 deletions(-) delete mode 100644 sapl/painel/migrations/0003_auto_20190603_1033.py~HEAD delete mode 100644 sapl/painel/migrations/0004_auto_20190603_1033.py~HEAD create mode 100644 sapl/painel/migrations/0006_auto_20190612_1347.py create mode 100644 sapl/painel/migrations/0007_painelconfig_tempo_disparo_termino.py diff --git a/sapl/painel/forms.py b/sapl/painel/forms.py index e2314c407..3366b7384 100644 --- a/sapl/painel/forms.py +++ b/sapl/painel/forms.py @@ -18,4 +18,12 @@ class ConfiguracoesPainelForm(forms.ModelForm): class Meta: model = PainelConfig - fields = ['cronometro_ordem'] \ No newline at end of file + fields = ['cronometro_ordem', + 'disparo_cronometro', + 'tempo_disparo_antecedencia', + 'tempo_disparo_termino'] + + def __init__(self, *args, **kwargs): + super(ConfiguracoesPainelForm, self).__init__(*args, **kwargs) + self.fields['tempo_disparo_antecedencia'].widget.attrs['class'] = 'cronometro' + self.fields['tempo_disparo_termino'].widget.attrs['class'] = 'cronometro' diff --git a/sapl/painel/migrations/0003_auto_20190603_1033.py~HEAD b/sapl/painel/migrations/0003_auto_20190603_1033.py~HEAD deleted file mode 100644 index 7df9c2b83..000000000 --- a/sapl/painel/migrations/0003_auto_20190603_1033.py~HEAD +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-03 13:33 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('painel', '0002_auto_20180523_1430'), - ] - - operations = [ - migrations.AlterModelOptions( - name='cronometro', - options={'ordering': ['ordenacao'], 'verbose_name': 'Cronômetro', 'verbose_name_plural': 'Cronômetros'}, - ), - migrations.RemoveField( - model_name='cronometro', - name='data_cronometro', - ), - migrations.AddField( - model_name='cronometro', - name='ativo', - field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], default=False, verbose_name='Ativo?'), - ), - migrations.AddField( - model_name='cronometro', - name='duracao_cronometro', - field=models.DurationField(verbose_name='Duração do cronômetro'), - ), - migrations.AddField( - model_name='cronometro', - name='ordenacao', - field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Ordenação'), - ), - migrations.AlterField( - model_name='cronometro', - name='status', - field=models.CharField(choices=[('I', 'Start'), ('R', 'Reset'), ('S', 'Stop'), ('C', 'Increment')], default='S', max_length=1, verbose_name='Status do cronômetro'), - ), - migrations.AlterField( - model_name='cronometro', - name='tipo', - field=models.CharField(max_length=100, unique=True, verbose_name='Tipo Cronômetro'), - ), - ] diff --git a/sapl/painel/migrations/0004_auto_20190603_1033.py~HEAD b/sapl/painel/migrations/0004_auto_20190603_1033.py~HEAD deleted file mode 100644 index f3256ae61..000000000 --- a/sapl/painel/migrations/0004_auto_20190603_1033.py~HEAD +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-03 13:33 -from __future__ import unicode_literals - -from django.db import migrations - - -def create_default_cronometros(apps, schema_editor): - tipos_default = ['Cronômetro do Discurso', 'Cronômetro do Aparte', - 'Cronômetro da Questão de Ordem', 'Cronômetro de Considerações Finais'] - Cronometro = apps.get_model('painel', 'Cronometro') - - for i,tipo in enumerate(tipos_default): - Cronometro.objects.get_or_create(tipo=tipo, duracao_cronometro='00:05:00', status='S', ativo=True, ordenacao=i+1) - - -class Migration(migrations.Migration): - - dependencies = [ - ('painel', '0003_auto_20190603_1033'), - ] - - operations = [ - migrations.RunPython(create_default_cronometros) - ] diff --git a/sapl/painel/migrations/0006_auto_20190612_1347.py b/sapl/painel/migrations/0006_auto_20190612_1347.py new file mode 100644 index 000000000..8f20a356d --- /dev/null +++ b/sapl/painel/migrations/0006_auto_20190612_1347.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-06-12 16:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('painel', '0005_painelconfig'), + ] + + operations = [ + migrations.AddField( + model_name='painelconfig', + name='disparo_cronometro', + field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], default=True, verbose_name='Cronômetros devem disparar com antecedência?'), + ), + migrations.AddField( + model_name='painelconfig', + name='tempo_disparo_antecedencia', + field=models.DurationField(blank=True, default='00:00:30', null=True, verbose_name='Cronômetros devem disparar com quanto tempo de antecedência?'), + ), + ] diff --git a/sapl/painel/migrations/0007_painelconfig_tempo_disparo_termino.py b/sapl/painel/migrations/0007_painelconfig_tempo_disparo_termino.py new file mode 100644 index 000000000..ec4633d8a --- /dev/null +++ b/sapl/painel/migrations/0007_painelconfig_tempo_disparo_termino.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-06-14 14:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('painel', '0006_auto_20190612_1347'), + ] + + operations = [ + migrations.AddField( + model_name='painelconfig', + name='tempo_disparo_termino', + field=models.DurationField(blank=True, default='00:00:05', null=True, verbose_name='Cronômetros devem permanecer tocando por quanto tempo ao término?'), + ), + ] diff --git a/sapl/painel/models.py b/sapl/painel/models.py index 555899884..97ed3b138 100644 --- a/sapl/painel/models.py +++ b/sapl/painel/models.py @@ -74,6 +74,22 @@ class PainelConfig(models.Model): verbose_name=_('Cronômetro da Questão de Ordem deve travar os demais?'), choices=YES_NO_CHOICES, default=True) + disparo_cronometro = models.BooleanField( + verbose_name=_('Cronômetros devem disparar com antecedência?'), + choices=YES_NO_CHOICES, default=True) + + tempo_disparo_antecedencia = models.DurationField( + verbose_name=_('Cronômetros devem disparar com quanto tempo de antecedência?'), + default="00:00:30", + blank=True, + null=True) + + tempo_disparo_termino = models.DurationField( + verbose_name=_('Cronômetros devem permanecer tocando por quanto tempo ao término?'), + default="00:00:05", + blank=True, + null=True) + class Meta: verbose_name = _('Configurações do Painel') verbose_name_plural = _('Configurações do Painel') diff --git a/sapl/templates/painel/index.html b/sapl/templates/painel/index.html index 9acc59042..b6007a163 100644 --- a/sapl/templates/painel/index.html +++ b/sapl/templates/painel/index.html @@ -149,19 +149,41 @@ return voto } + function playAudioNumVezes(audio, times, ended) { + if (times <= 0) { + return; + } + let played = 0; + audio.addEventListener("ended", function() { + played++; + if (played < times) { + audio.play(); + } else if (ended) { + ended(); + } + }); + audio.play(); + } + $(document).ready(function() { //TODO: replace by a fancy jQuery clock startTime(); var audioAlertFinish = document.getElementById("audio"); + // Obtém duração do disparo ao término do tempo e converte para segundos + var duracao_disparo = "{{ painel_config.tempo_disparo_termino }}"; + let tmp = duracao_disparo.split(":"); + duracao_disparo = parseInt(tmp[0])*3600 + parseInt(tmp[1])*60 + parseInt(tmp[2]); + var num_vezes_toca_audio = Math.round(duracao_disparo/audioAlertFinish.duration); + var cronometros_previous = []; {% for cron in cronometros %} cronometros_previous.push(0); $('#cronometro_' + "{{cron.id}}").runner({ autostart: false, countdown: true, - startAt: {{cron.duracao_cronometro|duration_to_seconds}} * 1000, + startAt: parseInt("{{cron.duracao_cronometro|duration_to_seconds}}") * 1000, stopAt: 0, milliseconds: false, format: function(value) { @@ -174,10 +196,14 @@ return h.toString() + ":" + m.toString() + ":" + s.toString(); } }).on('runnerFinish', function(eventObject, info){ - audioAlertFinish.play(); + playAudioNumVezes(audioAlertFinish, num_vezes_toca_audio); }) {% endfor %} + var tempo_disparo_antecedencia = "{{ painel_config.tempo_disparo_antecedencia }}" + tmp = tempo_disparo_antecedencia.split(":"); + tempo_disparo_antecedencia = checkTime(parseInt(tmp[0])) + ":" + checkTime(parseInt(tmp[1])) + ":" + checkTime(parseInt(tmp[2])); + var counter = 1; (function poll() { $.ajax({ @@ -296,8 +322,10 @@ cronometros_previous[i] = status_cronometros[i]; } - if($('#cronometro_' + ids[i]).runner('info').formattedTime == 30) + if($('#cronometro_' + ids[i]).runner('info').formattedTime == tempo_disparo_antecedencia && + "{{ painel_config.disparo_cronometro }}" == "True" ) audioAlertFinish.play(); + } if(data['sessao_finalizada']){ diff --git a/sapl/templates/painel/layouts.yaml b/sapl/templates/painel/layouts.yaml index 47957549e..7e89dbc22 100644 --- a/sapl/templates/painel/layouts.yaml +++ b/sapl/templates/painel/layouts.yaml @@ -6,3 +6,5 @@ Cronometro: PainelConfig: {% trans 'Configurações do Painel' %}: - cronometro_ordem + - disparo_cronometro:6 tempo_disparo_antecedencia:6 + - tempo_disparo_termino:8 diff --git a/sapl/templates/painel/painelconfig_form.html b/sapl/templates/painel/painelconfig_form.html index 990d81b7b..fb1bfe98b 100644 --- a/sapl/templates/painel/painelconfig_form.html +++ b/sapl/templates/painel/painelconfig_form.html @@ -6,8 +6,24 @@ diff --git a/sapl/templates/sessao/painel.html b/sapl/templates/sessao/painel.html index a9039b4e6..9b0078fd3 100644 --- a/sapl/templates/sessao/painel.html +++ b/sapl/templates/sessao/painel.html @@ -2,7 +2,6 @@ {% load i18n %} {% load common_tags %} {% load staticfiles %} - {% load webpack_static from webpack_loader %} {% load render_bundle from webpack_loader %} @@ -100,6 +99,23 @@ function startTime() { },500); } +function playAudioNumVezes(audio, times, ended) { + if (times <= 0) { + return; + } + let played = 0; + audio.addEventListener("ended", function() { + played++; + if (played < times) { + audio.play(); + } else if (ended) { + ended(); + } + }); + audio.play(); +} + + $(document).ready(function(){ let pk_sessao = parseInt("{{root_pk}}"); let botao_abrir = $('#id_abrir_painel'); @@ -127,6 +143,12 @@ $(document).ready(function(){ startTime(); let audioAlertFinish = document.getElementById("audio"); + // Obtém duração do disparo ao término do tempo e converte para segundos + var duracao_disparo = "{{ painel_config.tempo_disparo_termino }}"; + let tmp = duracao_disparo.split(":"); + duracao_disparo = parseInt(tmp[0])*3600 + parseInt(tmp[1])*60 + parseInt(tmp[2]); + let num_vezes_toca_audio = Math.round(duracao_disparo/audioAlertFinish.duration); + {% for cron in cronometros %} $('#cronometro_' + "{{cron.id}}").prop('disabled', false); @@ -135,10 +157,19 @@ $(document).ready(function(){ countdown: true, startAt: parseInt("{{cron.duracao_cronometro|duration_to_seconds}}") * 1000, stopAt: 0, - milliseconds: false + milliseconds: false, + format: function(value) { + let h = Math.floor((value/1000) / 3600); + h = checkTime(h); + let m = Math.floor((value/1000) % 3600 / 60); + m = checkTime(m); + let s = Math.floor((value/1000) % 3600 % 60); + s = checkTime(s); + return h.toString() + ":" + m.toString() + ":" + s.toString(); + } }).on('runnerFinish', function(eventObject, info){ $.get('/painel/cronometro', { tipo: 'cronometro_' + "{{cron.id}}", action: 'stop' } ); - audioAlertFinish.play(); + playAudioNumVezes(audioAlertFinish, num_vezes_toca_audio); $('#cronometro_' + "{{cron.id}}" + '_Reset').show(); $('#cronometro_' + "{{cron.id}}").runner('stop'); $('#cronometro_' + "{{cron.id}}" + '_Start').text('Iniciar'); @@ -188,6 +219,7 @@ $(document).ready(function(){ $('#cronometro_' + "{{cron.id}}").runner('stop'); $('#cronometro_' + "{{cron.id}}").runner('reset'); }); + {% endfor %} });