97 lines
2.5 KiB
Svelte
97 lines
2.5 KiB
Svelte
<script>
|
|
import { goto } from '$app/navigation';
|
|
import { page } from '$app/stores';
|
|
|
|
import {
|
|
Button,
|
|
Icon,
|
|
Spinner,
|
|
} from '@sveltestrap/sveltestrap';
|
|
|
|
import { gongs } from '$lib/stores/gongs';
|
|
|
|
function chooseGong(gong) {
|
|
gong.setDefault().then(() => {
|
|
gongs.refresh();
|
|
});
|
|
}
|
|
|
|
export let flush = false;
|
|
export let edit = false;
|
|
|
|
export { className as class };
|
|
let className = '';
|
|
|
|
let refreshInProgress = false;
|
|
function refresh_gongs() {
|
|
refreshInProgress = true;
|
|
gongs.refresh().then(() => {
|
|
refreshInProgress = false;
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<div class="d-flex justify-content-between align-items-center" class:px-2={flush}>
|
|
<h2>
|
|
Gongs
|
|
</h2>
|
|
<div>
|
|
{#if !edit}
|
|
<Button
|
|
href="musiks/gongs"
|
|
color="outline-info"
|
|
size="sm"
|
|
>
|
|
<Icon name="pencil" />
|
|
</Button>
|
|
{/if}
|
|
<Button
|
|
href="musiks/gongs/new"
|
|
color="outline-primary"
|
|
size="sm"
|
|
>
|
|
<Icon name="plus-lg" />
|
|
</Button>
|
|
<Button
|
|
color="outline-dark"
|
|
size="sm"
|
|
title="Rafraîchir la liste des gongs"
|
|
on:click={refresh_gongs}
|
|
disabled={refreshInProgress}
|
|
>
|
|
{#if !refreshInProgress}
|
|
<Icon name="arrow-clockwise" />
|
|
{:else}
|
|
<Spinner color="dark" size="sm" />
|
|
{/if}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div class="list-group {className}" class:list-group-flush={flush}>
|
|
{#if $gongs.list}
|
|
{#each $gongs.list as gong (gong.id)}
|
|
<button
|
|
type="button"
|
|
class="list-group-item list-group-item-action"
|
|
class:active={(edit && $page.url.pathname.indexOf('/gongs/') !== -1 && $page.params.gid == gong.id) || (!edit && gong.enabled)}
|
|
aria-current="true"
|
|
on:click={() => {
|
|
if (edit) {
|
|
goto('musiks/gongs/' + gong.id);
|
|
} else {
|
|
chooseGong(gong);
|
|
}
|
|
}}
|
|
>
|
|
{gong.name}
|
|
</button>
|
|
{/each}
|
|
{:else}
|
|
{#await gongs.refresh()}
|
|
<div class="d-flex justify-content-center align-items-center gap-2">
|
|
<Spinner color="primary" /> Chargement en cours…
|
|
</div>
|
|
{/await}
|
|
{/if}
|
|
</div>
|