Handle Alarms
This commit is contained in:
parent
efdd3a29b3
commit
6e54ad1a87
24 changed files with 1148 additions and 136 deletions
|
|
@ -15,11 +15,11 @@
|
|||
|
||||
function slugToComponent(slug) {
|
||||
switch(slug) {
|
||||
case "singles":
|
||||
case "single":
|
||||
return AlarmSingleList;
|
||||
case "repeateds":
|
||||
case "repeated":
|
||||
return AlarmRepeatedList;
|
||||
case "excepts":
|
||||
case "exceptions":
|
||||
return AlarmExceptionList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,20 +11,20 @@
|
|||
|
||||
function slugToComponent(slug) {
|
||||
switch(slug) {
|
||||
case "singles":
|
||||
case "single":
|
||||
return AlarmSingleList;
|
||||
case "repeateds":
|
||||
case "repeated":
|
||||
return AlarmRepeatedList;
|
||||
case "exceptions":
|
||||
return AlarmExceptList;
|
||||
return AlarmExceptionList;
|
||||
}
|
||||
}
|
||||
|
||||
function slugToText(slug) {
|
||||
switch(slug) {
|
||||
case "singles":
|
||||
case "single":
|
||||
return "un réveil manuel";
|
||||
case "repeateds":
|
||||
case "repeated":
|
||||
return "un réveil habituel";
|
||||
case "exceptions":
|
||||
return "une exception";
|
||||
|
|
|
|||
|
|
@ -3,33 +3,150 @@
|
|||
Button,
|
||||
Col,
|
||||
Container,
|
||||
Row,
|
||||
Icon,
|
||||
ListGroup,
|
||||
ListGroupItem,
|
||||
Row,
|
||||
Spinner,
|
||||
} from 'sveltestrap';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import DateFormat from '../../../../components/DateFormat.svelte';
|
||||
import DateRangeFormat from '../../../../components/DateRangeFormat.svelte';
|
||||
import { getAlarmSingle } from '../../../../lib/alarmsingle';
|
||||
import { getAlarmRepeated, weekdayStr } from '../../../../lib/alarmrepeated';
|
||||
import { getAlarmException } from '../../../../lib/alarmexception';
|
||||
import { alarmsRepeated } from '../../../../stores/alarmrepeated';
|
||||
import { alarmsSingle } from '../../../../stores/alarmsingle';
|
||||
import { alarmsExceptions } from '../../../../stores/alarmexceptions';
|
||||
|
||||
function slugToTitle(slug) {
|
||||
switch(slug) {
|
||||
case "manuals":
|
||||
case "single":
|
||||
return "Réveil manuel";
|
||||
case "usuals":
|
||||
case "repeated":
|
||||
return "Réveil habituel";
|
||||
case "excepts":
|
||||
case "exceptions":
|
||||
return "Exception";
|
||||
}
|
||||
}
|
||||
|
||||
let objP;
|
||||
let obj;
|
||||
|
||||
$: {
|
||||
switch ($page.params["kind"]) {
|
||||
case "single":
|
||||
objP = getAlarmSingle($page.params["aid"]);
|
||||
break;
|
||||
case "repeated":
|
||||
objP = getAlarmRepeated($page.params["aid"]);
|
||||
break;
|
||||
case "exceptions":
|
||||
objP = getAlarmException($page.params["aid"]);
|
||||
break;
|
||||
}
|
||||
objP.then((o) => obj = o);
|
||||
}
|
||||
|
||||
function editThis() {
|
||||
goto('alarms/' + $page.params["kind"]);
|
||||
}
|
||||
|
||||
function deleteThis() {
|
||||
obj.delete().then(() => {
|
||||
switch($page.params["kind"]) {
|
||||
case "single":
|
||||
alarmsSingle.clear();
|
||||
break;
|
||||
case "repeated":
|
||||
alarmsRepeated.clear();
|
||||
break;
|
||||
case "exceptions":
|
||||
alarmsExceptions.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
goto('alarms/' + $page.params["kind"]);
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container fluid class="flex-fill">
|
||||
<h2 class="mb-0">
|
||||
{slugToTitle($page.params["kind"])} du ...
|
||||
</h2>
|
||||
{#if $page.params["kind"] == "manuals"}
|
||||
manuals
|
||||
{:else if $page.params["kind"] == "usuals"}
|
||||
ususlas
|
||||
{:else if $page.params["kind"] == "excepts"}
|
||||
excepts
|
||||
{#if $page.params["kind"] == "single"}
|
||||
{#await objP}
|
||||
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||
<Spinner color="primary" /> Chargement en cours…
|
||||
</div>
|
||||
{:then alarm}
|
||||
<h2 class="mb-0">
|
||||
{slugToTitle($page.params["kind"])} du <DateFormat date={alarm.time} dateStyle="long" />
|
||||
</h2>
|
||||
<ListGroup class="my-2">
|
||||
<ListGroupItem>
|
||||
<strong>Date du réveil</strong> <DateFormat date={alarm.time} dateStyle="long" />
|
||||
</ListGroupItem>
|
||||
<ListGroupItem>
|
||||
<strong>Heure du réveil</strong> <DateFormat date={alarm.time} timeStyle="long" />
|
||||
</ListGroupItem>
|
||||
</ListGroup>
|
||||
{/await}
|
||||
{:else if $page.params["kind"] == "repeated"}
|
||||
{#await objP}
|
||||
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||
<Spinner color="primary" /> Chargement en cours…
|
||||
</div>
|
||||
{:then alarm}
|
||||
<h2 class="mb-0">
|
||||
{slugToTitle($page.params["kind"])} des {weekdayStr(alarm.weekday)} à {alarm.time}
|
||||
</h2>
|
||||
<ListGroup class="my-2">
|
||||
<ListGroupItem>
|
||||
<strong>Jour de la semaine</strong> {weekdayStr(alarm.weekday)}
|
||||
</ListGroupItem>
|
||||
<ListGroupItem>
|
||||
<strong>Heure du réveil</strong> {alarm.time}
|
||||
</ListGroupItem>
|
||||
<ListGroupItem>
|
||||
<strong>Ignorer les exceptions ?</strong> {alarm.ignore_exceptions?"oui":"non"}
|
||||
</ListGroupItem>
|
||||
</ListGroup>
|
||||
{/await}
|
||||
{:else if $page.params["kind"] == "exceptions"}
|
||||
{#await objP}
|
||||
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||
<Spinner color="primary" /> Chargement en cours…
|
||||
</div>
|
||||
{:then exception}
|
||||
<h2 class="mb-0">
|
||||
{slugToTitle($page.params["kind"])} du <DateRangeFormat startDate={exception._start()} endDate={exception._end()} dateStyle="long" />
|
||||
</h2>
|
||||
Entre le <DateRangeFormat startDate={exception._start()} endDate={exception._end()} dateStyle="long" />
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
{#await objP then alarm}
|
||||
<ListGroup class="my-2 text-center">
|
||||
<ListGroupItem
|
||||
action
|
||||
tag="button"
|
||||
class="text-info fw-bold"
|
||||
on:click={editThis}
|
||||
>
|
||||
<Icon name="pencil" />
|
||||
Éditer ce {slugToTitle($page.params["kind"]).toLowerCase()}
|
||||
</ListGroupItem>
|
||||
<ListGroupItem
|
||||
action
|
||||
tag="button"
|
||||
class="text-danger fw-bold"
|
||||
on:click={deleteThis}
|
||||
>
|
||||
<Icon name="trash" />
|
||||
Supprimer ce {slugToTitle($page.params["kind"]).toLowerCase()}
|
||||
</ListGroupItem>
|
||||
</ListGroup>
|
||||
{/await}
|
||||
</Container>
|
||||
|
|
|
|||
|
|
@ -1,100 +1,155 @@
|
|||
<script>
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Col,
|
||||
Container,
|
||||
Form,
|
||||
FormGroup,
|
||||
Icon,
|
||||
Input,
|
||||
Label,
|
||||
Row,
|
||||
Icon,
|
||||
Spinner,
|
||||
} from 'sveltestrap';
|
||||
|
||||
import { page } from '$app/stores';
|
||||
import DateTimeInput from '../../../../components/DateTimeInput.svelte';
|
||||
import { AlarmSingle } from '../../../../lib/alarmsingle';
|
||||
import { AlarmRepeated } from '../../../../lib/alarmrepeated';
|
||||
import { AlarmException } from '../../../../lib/alarmexception';
|
||||
import { alarmsRepeated } from '../../../../stores/alarmrepeated';
|
||||
import { alarmsSingle } from '../../../../stores/alarmsingle';
|
||||
import { alarmsExceptions } from '../../../../stores/alarmexceptions';
|
||||
import { routines } from '../../../../stores/routines';
|
||||
|
||||
function slugToTitle(slug) {
|
||||
switch(slug) {
|
||||
case "manuals":
|
||||
case "single":
|
||||
return "Nouveau réveil manuel";
|
||||
case "usuals":
|
||||
case "repeated":
|
||||
return "Nouveau réveil habituel";
|
||||
case "excepts":
|
||||
case "exceptions":
|
||||
return "Nouvelle exception";
|
||||
}
|
||||
}
|
||||
|
||||
let obj;
|
||||
|
||||
switch($page.params["kind"]) {
|
||||
case "single":
|
||||
obj = new AlarmSingle();
|
||||
break;
|
||||
case "repeated":
|
||||
obj = new AlarmRepeated();
|
||||
break;
|
||||
case "exceptions":
|
||||
obj = new AlarmException();
|
||||
break;
|
||||
}
|
||||
|
||||
function submit() {
|
||||
obj.save().then((res) => {
|
||||
switch($page.params["kind"]) {
|
||||
case "single":
|
||||
alarmsSingle.clear();
|
||||
break;
|
||||
case "repeated":
|
||||
alarmsRepeated.clear();
|
||||
break;
|
||||
case "exceptions":
|
||||
alarmsExceptions.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
goto('alarms/' + $page.params["kind"] + '/' + res.id);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container fluid class="flex-fill">
|
||||
<Form>
|
||||
<form on:submit|preventDefault={submit}>
|
||||
<Button type="submit" color="link" class="d-block d-md-none float-end">
|
||||
Ajouter
|
||||
</Button>
|
||||
<h2 class="mb-0">
|
||||
{slugToTitle($page.params["kind"])}
|
||||
</h2>
|
||||
{#if $page.params["kind"] == "manuals"}
|
||||
{#if $page.params["kind"] == "single"}
|
||||
<FormGroup>
|
||||
<Label for="exampleHour">Heure</Label>
|
||||
<Input id="exampleHour" type="datetime-local" required />
|
||||
<DateTimeInput id="exampleHour" required bind:date={obj.time} />
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<Label for="routineSelect">Routines</Label>
|
||||
<Input type="select" name="select" id="routineSelect">
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
<option>5</option>
|
||||
</Input>
|
||||
{#if $routines.list}
|
||||
<Input type="select" id="routineSelect" placeholder="Choissez une nouvelle routine">
|
||||
{#each $routines.list as routine (routine.id)}
|
||||
<option value="{routine.id}">{routine.name}</option>
|
||||
{/each}
|
||||
</Input>
|
||||
{:else}
|
||||
{#await routines.refresh()}
|
||||
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||
<Spinner color="primary" /> Chargement en cours…
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
</FormGroup>
|
||||
{:else if $page.params["kind"] == "usuals"}
|
||||
{:else if $page.params["kind"] == "repeated"}
|
||||
<FormGroup>
|
||||
<Label for="daySelect">Jour de la semaine</Label>
|
||||
<Input type="select" id="daySelect" required>
|
||||
<option value="1">Lundi</option>
|
||||
<option value="2">Mardi</option>
|
||||
<option value="3">Mercredi</option>
|
||||
<option value="4">Jeudi</option>
|
||||
<option value="5">Vendredi</option>
|
||||
<option value="6">Samedi</option>
|
||||
<option value="0">Dimanche</option>
|
||||
<Input type="select" id="daySelect" required bind:value={obj.weekday}>
|
||||
<option value={1}>Lundi</option>
|
||||
<option value={2}>Mardi</option>
|
||||
<option value={3}>Mercredi</option>
|
||||
<option value={4}>Jeudi</option>
|
||||
<option value={5}>Vendredi</option>
|
||||
<option value={6}>Samedi</option>
|
||||
<option value={0}>Dimanche</option>
|
||||
</Input>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<Label for="exampleHour">Heure</Label>
|
||||
<Input id="exampleHour" type="time" required />
|
||||
<Input id="exampleHour" type="time" required bind:value={obj.time} />
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<Label for="routineSelect">Routines</Label>
|
||||
<Input type="select" id="routineSelect">
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
<option>5</option>
|
||||
</Input>
|
||||
{#if $routines.list}
|
||||
<Input type="select" id="routineSelect" placeholder="Choissez une nouvelle routine">
|
||||
{#each $routines.list as routine (routine.id)}
|
||||
<option value="{routine.id}">{routine.name}</option>
|
||||
{/each}
|
||||
</Input>
|
||||
{:else}
|
||||
{#await routines.refresh()}
|
||||
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||
<Spinner color="primary" /> Chargement en cours…
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<Input id="ignoreExceptions" type="checkbox" label="Ignorer les exceptions" />
|
||||
<Input id="ignoreExceptions" type="checkbox" label="Ignorer les exceptions" bind:checked={obj.ignore_exceptions} />
|
||||
</FormGroup>
|
||||
{:else if $page.params["kind"] == "excepts"}
|
||||
{:else if $page.params["kind"] == "exceptions"}
|
||||
<FormGroup>
|
||||
<Label for="exceptionStart">Date de début</Label>
|
||||
<Input id="exceptionStart" type="date" required />
|
||||
<Input id="exceptionStart" type="date" required bind:value={obj.start} />
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<Label for="exceptionEnd">Date de fin</Label>
|
||||
<Input id="exceptionEnd" type="date" required />
|
||||
<Input id="exceptionEnd" type="date" required bind:value={obj.end} />
|
||||
</FormGroup>
|
||||
{/if}
|
||||
|
||||
<Button type="submit" color="primary" class="d-none d-md-block">
|
||||
Ajouter
|
||||
</Button>
|
||||
</Form>
|
||||
</form>
|
||||
</Container>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue