From 1a98b10eee72e728d6c903d2df78f9b9ca886c4a Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 4 May 2023 08:39:38 +0600 Subject: [PATCH] TSK-1403 Improve tags filter (#3126) Signed-off-by: Denis Bykhov --- .../src/components/TagItem.svelte | 2 +- .../src/components/TagsEditor.svelte | 24 +++--- .../src/components/TagsFilter.svelte | 76 +++++++++++-------- 3 files changed, 59 insertions(+), 43 deletions(-) diff --git a/plugins/tags-resources/src/components/TagItem.svelte b/plugins/tags-resources/src/components/TagItem.svelte index f58dae046b..1e4967dace 100644 --- a/plugins/tags-resources/src/components/TagItem.svelte +++ b/plugins/tags-resources/src/components/TagItem.svelte @@ -31,7 +31,7 @@ $: name = element?.title ?? tag?.title ?? 'New item' - $: tagIcon = schema === '3' ? undefined : tagLevel[(((tag?.weight ?? 0) % 3) + 1) as 1 | 2 | 3] + $: tagIcon = schema !== '9' ? undefined : tagLevel[(((tag?.weight ?? 0) % 3) + 1) as 1 | 2 | 3] {#if inline} diff --git a/plugins/tags-resources/src/components/TagsEditor.svelte b/plugins/tags-resources/src/components/TagsEditor.svelte index 207219cfd1..1fd09f03da 100644 --- a/plugins/tags-resources/src/components/TagsEditor.svelte +++ b/plugins/tags-resources/src/components/TagsEditor.svelte @@ -37,7 +37,7 @@ export let key: KeyedAttribute export let showTitle = true export let elements: Map, TagElement> - export let schema: '3' | '9' = key.attr.schema ?? '9' + export let schema: '0' | '3' | '9' = key.attr.schema ?? '0' const dispatch = createEventDispatcher() @@ -138,18 +138,20 @@ removeTag(tag._id) }} on:click={(evt) => { - showPopup( - WeightPopup, - { value: tag.weight ?? 1, format: 'number', schema }, - getEventPopupPositionElement(evt), - (res) => { - if (Number.isFinite(res) && res >= 0 && res <= 8) { - if (res != null) { - dispatch('change', { tag, weight: res }) + if (schema !== '0') { + showPopup( + WeightPopup, + { value: tag.weight ?? 1, format: 'number', schema }, + getEventPopupPositionElement(evt), + (res) => { + if (Number.isFinite(res) && res >= 0 && res <= 8) { + if (res != null) { + dispatch('change', { tag, weight: res }) + } } } - } - ) + ) + } }} /> {/each} diff --git a/plugins/tags-resources/src/components/TagsFilter.svelte b/plugins/tags-resources/src/components/TagsFilter.svelte index 1f47fdb803..4ae06355df 100644 --- a/plugins/tags-resources/src/components/TagsFilter.svelte +++ b/plugins/tags-resources/src/components/TagsFilter.svelte @@ -88,7 +88,7 @@ const el: HTMLElement = ev.currentTarget as HTMLElement el.classList.toggle('show') } - const show: boolean = false + $: show = categories.length <= 1 const getCount = (cat: TagCategory): string => { const count = objects.filter((el) => el.category === cat._id).filter((it) => selected.includes(it._id)).length @@ -111,7 +111,7 @@ categories = categories } - $: schema = filter.key.attribute.schema ?? '9' + $: schema = filter.key.attribute.schema ?? '0' const dispatch = createEventDispatcher() getValues(search) @@ -131,22 +131,24 @@ }} placeholder={phTraslate} /> -
-
+ }) + }} + /> + + {/if}
@@ -154,24 +156,32 @@ {:else} {#each categories as cat} - {#if objects.filter((el) => el.category === cat._id).length > 0} + {@const values = objects.filter((el) => el.category === cat._id)} + {#if values.length > 0}
-
-
- ({objects.filter((el) => el.category === cat._id).length}) - {getCount(cat)} -
+
+ ({values.length}) + {getCount(cat)} +
+ {/if}