diff --git a/shared/static/shared/timer.webp b/shared/static/shared/timer.webp new file mode 100644 index 0000000000000000000000000000000000000000..9671ccf1eab3616ca75d824e4acb77ff52a58823 Binary files /dev/null and b/shared/static/shared/timer.webp differ diff --git a/shared/templates/shared/base.html b/shared/templates/shared/base.html index fafea799b6a4c9b7c6b21dba89cce8e9945053bb..e0e1da9ef6ce2634bc2f0370041b5ff369c34874 100644 --- a/shared/templates/shared/base.html +++ b/shared/templates/shared/base.html @@ -66,9 +66,11 @@ </ui-app> </nav> {% endblock %} - <div class="container container--default py-8 lg:py-24"> - {% block content %}{% endblock %} - </div> + {% block raw_content %} + <div class="container container--default py-8 lg:py-24"> + {% block content %}{% endblock %} + </div> + {% endblock %} {% block footer %} <footer class="footer bg-grey-700 text-white __js-root hidden lg:block"> <ui-app inline-template> diff --git a/shared/templates/shared/index.html b/shared/templates/shared/index.html index 680242ceb6d3e01e6f892fd117de382fc69c626a..9c5c7e4d904b120d6d978ab6e68fef66ef5951be 100644 --- a/shared/templates/shared/index.html +++ b/shared/templates/shared/index.html @@ -77,6 +77,26 @@ </div> </li> + <li class="card"> + <a href="{% url "timer:index" %}"> + <img + src="{% static "shared/timer.webp" %}" + alt="ÄŚasovaÄŤ pro Ĺ™eÄŤnĂky" + class="w-full h-48 object-cover" + > + </a> + <div class="p-4"> + <h2 class="mb-2 text-xl font-bold"> + <a href="{% url "timer:index" %}"> + ÄŚasovaÄŤ pro Ĺ™eÄŤnĂky + </a> + </h2> + <div class="font-light text-sm break-words"> + VzdálenÄ› ovladatelnĂ˝ ÄŤasovaÄŤ pro omezenĂ doby projevu Ĺ™eÄŤnĂkĹŻ. + </div> + </div> + </li> + <li class="card"> <a href="{% url "asset_server_resize:index" %}"> <img diff --git a/static_src/member_group_size_calc.js b/static_src/member_group_size_calc.js index be1f821d036ffaaab5e52a701c4bf17e3e3774cf..8c61aef2d2b9229fd228edefe4b96fc5071f9917 100644 --- a/static_src/member_group_size_calc.js +++ b/static_src/member_group_size_calc.js @@ -1,4 +1,4 @@ -import $ from "jquery"; + import $ from "jquery"; $(window).ready( () => { diff --git a/static_src/timer.js b/static_src/timer.js index ba838ffb0f3163564482923a8b3094be918a1699..7a51484ede93ff7e92d811e9bb7af06069c63e59 100644 --- a/static_src/timer.js +++ b/static_src/timer.js @@ -5,7 +5,7 @@ const assignEventListeners = (timer) => { timer.addEventListener( 'secondsUpdated', (event) => { - $('#timer .timer-values').html(timer.getTimeValues().toString()) + $('#timer .timer-values').html(timer.getTimeValues().toString(['minutes', 'seconds'])) } ) @@ -17,7 +17,7 @@ const assignEventListeners = (timer) => { } ) - $('#timer .timer-values').html(timer.getTimeValues().toString()) + $('#timer .timer-values').html(timer.getTimeValues().toString(['minutes', 'seconds'])) } $(window).ready( @@ -27,14 +27,16 @@ $(window).ready( let timer = new Timer({ countdown: true, startValues: { - hours: window.startingTime.hours, minutes: window.startingTime.minutes, seconds: window.startingTime.seconds, } }) const timerSocket = new WebSocket( - "wss://" + ( + (window.location.protocol === "https:") ? + "wss://" : "ws://" + ) + window.location.host + "/ws/timer/" ) @@ -45,11 +47,12 @@ $(window).ready( if ("status" in data) { if (data["status"] === "playing") { // Reset if we are playing again. - if (!timer.isRunning()) { + const remainingTime = timer.getTimeValues() + + if (remainingTime.seconds === 0 && remainingTime.minutes === 0) { timer = new Timer({ countdown: true, startValues: { - hours: window.startingTime.hours, minutes: window.startingTime.minutes, seconds: window.startingTime.seconds, } @@ -66,7 +69,6 @@ $(window).ready( timer.pause() window.startingTime = { - hours: data["time"]["hours"], minutes: data["time"]["minutes"], seconds: data["time"]["seconds"] } @@ -74,7 +76,6 @@ $(window).ready( timer = new Timer({ countdown: true, startValues: { - hours: window.startingTime.hours, minutes: window.startingTime.minutes, seconds: window.startingTime.seconds, } @@ -90,14 +91,25 @@ $(window).ready( // --- BEGIN Controls --- + $("#pause_play").on( + "click", + (event) => { + $("#is_counting").click() + } + ) + $("#is_counting").on( "change", (event) => { if (event.target.checked) { + $("#pause_play > .btn__body").html("⏸︎") + timerSocket.send(JSON.stringify({ "status": "playing" })) } else { + $("#pause_play > .btn__body").html("⏵︎") + timerSocket.send(JSON.stringify({ "status": "paused" })) @@ -110,7 +122,6 @@ $(window).ready( (event) => { timerSocket.send(JSON.stringify({ "time": { - "hours": Number($("#hours").val()), "minutes": Number($("#minutes").val()), "seconds": Number($("#seconds").val()) } diff --git a/timer/consumers.py b/timer/consumers.py index 1946e2ff37b88f38c2b2e812820ed687e84f88e7..4cdf054f097fa0f5e8c1c6d19b2a125ee9c4e275 100644 --- a/timer/consumers.py +++ b/timer/consumers.py @@ -27,7 +27,6 @@ class TimerConsumer(WebsocketConsumer): if "time" in json_data: response = { "time": { - "hours": json_data["time"]["hours"], "minutes": json_data["time"]["minutes"], "seconds": json_data["time"]["seconds"], } diff --git a/timer/forms.py b/timer/forms.py index 7214ca8397053ef9e748bb39ef0435b641f731fa..4ca9fd67cc92817394bb90097d505ea498def8d1 100644 --- a/timer/forms.py +++ b/timer/forms.py @@ -7,10 +7,6 @@ from django.core.validators import ( class TimeOnlyForm(forms.Form): - hours = forms.IntegerField( - label="Hodiny", validators=[MinValueValidator(limit_value=0)] - ) - minutes = forms.IntegerField( label="Minuty", validators=[ diff --git a/timer/migrations/0002_alter_ongoingtimer_name.py b/timer/migrations/0002_alter_ongoingtimer_name.py new file mode 100644 index 0000000000000000000000000000000000000000..338b6da52b461b951a137c3f14ca0cb94135ada8 --- /dev/null +++ b/timer/migrations/0002_alter_ongoingtimer_name.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.5 on 2023-08-25 11:53 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("timer", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="ongoingtimer", + name="name", + field=models.CharField( + max_length=64, + validators=[django.core.validators.MinLengthValidator(limit_value=1)], + verbose_name="Název", + ), + ), + ] diff --git a/timer/migrations/0003_remove_ongoingtimer_hours.py b/timer/migrations/0003_remove_ongoingtimer_hours.py new file mode 100644 index 0000000000000000000000000000000000000000..d3f4014da3cdef07cfc53e68d58e9cbef631541c --- /dev/null +++ b/timer/migrations/0003_remove_ongoingtimer_hours.py @@ -0,0 +1,16 @@ +# Generated by Django 4.1.5 on 2023-08-25 16:47 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("timer", "0002_alter_ongoingtimer_name"), + ] + + operations = [ + migrations.RemoveField( + model_name="ongoingtimer", + name="hours", + ), + ] diff --git a/timer/models.py b/timer/models.py index cc97e9bb807c624d8c00d923b4275650d8dcee5f..545cb289d39ab4932579c3c3aeaa0955b44b7176 100644 --- a/timer/models.py +++ b/timer/models.py @@ -15,10 +15,6 @@ class OngoingTimer(models.Model): validators=[MinLengthValidator(limit_value=1)], ) - hours = models.IntegerField( - verbose_name="Hodiny", validators=[MinValueValidator(limit_value=0)] - ) - minutes = models.IntegerField( verbose_name="Minuty", validators=[ diff --git a/timer/templates/timer/edit_timer.html b/timer/templates/timer/edit_timer.html index d4d75af1639d6c14bd26385bfa9dde5a2e13ace6..8ae64853e9df0410cd0bcb80debd532188dc380f 100644 --- a/timer/templates/timer/edit_timer.html +++ b/timer/templates/timer/edit_timer.html @@ -17,43 +17,45 @@ {% block content %} <script> window.startingTime = { - hours: {{ timer.hours }}, minutes: {{ timer.minutes }}, seconds: {{ timer.seconds }}, } </script> <main> - <h1 class="text-6xl font-bebas mb">Ăšprava ÄŤasovaÄŤe {{ timer.name }}</h1> + <h1 class="text-6xl font-bebas">Ăšprava ÄŤasovaÄŤe {{ timer.name }}</h1> - <div> + <hr> + + <div class="text-xl"> <div id="timer"> - <div class="timer-values">{{ timer.hours }}:{{ timer.minutes }}:{{ timer.seconds }}</div> + <div class="timer-values"></div> </div> </div> - <div class="flex flex-col gap-2"> + <hr> + + <div class="flex flex-col gap-5"> <div> - <input - type="checkbox" - id="is_counting" - name="is_counting" - autocomplete="off" - value="false" + <div class="hidden"> + <input + type="checkbox" + id="is_counting" + name="is_counting" + autocomplete="off" + value="false" + > + </div> + <button + id="pause_play" + class="btn w-64 text-xl" > - <label - for="is_counting" - >OdpoÄŤet spuštÄ›nĂ˝</label> + <div class="btn__body">⏵︎</div> + </button> </div> - <div class="flex gap-2"> - <input - type="number" - id="hours" - name="hours" - placeholder="Hodiny" - autocomplete="off" - > + <div class="flex flex-col gap-2"> <input + class="w-64 text-lg" type="number" id="minutes" name="minutes" @@ -61,6 +63,7 @@ autocomplete="off" > <input + class="w-64 text-lg" type="number" id="seconds" name="seconds" @@ -69,7 +72,10 @@ > <button id="update-time" - >Aktualizovat ÄŤas</button> + class="btn w-64" + > + <div class="btn__body">Aktualizovat ÄŤas</div> + </button> </div> </div> </main> diff --git a/timer/templates/timer/view_timer.html b/timer/templates/timer/view_timer.html index 5e11cf3f617a642f2af0f6a206b4758e7e398ced..88feba5644b0dbd18b0de542979a0c1e561e0fc8 100644 --- a/timer/templates/timer/view_timer.html +++ b/timer/templates/timer/view_timer.html @@ -16,16 +16,15 @@ {% block nav %}{% endblock %} -{% block content %} +{% block raw_content %} <script> window.startingTime = { - hours: {{ timer.hours }}, minutes: {{ timer.minutes }}, seconds: {{ timer.seconds }}, } </script> - <main> + <main class="text-center bg-black text-white h-screen flex flex-col justify-between py-5"> <h1 class="text-6xl font-bebas mb">{{ timer.name }}</h1> <div @@ -38,7 +37,7 @@ </div> <a - class="text-gray-400" + class="text-white opacity-25 text-sm" href="{% url 'timer:edit_timer' timer.id %}" >Upravit</a> </main>