From 6fa9f419d4301ec79cc3282f234cf51cd38abfb8 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 9 Nov 2026 17:04:44 +0100 Subject: [PATCH 1/3] workin on search based on tags Signed-off-by: Stephan Richter --- frontend/src/routes/search/Search.svelte | 43 +++++++++++++++++-- .../srsoftware/umbrella/tags/TagModule.java | 25 +++++++++-- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/frontend/src/routes/search/Search.svelte b/frontend/src/routes/search/Search.svelte index 14d6ee60..86623260 100644 --- a/frontend/src/routes/search/Search.svelte +++ b/frontend/src/routes/search/Search.svelte @@ -9,7 +9,7 @@ import Bookmark from '../bookmark/Template.svelte'; const router = useTinyRouter(); - let counter = 9; + let counter = 10; let bookmarks = $state(null); let companies = $state(null); let documents = $state(null); @@ -18,14 +18,13 @@ let pages = $state(null); let projects = $state(null); let stock = $state(null); + let tags = $state(null); let tasks = $state(null); let times = $state(null); - - function doSearch(key){ warn(t('searching…')); - + console.log("doSearch"); const data = { key : key, fulltext : fulltext }; post(api('bookmark/search'),data).then(handleBookmarks); post(api('company/search '),data).then(handleCompanies); @@ -34,6 +33,7 @@ post(api('project/search' ),data).then(handleProjects); post(api('task/search' ),data).then(handleTasks); post(api('stock/search' ),data).then(handleStock); + post(api('tags/search' ),data).then(handleTags); post(api('time/search' ),data).then(handleTimes); post(api('wiki/search' ),data).then(handleWikiPages); } @@ -110,6 +110,20 @@ } } + async function handleTags(resp){ + quitOne(); + if (resp.ok){ + const res = await resp.json(); + tags = Object.keys(res).length ? res : null; + for (let [module, ids] of Object.entries(tags)){ + console.log("found "+module+" with tags:"); + // TODO: load entities from module + } + } else { + error(resp); + } + } + async function handleTasks(resp){ quitOne(); if (resp.ok){ @@ -364,3 +378,24 @@ {/if} +{#if tags} +
+ + {t('tags')} + +
    + {#each Object.entries(tags) as [module,items]} + {#each items as item} +
  • + {module} {item} +
  • + {/each} + {/each} +
+
+{/if} +
+    
+        {JSON.stringify(tags,null,2)}
+    
+
\ No newline at end of file diff --git a/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java b/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java index c06c5a20..ebc701fe 100644 --- a/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java +++ b/tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java @@ -4,6 +4,7 @@ package de.srsoftware.umbrella.tags; import static de.srsoftware.umbrella.core.ConnectionProvider.connect; import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; +import static de.srsoftware.umbrella.core.constants.Field.KEY; import static de.srsoftware.umbrella.core.constants.Field.USER_LIST; import static de.srsoftware.umbrella.core.constants.Path.SEARCH; import static de.srsoftware.umbrella.core.constants.Path.USES; @@ -94,7 +95,18 @@ public class TagModule extends BaseHandler implements TagService { var user = userService().loadUser(token); if (user.isEmpty()) return unauthorized(ex); var module = path.pop(); - if (module == null) throw unprocessable("Module missing in path."); + return switch (module) { + case null -> throw unprocessable("Module missing in path."); + case SEARCH -> postSearch(ex, path, user.get()); + default -> postTag(ex, module, path); + }; + } catch (UmbrellaException e) { + return send(ex, e); + } + } + + private boolean postTag(HttpExchange ex, String module, Path path) throws IOException { + try { var head = path.pop(); long entityId = Long.parseLong(head); var json = json(ex); @@ -102,7 +114,7 @@ public class TagModule extends BaseHandler implements TagService { List userList = null; if (!json.has(USER_LIST)) throw missingField(USER_LIST); var ul = json.isNull(USER_LIST) ? null : json.get(USER_LIST); - if (ul instanceof JSONArray arr){ + if (ul instanceof JSONArray arr) { userList = arr.toList().stream() .filter(elem -> elem instanceof Number) .map(Number.class::cast) @@ -115,8 +127,6 @@ public class TagModule extends BaseHandler implements TagService { return sendContent(ex, tag); } catch (NumberFormatException e) { return sendContent(ex, HTTP_UNPROCESSABLE, "Entity id missing in path."); - } catch (UmbrellaException e) { - return send(ex, e); } } @@ -149,6 +159,13 @@ public class TagModule extends BaseHandler implements TagService { return entry; } + private boolean postSearch(HttpExchange ex, Path path, UmbrellaUser user) throws IOException { + var json = json(ex); + if (!json.has(KEY)) throw missingField(KEY); + var key = json.getString(KEY); + return getTagUses(ex,key,user); + } + @Override public void save(String module, long entityId, Collection userIds, Collection tags) { tagDb.save(userIds,module,entityId,tags.stream().map(String::trim).toList()); From 7411bc1583979a170ebe9b8b586b611d830204ac Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 9 Nov 2026 18:53:24 +0100 Subject: [PATCH 2/3] working on tag search Signed-off-by: Stephan Richter --- frontend/src/routes/search/Search.svelte | 127 ++++++++++++++++++++--- 1 file changed, 110 insertions(+), 17 deletions(-) diff --git a/frontend/src/routes/search/Search.svelte b/frontend/src/routes/search/Search.svelte index 86623260..39e5a680 100644 --- a/frontend/src/routes/search/Search.svelte +++ b/frontend/src/routes/search/Search.svelte @@ -9,11 +9,13 @@ import Bookmark from '../bookmark/Template.svelte'; const router = useTinyRouter(); - let counter = 10; + let fulltext = false; + search.key = router.getQueryParam('key'); + + let counter = 0; let bookmarks = $state(null); let companies = $state(null); let documents = $state(null); - let fulltext = false; let notes = $state(null); let pages = $state(null); let projects = $state(null); @@ -22,10 +24,12 @@ let tasks = $state(null); let times = $state(null); - function doSearch(key){ + function doSearch(){ + if (counter > 0) return; + counter = 10; warn(t('searching…')); console.log("doSearch"); - const data = { key : key, fulltext : fulltext }; + let data = { key : search.key, fulltext : fulltext }; post(api('bookmark/search'),data).then(handleBookmarks); post(api('company/search '),data).then(handleCompanies); post(api('document/search'),data).then(handleDocuments); @@ -33,7 +37,6 @@ post(api('project/search' ),data).then(handleProjects); post(api('task/search' ),data).then(handleTasks); post(api('stock/search' ),data).then(handleStock); - post(api('tags/search' ),data).then(handleTags); post(api('time/search' ),data).then(handleTimes); post(api('wiki/search' ),data).then(handleWikiPages); } @@ -110,15 +113,95 @@ } } + async function fetchMissing(module, id){ + } + async function handleTags(resp){ quitOne(); if (resp.ok){ - const res = await resp.json(); - tags = Object.keys(res).length ? res : null; - for (let [module, ids] of Object.entries(tags)){ - console.log("found "+module+" with tags:"); - // TODO: load entities from module + const json = await resp.json(); + let map = {}; + for (let [module, ids] of Object.entries(json)){ + let list = {}; + 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 = {}; + list = bookmarks; + break; + } + case 'company': { + if (!companies) companies = {}; + list = companies; + break; + } + case 'document': { + if (!documents) documents = {}; + list = documents; + break; + } + case 'note': { + if (!notes) notes = {}; + list = notes; + break; + } + case 'wiki': { + if (!pages) pages = {}; + list = pages; + break; + } + case 'project': { + if (!projects) projects = {}; + list = projects; + break; + } + case 'stock': { + if (!stock) stock = {}; + list = stock; + break; + } + case 'task': { + if (!tasks) tasks = {}; + list = tasks; + break; + } + case 'time': { + if (!times) times = {}; + list = times; + break; + } + default:{ + console.warn("no handler for "+module+" with tag "+search.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 resp = await get(url); + if (resp.ok) { + list[id] = await resp.json(); + } else { + console.warn(`Failed to fetch ${module} ${id}: ${resp.statusText}`); + } + } + map[module][id] = list[id]; + } } + tags = map; } else { error(resp); } @@ -165,7 +248,7 @@ async function setKey(ev){ if (ev) ev.preventDefault(); - doSearch(search.key); + doSearch(); } async function setTitle(resp,key,module){ @@ -183,22 +266,30 @@ counter--; if (counter > 0) { warn(t('searching…')+" "+counter); + if (counter == 1) { + console.log("search for tags: "+search.key); + let data = { key : search.key, fulltext : fulltext }; + post(api('tags/search'),data).then(handleTags); + } } else yikes(); } 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(search.key); + doSearch(); } } $effect(() => { - doSearch(router.getQueryParam('key')); + doSearch(); }); + + @@ -383,15 +474,17 @@ {t('tags')} + {#each Object.entries(tags) as [module,list]} +

{t(module)}

+ {/each} + {/if}

From d699bd8b7e2b1d22e60bd77b410c55e572c4cb3d Mon Sep 17 00:00:00 2001
From: Stephan Richter 
Date: Mon, 9 Nov 2026 22:37:06 +0100
Subject: [PATCH 3/3] 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