Skip to content
Snippets Groups Projects
Commit e11d3c69 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

add reset timer function

parent 79157237
No related branches found
No related tags found
1 merge request!9Release
Pipeline #15165 passed
...@@ -5,11 +5,11 @@ import alertify from "alertifyjs"; ...@@ -5,11 +5,11 @@ import alertify from "alertifyjs";
import "alertifyjs/build/css/alertify.css"; import "alertifyjs/build/css/alertify.css";
const disableInputs = () => { const disableInputs = () => {
$("#pause_play,#minutes,#seconds,#update_time").prop("disabled", true) $("#pause_play,#minutes,#seconds,#update_time,#reset_time").prop("disabled", true)
} }
const enableInputs = () => { const enableInputs = () => {
$("#pause_play,#minutes,#seconds,#update_time").prop("disabled", false) $("#pause_play,#minutes,#seconds,#update_time,#reset_time").prop("disabled", false)
} }
const updateTimeText = () => { const updateTimeText = () => {
...@@ -246,6 +246,20 @@ $(window).ready( ...@@ -246,6 +246,20 @@ $(window).ready(
} }
) )
$("#reset_time").on(
"click",
(event) => {
disableInputs()
window.timer.pause()
timerSocket.send(JSON.stringify({
"reset": true,
"is_running": false
}))
}
)
// --- END Controls --- // --- END Controls ---
} }
......
...@@ -12,8 +12,6 @@ running_timer_threads = [] ...@@ -12,8 +12,6 @@ running_timer_threads = []
def tick_timer(timer, iteration: int, total_seconds: int) -> None: def tick_timer(timer, iteration: int, total_seconds: int) -> None:
print("ticking", timer)
second_compensation = 0 second_compensation = 0
start_time = timeit.default_timer() start_time = timeit.default_timer()
...@@ -24,8 +22,6 @@ def tick_timer(timer, iteration: int, total_seconds: int) -> None: ...@@ -24,8 +22,6 @@ def tick_timer(timer, iteration: int, total_seconds: int) -> None:
second_compensation = end_time - start_time second_compensation = end_time - start_time
while not timer.is_running: while not timer.is_running:
print("waiting to run ...")
time.sleep(0.05) time.sleep(0.05)
timer.refresh_from_db() timer.refresh_from_db()
...@@ -154,8 +150,18 @@ class TimerConsumer(AsyncWebsocketConsumer): ...@@ -154,8 +150,18 @@ class TimerConsumer(AsyncWebsocketConsumer):
await sync_to_async(self.timer.save)() await sync_to_async(self.timer.save)()
if "time" in json_data: if "time" in json_data:
self.timer.minutes = json_data["time"]["minutes"] # Don't save here in case there is a tick thread running
self.timer.seconds = json_data["time"]["seconds"]
self.timer.minutes = self.timer.initial_minutes = json_data["time"]["minutes"]
self.timer.seconds = self.timer.initial_seconds = json_data["time"]["seconds"]
reset_timer = True
if "reset" in json_data:
# Don't save here in case there is a tick thread running
self.timer.minutes = self.timer.initial_minutes
self.timer.seconds = self.timer.initial_seconds
reset_timer = True reset_timer = True
......
# Generated by Django 4.1.5 on 2023-10-24 20:06
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('timer', '0004_ongoingtimer_is_running_ongoingtimer_iteration'),
]
operations = [
migrations.AddField(
model_name='ongoingtimer',
name='initial_minutes',
field=models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(limit_value=0), django.core.validators.MaxValueValidator(limit_value=60)], verbose_name='Původní Minuty'),
preserve_default=False,
),
migrations.AddField(
model_name='ongoingtimer',
name='initial_seconds',
field=models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(limit_value=0), django.core.validators.MaxValueValidator(limit_value=60)], verbose_name='Původní sekundy'),
preserve_default=False,
),
migrations.AlterField(
model_name='ongoingtimer',
name='seconds',
field=models.IntegerField(validators=[django.core.validators.MinValueValidator(limit_value=0), django.core.validators.MaxValueValidator(limit_value=60)], verbose_name='Sekundy'),
),
]
...@@ -15,6 +15,22 @@ class OngoingTimer(models.Model): ...@@ -15,6 +15,22 @@ class OngoingTimer(models.Model):
validators=[MinLengthValidator(limit_value=1)], validators=[MinLengthValidator(limit_value=1)],
) )
initial_minutes = models.IntegerField(
verbose_name="Původní Minuty",
validators=[
MinValueValidator(limit_value=0),
MaxValueValidator(limit_value=60),
],
)
initial_seconds = models.IntegerField(
verbose_name="Původní sekundy",
validators=[
MinValueValidator(limit_value=0),
MaxValueValidator(limit_value=60),
],
)
minutes = models.IntegerField( minutes = models.IntegerField(
verbose_name="Minuty", verbose_name="Minuty",
validators=[ validators=[
...@@ -24,7 +40,7 @@ class OngoingTimer(models.Model): ...@@ -24,7 +40,7 @@ class OngoingTimer(models.Model):
) )
seconds = models.IntegerField( seconds = models.IntegerField(
verbose_name="Minuty", verbose_name="Sekundy",
validators=[ validators=[
MinValueValidator(limit_value=0), MinValueValidator(limit_value=0),
MaxValueValidator(limit_value=60), MaxValueValidator(limit_value=60),
......
...@@ -87,6 +87,12 @@ ...@@ -87,6 +87,12 @@
> >
<div class="btn__body">Aktualizovat čas</div> <div class="btn__body">Aktualizovat čas</div>
</button> </button>
<button
id="reset_time"
class="btn w-64"
>
<div class="btn__body">Resetovat čas</div>
</button>
</div> </div>
<a <a
......
...@@ -20,6 +20,8 @@ def create(request): ...@@ -20,6 +20,8 @@ def create(request):
if form.is_valid(): if form.is_valid():
timer = OngoingTimer( timer = OngoingTimer(
initial_minutes=form.cleaned_data["minutes"],
initial_seconds=form.cleaned_data["seconds"],
minutes=form.cleaned_data["minutes"], minutes=form.cleaned_data["minutes"],
seconds=form.cleaned_data["seconds"], seconds=form.cleaned_data["seconds"],
name=form.cleaned_data["name"], name=form.cleaned_data["name"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment