summaryrefslogtreecommitdiffstats
path: root/apps/projects-web/src/app/pages/views/settings-labels-tile.svelte
blob: f59e233c48d9c3e086a7782dfa93f191326e30e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<script>
	import {IconNames} from "$shared/lib/configuration";
	import {onMount} from "svelte";
	import labels, {reload_labels, delete_label_async} from "$app/lib/stores/labels";
	import Button from "$shared/components/button.svelte";
	import Tile from "$shared/components/tile.svelte";
	import {Table, THead, TBody, TCell, TRow} from "$shared/components/table";

	let is_loading = true;

	$: active_labels = $labels.filter(c => !c.archived);
	$: archived_labels = $labels.filter(c => c.archived);

	async function load_labels() {
		is_loading = true;
		await reload_labels();
		is_loading = false;
	}

	async function handle_edit_label_click(event) {
	}

	async function handle_delete_label_click(event) {
		const row = event.target.closest("tr");
		if (
			row &&
			row.dataset.id &&
			confirm(
				"Are you sure you want to delete this label?\nIt will be removed from all related entries!"
			)
		) {
			await delete_label_async({id: row.dataset.id});
			row.classList.add("d-none");
		}
	}

	onMount(() => {
		load_labels();
	});
</script>

<Tile class="col-6@md col-12 {is_loading ? 'c-disabled loading' : ''}">
    <h2 class="margin-bottom-xxs">Labels</h2>
    {#if active_labels.length > 0 && archived_labels.length > 0}
        <nav class="s-tabs text-sm">
            <ul class="s-tabs__list">
                <li><a class="s-tabs__link s-tabs__link--current"
                       href="#0">Active ({active_labels.length})</a></li>
                <li><a class="s-tabs__link"
                       href="#0">Archived ({archived_labels.length})</a></li>
            </ul>
        </nav>
    {/if}
    <div class="max-width-100% overflow-auto">
        <Table class="text-sm width-100%">
            <THead class="text-left">
            <TCell type="th"
                   thScope="row">
                Name
            </TCell>
            <TCell type="th"
                   thScope="row">
                Color
            </TCell>
            <TCell type="th"
                   thScope="row"
                   style="width: 50px;">
            </TCell>
            </THead>
            <TBody class="text-left">
            {#if $labels.length > 0}
                {#each $labels as label}
                    <TRow class="text-nowrap"
                          dataId={label.id}>
                        <TCell>
                            {label.name}
                        </TCell>
                        <TCell>
                        <span style="border-left: 3px solid {label.color}; background-color:{label.color}25;">
                            {label.color}
                        </span>
                        </TCell>
                        <TCell>
                            <Button icon="{IconNames.pencilSquare}"
                                    variant="reset"
                                    icon_width="1.2rem"
                                    class="hide"
                                    icon_height="1.2rem"
                                    on:click={handle_edit_label_click}
                                    title="Edit entry"/>
                            <Button icon="{IconNames.trash}"
                                    variant="reset"
                                    icon_width="1.2rem"
                                    icon_height="1.2rem"
                                    on:click={handle_delete_label_click}
                                    title="Delete entry"/>
                        </TCell>
                    </TRow>
                {/each}
            {:else}
                <TRow>
                    <TCell type="th"
                           thScope="row"
                           colspan="3">
                        No labels
                    </TCell>
                </TRow>
            {/if}
            </TBody>
        </Table>
    </div>
</Tile>