Add categories to sort/filter works/surveys
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b88d284859
commit
4c76dd9728
17 changed files with 586 additions and 25 deletions
39
ui/src/routes/categories/[cid]/index.svelte
Normal file
39
ui/src/routes/categories/[cid]/index.svelte
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<script context="module">
|
||||
import { getWork } from '$lib/works';
|
||||
|
||||
export async function load({ params }) {
|
||||
return {
|
||||
props: {
|
||||
cid: params.cid,
|
||||
},
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { user } from '$lib/stores/user';
|
||||
import CategoryAdmin from '$lib/components/CategoryAdmin.svelte';
|
||||
import { Category, getCategory } from '$lib/categories';
|
||||
|
||||
export let cid;
|
||||
|
||||
let categoryP = null;
|
||||
$: {
|
||||
categoryP = getCategory(cid);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#await categoryP then category}
|
||||
<div class="d-flex align-items-center">
|
||||
<h2>
|
||||
<a href="categories/" class="text-muted" style="text-decoration: none"><</a>
|
||||
{category.label}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{#if $user && $user.is_admin}
|
||||
<CategoryAdmin {category} on:saved={(e) => { goto(`categories/`)}} />
|
||||
{/if}
|
||||
{/await}
|
||||
70
ui/src/routes/categories/index.svelte
Normal file
70
ui/src/routes/categories/index.svelte
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<script>
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { user } from '$lib/stores/user';
|
||||
import { getCategories } from '$lib/categories';
|
||||
import { getPromos } from '$lib/users';
|
||||
|
||||
function showCategory(category) {
|
||||
goto(`categories/${category.id}`)
|
||||
}
|
||||
|
||||
let filterPromo = "";
|
||||
</script>
|
||||
|
||||
{#if $user && $user.is_admin}
|
||||
<a href="categories/new" class="btn btn-primary ml-1 float-end" title="Ajouter une catégorie">
|
||||
<i class="bi bi-plus"></i>
|
||||
</a>
|
||||
{#await getPromos() then promos}
|
||||
<div class="float-end me-2">
|
||||
<select class="form-select" bind:value={filterPromo}>
|
||||
<option value="">-</option>
|
||||
{#each promos as promo, pid (pid)}
|
||||
<option value={promo}>{promo}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
<h2>
|
||||
Catégories // cours
|
||||
</h2>
|
||||
|
||||
{#await getCategories()}
|
||||
<div class="text-center">
|
||||
<div class="spinner-border text-danger mx-3" role="status"></div>
|
||||
<span>Chargement des catégories …</span>
|
||||
</div>
|
||||
{:then categories}
|
||||
<table class="table table-sm table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nom</th>
|
||||
<th>Promo</th>
|
||||
<th>Étendre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each categories.filter((c) => (filterPromo === "" || filterPromo === c.promo)) as c (c.id)}
|
||||
<tr>
|
||||
<td>{c.id}</td>
|
||||
<td>
|
||||
<a href="categories/{c.id}">{c.label}</a>
|
||||
</td>
|
||||
<td>{c.promo}</td>
|
||||
<td>
|
||||
<span
|
||||
class="badge"
|
||||
class:bg-success={c.expand}
|
||||
class:bg-danger={!c.expand}
|
||||
>
|
||||
{c.expand?"Oui":"Non"}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{/await}
|
||||
20
ui/src/routes/categories/new.svelte
Normal file
20
ui/src/routes/categories/new.svelte
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<script>
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { user } from '$lib/stores/user';
|
||||
import CategoryAdmin from '$lib/components/CategoryAdmin.svelte';
|
||||
import { Category } from '$lib/categories';
|
||||
|
||||
let category = new Category();
|
||||
</script>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<h2>
|
||||
<a href="categories/" class="text-muted" style="text-decoration: none"><</a>
|
||||
Nouvelle catégorie
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{#if $user && $user.is_admin}
|
||||
<CategoryAdmin {category} on:saved={(e) => { goto(`categories/${e.detail.id}`)}} />
|
||||
{/if}
|
||||
Reference in a new issue