Handle Alarms

This commit is contained in:
nemunaire 2022-10-05 22:33:31 +02:00
commit 9fcb4a1867
24 changed files with 1148 additions and 136 deletions

View file

@ -1,5 +1,4 @@
<script>
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import {

View file

@ -4,8 +4,12 @@
import {
Button,
Icon,
Spinner,
} from 'sveltestrap';
import DateRangeFormat from '../components/DateRangeFormat.svelte';
import { alarmsExceptions } from '../stores/alarmexceptions';
export let flush = false;
</script>
@ -14,22 +18,36 @@
Exceptions
</h2>
<Button
href="alarms/excepts/new"
href="alarms/exceptions/new"
color="outline-primary"
size="sm"
class="float-end {($page.params.kind === 'excepts' && $page.url.pathname.endsWith('/new'))?'active':''}"
class="float-end {($page.params.kind === 'exceptions' && $page.url.pathname.endsWith('/new'))?'active':''}"
>
<Icon name="plus-lg" />
</Button>
</div>
<div class="list-group" class:list-group-flush={flush}>
<a
href="alarms/excepts/1"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "excepts" && $page.params.aid === "1"}
>
<Icon name="x-octagon-fill" />
Du <abbr title="test">samedi 14</abbr>
au <abbr title="test">dimanche 26 février</abbr>
</a>
<div class="text-center">
{#if $alarmsExceptions.list !== null}
{#if $alarmsExceptions.list.length}
<div class="list-group" class:list-group-flush={flush}>
{#each $alarmsExceptions.list as alarm (alarm.id)}
<a
href="alarms/exceptions/{alarm.id}"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "exceptions" && $page.params.aid === alarm.id}
>
Du <DateRangeFormat startDate={alarm._start()} endDate={alarm._end()} dateStyle="long" />
</a>
{/each}
</div>
{:else}
<p class="fst-italic">Pas d'exception programmée</p>
{/if}
{:else}
{#await alarmsExceptions.refresh()}
<div class="d-flex justify-content-center align-items-center gap-2">
<Spinner color="primary" /> Chargement en cours&hellip;
</div>
{/await}
{/if}
</div>

View file

@ -4,8 +4,12 @@
import {
Button,
Icon,
Spinner,
} from 'sveltestrap';
import { weekdayStr } from '../lib/alarmrepeated';
import { alarmsRepeated } from '../stores/alarmrepeated';
export let flush = false;
</script>
@ -14,27 +18,36 @@
Réveils habituels
</h2>
<Button
href="alarms/usuals/new"
href="alarms/repeated/new"
color="outline-primary"
size="sm"
class="float-end {($page.params.kind === 'usuals' && $page.url.pathname.endsWith('/new'))?'active':''}"
class="float-end {($page.params.kind === 'repeated' && $page.url.pathname.endsWith('/new'))?'active':''}"
>
<Icon name="plus-lg" />
</Button>
</div>
<div class="list-group" class:list-group-flush={flush}>
<a
href="alarms/usuals/1"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "usuals" && $page.params.aid === "1"}
>
Les lundis à 6h50
</a>
<a
href="alarms/usuals/2"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "usuals" && $page.params.aid === "2"}
>
Les mardis à 6h50
</a>
<div class="text-center">
{#if $alarmsRepeated.list !== null}
{#if $alarmsRepeated.list.length}
<div class="list-group" class:list-group-flush={flush}>
{#each $alarmsRepeated.list as alarm (alarm.id)}
<a
href="alarms/repeated/{alarm.id}"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "repeated" && $page.params.aid === alarm.id}
>
Les {weekdayStr(alarm.weekday)}s à {alarm.time}
</a>
{/each}
</div>
{:else}
<p class="fst-italic">Pas de réveil habituel programmé</p>
{/if}
{:else}
{#await alarmsRepeated.refresh()}
<div class="d-flex justify-content-center align-items-center gap-2">
<Spinner color="primary" /> Chargement en cours&hellip;
</div>
{/await}
{/if}
</div>

View file

@ -4,8 +4,12 @@
import {
Button,
Icon,
Spinner,
} from 'sveltestrap';
import DateFormat from '../components/DateFormat.svelte';
import { alarmsSingle } from '../stores/alarmsingle';
export let flush = false;
</script>
@ -14,14 +18,36 @@
Réveils manuels
</h2>
<Button
href="alarms/manuals/new"
href="alarms/single/new"
color="outline-primary"
size="sm"
class="float-end {($page.params.kind === 'manuals' && $page.url.pathname.endsWith('/new'))?'active':''}"
class="float-end {($page.params.kind === 'single' && $page.url.pathname.endsWith('/new'))?'active':''}"
>
<Icon name="plus-lg" />
</Button>
</div>
<div class="text-center">
<p class="fst-italic">Pas de prochain réveil manuel programmé</p>
{#if $alarmsSingle.list !== null}
{#if $alarmsSingle.list.length}
<div class="list-group" class:list-group-flush={flush}>
{#each $alarmsSingle.list as alarm (alarm.id)}
<a
href="alarms/single/{alarm.id}"
class="list-group-item list-group-item-action"
class:active={$page.params.kind === "single" && $page.params.aid === alarm.id}
>
Le <DateFormat date={alarm.time} dateStyle="long" timeStyle="long" />
</a>
{/each}
</div>
{:else}
<p class="fst-italic">Pas de prochain réveil manuel programmé</p>
{/if}
{:else}
{#await alarmsSingle.refresh()}
<div class="d-flex justify-content-center align-items-center gap-2">
<Spinner color="primary" /> Chargement en cours&hellip;
</div>
{/await}
{/if}
</div>

View file

@ -0,0 +1,17 @@
<script>
export let date;
export let dateStyle;
export let timeStyle;
function formatDate(input, dateStyle, timeStyle) {
if (typeof input === 'string') {
input = new Date(input);
}
return new Intl.DateTimeFormat(undefined, {
dateStyle,
timeStyle,
}).format(input);
}
</script>
{formatDate(date, dateStyle, timeStyle)}

View file

@ -0,0 +1,18 @@
<script>
export let startDate;
export let endDate;
export let dateStyle;
export let timeStyle;
function formatRange(startDate, endDate, dateStyle, timeStyle) {
if (typeof input === 'string') {
input = new Date(input);
}
return new Intl.DateTimeFormat(undefined, {
dateStyle,
timeStyle,
}).formatRange(startDate, endDate);
}
</script>
{formatRange(startDate, endDate, dateStyle, timeStyle)}

View file

@ -0,0 +1,31 @@
<script>
import dayjs from 'dayjs';
import {
Input,
} from 'sveltestrap';
export let format = 'YYYY-MM-DD HH:mm';
export let date = new Date();
let className = '';
export { className as class };
export let id = null;
export let required = false;
let internal;
const input = (x) => (internal = dayjs(x).format(format));
const output = (x) => {
const d = dayjs(x, format).toDate();
if (d) {
date = d.toISOString();
}
};
$: input(date)
$: output(internal)
</script>
<Input type="datetime-local" class={className} id={id} {required} bind:value={internal} />

View file

@ -91,7 +91,6 @@
<div class="d-flex justify-content-center align-items-center gap-2">
<Spinner color="primary" /> Chargement en cours&hellip;
</div>
{:then gongs}
{/await}
{/if}
</div>

View file

@ -0,0 +1,71 @@
export class AlarmException {
constructor(res) {
if (res) {
this.update(res);
}
}
update({ id, start, end, comment }) {
this.id = id;
this.start = start;
this.end = end;
this.comment = comment;
}
_start() {
return new Date(this.start);
}
_end() {
return new Date(this.end);
}
async delete() {
const res = await fetch(`api/alarms/exceptions/${this.id}`, {
method: 'DELETE',
headers: {'Accept': 'application/json'}
});
if (res.status == 200) {
return true;
} else {
throw new Error((await res.json()).errmsg);
}
}
async save() {
const res = await fetch(this.id?`api/alarms/exceptions/${this.id}`:'api/alarms/exceptions', {
method: this.id?'PUT':'POST',
headers: {'Accept': 'application/json'},
body: JSON.stringify(this),
});
if (res.status == 200) {
const data = await res.json();
this.update(data);
return data;
} else {
throw new Error((await res.json()).errmsg);
}
}
}
export async function getAlarmsException() {
const res = await fetch(`api/alarms/exceptions`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
const data = await res.json();
if (data === null)
return [];
else
return data.map((t) => new AlarmException(t));
} else {
throw new Error((await res.json()).errmsg);
}
}
export async function getAlarmException(aid) {
const res = await fetch(`api/alarms/exceptions/${aid}`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return new AlarmException(await res.json());
} else {
throw new Error((await res.json()).errmsg);
}
}

View file

@ -0,0 +1,91 @@
export class AlarmRepeated {
constructor(res) {
if (res) {
this.update(res);
}
}
update({ id, weekday, time, routines, ignore_exceptions, comment }) {
this.id = id;
this.weekday = weekday;
this.time = time;
this.routines = routines;
this.ignore_exceptions = ignore_exceptions;
this.comment = comment;
}
async delete() {
const res = await fetch(`api/alarms/repeated/${this.id}`, {
method: 'DELETE',
headers: {'Accept': 'application/json'}
});
if (res.status == 200) {
return true;
} else {
throw new Error((await res.json()).errmsg);
}
}
async save() {
const res = await fetch(this.id?`api/alarms/repeated/${this.id}`:'api/alarms/repeated', {
method: this.id?'PUT':'POST',
headers: {'Accept': 'application/json'},
body: JSON.stringify(this),
});
if (res.status == 200) {
const data = await res.json();
this.update(data);
return data;
} else {
throw new Error((await res.json()).errmsg);
}
}
}
export async function getAlarmsRepeated() {
const res = await fetch(`api/alarms/repeated`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
const data = await res.json();
if (data === null)
return [];
else
return data.map((t) => new AlarmRepeated(t));
} else {
throw new Error((await res.json()).errmsg);
}
}
export async function getAlarmRepeated(aid) {
const res = await fetch(`api/alarms/repeated/${aid}`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return new AlarmRepeated(await res.json());
} else {
throw new Error((await res.json()).errmsg);
}
}
export function weekdayStr(weekday) {
switch (weekday) {
case 0:
case "0":
return "dimanche";
case 1:
case "1":
return "lundi";
case 2:
case "2":
return "mardi";
case 3:
case "3":
return "mercredi";
case 4:
case "4":
return "jeudi";
case 5:
case "5":
return "vendredi";
case 6:
case "6":
return "samedi";
}
}

63
ui/src/lib/alarmsingle.js Normal file
View file

@ -0,0 +1,63 @@
export class AlarmSingle {
constructor(res) {
if (res) {
this.update(res);
}
}
update({ id, time, routines, comment }) {
this.id = id;
this.time = new Date(time);
this.routines = routines;
this.comment = comment;
}
async delete() {
const res = await fetch(`api/alarms/single/${this.id}`, {
method: 'DELETE',
headers: {'Accept': 'application/json'}
});
if (res.status == 200) {
return true;
} else {
throw new Error((await res.json()).errmsg);
}
}
async save() {
const res = await fetch(this.id?`api/alarms/single/${this.id}`:'api/alarms/single', {
method: this.id?'PUT':'POST',
headers: {'Accept': 'application/json'},
body: JSON.stringify(this),
});
if (res.status == 200) {
const data = await res.json();
this.update(data);
return data;
} else {
throw new Error((await res.json()).errmsg);
}
}
}
export async function getAlarmsSingle() {
const res = await fetch(`api/alarms/single`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
const data = await res.json();
if (data === null)
return [];
else
return data.map((t) => new AlarmSingle(t));
} else {
throw new Error((await res.json()).errmsg);
}
}
export async function getAlarmSingle(aid) {
const res = await fetch(`api/alarms/single/${aid}`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return new AlarmSingle(await res.json());
} else {
throw new Error((await res.json()).errmsg);
}
}

View file

@ -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;
}
}

View file

@ -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";

View file

@ -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&hellip;
</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&hellip;
</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&nbsp;?</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&hellip;
</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>

View file

@ -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&hellip;
</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&hellip;
</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>

View file

@ -23,10 +23,6 @@ function createActionsStore() {
return list;
},
getActionByFilename: (fname) => {
},
update: (res_actions, cb=null) => {
if (res_actions.status === 200) {
res_actions.json().then((list) => {

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsException } from '../lib/alarmexception'
function createAlarmsExceptionStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsException();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsException, cb=null) => {
if (res_AlarmsException.status === 200) {
res_AlarmsException.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsExceptions = createAlarmsExceptionStore();

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsRepeated } from '../lib/alarmrepeated'
function createAlarmsRepeatedStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsRepeated();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsRepeated, cb=null) => {
if (res_AlarmsRepeated.status === 200) {
res_AlarmsRepeated.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsRepeated = createAlarmsRepeatedStore();

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsSingle } from '../lib/alarmsingle'
function createAlarmsSingleStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsSingle();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsSingle, cb=null) => {
if (res_AlarmsSingle.status === 200) {
res_AlarmsSingle.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsSingle = createAlarmsSingleStore();