handle tag management based on role

This commit is contained in:
Christoph Kluge 2024-09-19 11:15:46 +02:00
parent d7a8bbf40b
commit fe35313305

View File

@ -104,8 +104,8 @@
}; };
$: allTagsFiltered = ($initialized, fuzzySearchTags(filterTerm, allTags)); $: allTagsFiltered = ($initialized, fuzzySearchTags(filterTerm, allTags));
$: usedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'used'); $: usedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'used', isAdmin);
$: unusedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'unused'); $: unusedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'unused', isAdmin);
$: { $: {
newTagType = ""; newTagType = "";
@ -117,12 +117,14 @@
} }
} }
function matchJobTags(tags, availableTags, type) { function matchJobTags(tags, availableTags, type, isAdmin) {
const jobTagIds = tags.map((t) => t.id) const jobTagIds = tags.map((t) => t.id)
if (type == 'used') { if (type == 'used') {
return availableTags.filter((at) => jobTagIds.includes(at.id)) return availableTags.filter((at) => jobTagIds.includes(at.id))
} else if (type == 'unused') { } else if (type == 'unused' && isAdmin) {
return availableTags.filter((at) => !jobTagIds.includes(at.id)) return availableTags.filter((at) => !jobTagIds.includes(at.id))
} else if (type == 'unused' && !isAdmin) { // Normal Users should not see unused global tags here
return availableTags.filter((at) => !jobTagIds.includes(at.id) && at.scope !== "global")
} }
return [] return []
} }
@ -209,6 +211,8 @@
{#if pendingChange === utag.id} {#if pendingChange === utag.id}
<Spinner size="sm" secondary /> <Spinner size="sm" secondary />
{:else} {:else}
{#if utag.scope === 'global' || utag.scope === 'admin'}
{#if isAdmin}
<Button <Button
size="sm" size="sm"
color="danger" color="danger"
@ -216,6 +220,25 @@
> >
<Icon name="x" /> <Icon name="x" />
</Button> </Button>
{:else}
<Button
size="sm"
color="dark"
outline
disabled
>
Global Tag
</Button>
{/if}
{:else}
<Button
size="sm"
color="danger"
on:click={() => removeTagFromJob(utag)}
>
<Icon name="x" />
</Button>
{/if}
{/if} {/if}
</span> </span>
</ListGroupItem> </ListGroupItem>
@ -245,6 +268,8 @@
{#if pendingChange === uutag.id} {#if pendingChange === uutag.id}
<Spinner size="sm" secondary /> <Spinner size="sm" secondary />
{:else} {:else}
{#if uutag.scope === 'global' || uutag.scope === 'admin'}
{#if isAdmin}
<Button <Button
size="sm" size="sm"
color="success" color="success"
@ -253,6 +278,16 @@
<Icon name="plus" /> <Icon name="plus" />
</Button> </Button>
{/if} {/if}
{:else}
<Button
size="sm"
color="success"
on:click={() => addTagToJob(uutag)}
>
<Icon name="plus" />
</Button>
{/if}
{/if}
</span> </span>
</ListGroupItem> </ListGroupItem>
{/each} {/each}
@ -345,6 +380,8 @@
{#if pendingChange === utag.id} {#if pendingChange === utag.id}
<Spinner size="sm" secondary /> <Spinner size="sm" secondary />
{:else} {:else}
{#if utag.scope === 'global' || utag.scope === 'admin'}
{#if isAdmin}
<Button <Button
size="sm" size="sm"
color="danger" color="danger"
@ -353,6 +390,16 @@
<Icon name="x" /> <Icon name="x" />
</Button> </Button>
{/if} {/if}
{:else}
<Button
size="sm"
color="danger"
on:click={() => removeTagFromJob(utag)}
>
<Icon name="x" />
</Button>
{/if}
{/if}
</span> </span>
</ListGroupItem> </ListGroupItem>
{/each} {/each}
@ -381,6 +428,8 @@
{#if pendingChange === uutag.id} {#if pendingChange === uutag.id}
<Spinner size="sm" secondary /> <Spinner size="sm" secondary />
{:else} {:else}
{#if uutag.scope === 'global' || uutag.scope === 'admin'}
{#if isAdmin}
<Button <Button
size="sm" size="sm"
color="success" color="success"
@ -389,6 +438,16 @@
<Icon name="plus" /> <Icon name="plus" />
</Button> </Button>
{/if} {/if}
{:else}
<Button
size="sm"
color="success"
on:click={() => addTagToJob(uutag)}
>
<Icon name="plus" />
</Button>
{/if}
{/if}
</span> </span>
</ListGroupItem> </ListGroupItem>
{/each} {/each}