From b43c9d96fcca25a8d96cb469d5e53e4939b3cfd3 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 9 Nov 2026 22:37:06 +0100 Subject: [PATCH] finally implemented tag search Signed-off-by: Stephan Richter --- frontend/src/routes/search/Search.svelte | 130 +++++++++++------------ 1 file changed, 62 insertions(+), 68 deletions(-) diff --git a/frontend/src/routes/search/Search.svelte b/frontend/src/routes/search/Search.svelte index 39e5a680..9b49868f 100644 --- a/frontend/src/routes/search/Search.svelte +++ b/frontend/src/routes/search/Search.svelte @@ -8,11 +8,11 @@ import Bookmark from '../bookmark/Template.svelte'; - const router = useTinyRouter(); let fulltext = false; - search.key = router.getQueryParam('key'); - let counter = 0; + const router = useTinyRouter(); + let key = $derived(router.getQueryParam('key')); + search.key = key; let bookmarks = $state(null); let companies = $state(null); let documents = $state(null); @@ -26,10 +26,20 @@ function doSearch(){ if (counter > 0) return; - counter = 10; warn(t('searching…')); - console.log("doSearch"); - let data = { key : search.key, fulltext : fulltext }; + counter = 10; + bookmarks = null; + companies = null; + documents = null; + notes = null; + pages = null; + projects = null; + stock = null; + tags = null; + tasks = null; + times = null; + + let data = { key, fulltext : fulltext }; post(api('bookmark/search'),data).then(handleBookmarks); post(api('company/search '),data).then(handleCompanies); post(api('document/search'),data).then(handleDocuments); @@ -113,28 +123,15 @@ } } - async function fetchMissing(module, id){ - } async function handleTags(resp){ - quitOne(); if (resp.ok){ const json = await resp.json(); let map = {}; for (let [module, ids] of Object.entries(json)){ let list = {}; + let path = module; map[module] = {}; -/* - let bookmarks = $state(null); - let companies = $state(null); - let documents = $state(null); - let notes = $state(null); - let pages = $state(null); - let projects = $state(null); - let stock = $state(null); - let tags = $state(null); - let tasks = $state(null); - let times = $state(null);*/ switch(module){ case 'bookmark': { if (!bookmarks) bookmarks = {}; @@ -167,9 +164,10 @@ break; } case 'stock': { - if (!stock) stock = {}; - list = stock; - break; + if (!stock) stock = { items : {}}; + list = stock.items; + path = 'stock/item'; + break; } case 'task': { if (!tasks) tasks = {}; @@ -182,15 +180,13 @@ break; } default:{ - console.warn("no handler for "+module+" with tag "+search.key); + console.warn("no handler for "+module+" with tag "+key); continue; } } for (let id of ids){ - console.log("Trying to access "+module+"s:",list); if (!list[id]) { - const url = api(`${module}/${id}`); - console.log("fetching from "+url); + const url = api(`${path}/${id}`); const resp = await get(url); if (resp.ok) { list[id] = await resp.json(); @@ -205,6 +201,7 @@ } else { error(resp); } + quitOne(); } async function handleTasks(resp){ @@ -239,10 +236,12 @@ function onclick(e){ e.preventDefault(); - var target = e.target; - while (target && !target.href) target=target.parentNode; + let target = e.target; let href = target.getAttribute('href'); - if (href) router.navigate(href); + target = target.getAttribute('target'); + if (target == '_blank') { + window.open(href); + } else if (href) router.navigate(href); return false; } @@ -267,8 +266,7 @@ if (counter > 0) { warn(t('searching…')+" "+counter); if (counter == 1) { - console.log("search for tags: "+search.key); - let data = { key : search.key, fulltext : fulltext }; + let data = { key, fulltext : fulltext }; post(api('tags/search'),data).then(handleTags); } } else yikes(); @@ -276,16 +274,11 @@ function updateUrl(ev){ ev.preventDefault(); - console.log('updateUrl'); - let url = window.location.origin + window.location.pathname; - if (search.key) { - url += '?key=' + encodeURI(search.key); - window.history.replaceState(history.state, '', url); - doSearch(); - } + if (search.key) router.navigate(window.location.pathname + '?key=' + encodeURI(search.key)); } $effect(() => { + key = router.getQueryParam('key'); doSearch(); }); @@ -293,7 +286,7 @@ - Umbrella – {t('search')}{search.key?': '+search.key:''} + Umbrella – {t('search')}{key?': '+key:''} +{#if tags && Object.keys(tags).length} +
+ + {t('tagged with "{tag}"',{tag:key})} + + {#each Object.entries(tags) as [module,list]} +

{t(module)}

+ + {/each} +
+{/if} {#if projects}
@@ -318,7 +328,7 @@ @@ -332,7 +342,7 @@ @@ -360,13 +370,13 @@
{/if} -{#if stock} +{#if stock && (Object.keys(stock.items).length || Object.keys(stock.locations).length)}
{t('stock')} @@ -376,7 +386,7 @@
{/if} -{#if tags} -
- - {t('tags')} - - {#each Object.entries(tags) as [module,list]} -

{t(module)}

- - {/each} -
-{/if} + \ No newline at end of file