mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-06-08 00:23:48 +02:00
Migrate jobTag management
This commit is contained in:
parent
5e696c10d5
commit
6e2703998d
@ -33,26 +33,42 @@
|
||||
import { fuzzySearchTags } from "../utils.js";
|
||||
import Tag from "./Tag.svelte";
|
||||
|
||||
export let job;
|
||||
export let jobTags = job.tags;
|
||||
export let username;
|
||||
export let authlevel;
|
||||
export let roles;
|
||||
export let renderModal = true;
|
||||
/* Svelte 5 Props */
|
||||
let {
|
||||
jobTags = $bindable(),
|
||||
job,
|
||||
username,
|
||||
authlevel,
|
||||
roles,
|
||||
renderModal = true,
|
||||
} = $props();
|
||||
|
||||
let allTags = getContext("tags"),
|
||||
initialized = getContext("initialized");
|
||||
let newTagType = "",
|
||||
newTagName = "",
|
||||
newTagScope = username;
|
||||
let filterTerm = "";
|
||||
let pendingChange = false;
|
||||
let isOpen = false;
|
||||
/* Const Init */
|
||||
const isAdmin = (roles && authlevel == roles.admin);
|
||||
const isSupport = (roles && authlevel == roles.support);
|
||||
|
||||
const client = getContextClient();
|
||||
|
||||
/* State Init */
|
||||
let initialized = getContext("initialized")
|
||||
let allTags = getContext("tags")
|
||||
let newTagType = $state("");
|
||||
let newTagName = $state("");
|
||||
let newTagScope = $state(username);
|
||||
let filterTerm = $state("");
|
||||
let pendingChange = $state(false);
|
||||
let isOpen = $state(false);
|
||||
|
||||
/* Derived Init */
|
||||
const allTagsFiltered = $derived(($initialized, jobTags, fuzzySearchTags(filterTerm, allTags))); // $init und JobTags only for triggering react
|
||||
const usedTagsFiltered = $derived(matchJobTags(jobTags, allTagsFiltered, 'used', isAdmin, isSupport));
|
||||
const unusedTagsFiltered = $derived(matchJobTags(jobTags, allTagsFiltered, 'unused', isAdmin, isSupport));
|
||||
|
||||
/* Effects */
|
||||
$effect(() => {
|
||||
updateNewTag(filterTerm)
|
||||
});
|
||||
|
||||
/* Const Mutations */
|
||||
const createTagMutation = ({ type, name, scope }) => {
|
||||
return mutationStore({
|
||||
client: client,
|
||||
@ -104,19 +120,16 @@
|
||||
});
|
||||
};
|
||||
|
||||
$: allTagsFiltered = ($initialized, fuzzySearchTags(filterTerm, allTags));
|
||||
$: usedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'used', isAdmin, isSupport);
|
||||
$: unusedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'unused', isAdmin, isSupport);
|
||||
|
||||
$: {
|
||||
/* Functions */
|
||||
function updateNewTag(term) {
|
||||
newTagType = "";
|
||||
newTagName = "";
|
||||
let parts = filterTerm.split(":").map((s) => s.trim());
|
||||
let parts = term.split(":").map((s) => s.trim());
|
||||
if (parts.length == 2 && parts.every((s) => s.length > 0)) {
|
||||
newTagType = parts[0];
|
||||
newTagName = parts[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function matchJobTags(tags, availableTags, type, isAdmin, isSupport) {
|
||||
const jobTagIds = tags.map((t) => t.id)
|
||||
@ -183,7 +196,7 @@
|
||||
</script>
|
||||
|
||||
{#if renderModal}
|
||||
<Modal {isOpen} toggle={() => (isOpen = !isOpen)}>
|
||||
<Modal {isOpen} toggle={() => {isOpen = !isOpen; filterTerm = "";}}>
|
||||
<ModalHeader>
|
||||
Manage Tags <Icon name="tags"/>
|
||||
</ModalHeader>
|
||||
@ -232,7 +245,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="danger"
|
||||
on:click={() => removeTagFromJob(utag)}
|
||||
onclick={() => removeTagFromJob(utag)}
|
||||
>
|
||||
<Icon name="x" />
|
||||
</Button>
|
||||
@ -282,7 +295,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="success"
|
||||
on:click={() => addTagToJob(uutag)}
|
||||
onclick={() => addTagToJob(uutag)}
|
||||
>
|
||||
<Icon name="plus" />
|
||||
</Button>
|
||||
@ -314,7 +327,7 @@
|
||||
outline
|
||||
style="width:100%;"
|
||||
color="success"
|
||||
on:click={(e) => (
|
||||
onclick={(e) => (
|
||||
e.preventDefault(), createTag(newTagType, newTagName, newTagScope)
|
||||
)}
|
||||
>
|
||||
@ -345,11 +358,11 @@
|
||||
{/if}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="primary" on:click={() => (isOpen = false)}>Close</Button>
|
||||
<Button color="primary" onclick={() => {isOpen = false; filterTerm = "";}}>Close</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
|
||||
<Button outline on:click={() => (isOpen = true)} size="sm" color="primary">
|
||||
<Button outline onclick={() => (isOpen = true)} size="sm" color="primary">
|
||||
Manage {jobTags?.length ? jobTags.length : ''} Tags
|
||||
</Button>
|
||||
|
||||
@ -387,7 +400,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="danger"
|
||||
on:click={() => removeTagFromJob(utag)}
|
||||
onclick={() => removeTagFromJob(utag)}
|
||||
>
|
||||
<Icon name="x" />
|
||||
</Button>
|
||||
@ -396,7 +409,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="danger"
|
||||
on:click={() => removeTagFromJob(utag)}
|
||||
onclick={() => removeTagFromJob(utag)}
|
||||
>
|
||||
<Icon name="x" />
|
||||
</Button>
|
||||
@ -435,7 +448,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="success"
|
||||
on:click={() => addTagToJob(uutag)}
|
||||
onclick={() => addTagToJob(uutag)}
|
||||
>
|
||||
<Icon name="plus" />
|
||||
</Button>
|
||||
@ -444,7 +457,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
color="success"
|
||||
on:click={() => addTagToJob(uutag)}
|
||||
onclick={() => addTagToJob(uutag)}
|
||||
>
|
||||
<Icon name="plus" />
|
||||
</Button>
|
||||
@ -475,7 +488,7 @@
|
||||
outline
|
||||
style="width:100%;"
|
||||
color="success"
|
||||
on:click={(e) => (
|
||||
onclick={(e) => (
|
||||
e.preventDefault(), createTag(newTagType, newTagName, newTagScope)
|
||||
)}
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user