finally implemented tag search

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-11-10 23:37:40 +01:00
parent 453cad8194
commit b43c9d96fc
+62 -68
View File
@@ -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 @@
</script>
<svelte:head>
<title>Umbrella – {t('search')}{search.key?': '+search.key:''}</title>
<title>Umbrella – {t('search')}{key?': '+key:''}</title>
</svelte:head>
<fieldset class="search">
@@ -310,6 +303,23 @@
<button type="submit">{t('go')}</button>
</form>
</fieldset>
{#if tags && Object.keys(tags).length}
<fieldset>
<legend>
{t('tagged with "{tag}"',{tag:key})}
</legend>
{#each Object.entries(tags) as [module,list]}
<h4>{t(module)}</h4>
<ul>
{#each Object.entries(list) as [id,item]}
<li>
<a target="_blank" href="/{module}/{id}/view" {onclick} >{item?.name?item.name:(item?.comment?.source?item.comment.source:(item?.type?.name?t(item.type.name)+" "+item?.number:t(module)+" "+id))}</a>
</li>
{/each}
</ul>
{/each}
</fieldset>
{/if}
{#if projects}
<fieldset>
<legend>
@@ -318,7 +328,7 @@
<ul>
{#each Object.values(projects) as project}
<li>
<a href="/project/{project.id}/view" {onclick} >{project.name}</a>
<a target="_blank" href="/project/{project.id}/view" {onclick} >{project.name}</a>
</li>
{/each}
</ul>
@@ -332,7 +342,7 @@
<ul>
{#each Object.values(tasks) as task}
<li>
<a href="/task/{task.id}/view" {onclick} class={task.status.name}>{task.name}</a>
<a target="_blank" href="/task/{task.id}/view" {onclick} class={task.status.name}>{task.name}</a>
</li>
{/each}
</ul>
@@ -360,13 +370,13 @@
<ul>
{#each Object.values(companies) as company}
<li>
<a href="/company/{company.id}/view" {onclick} >{company.name}</a>
<a target="_blank" href="/company/{company.id}/view" {onclick} >{company.name}</a>
</li>
{/each}
</ul>
</fieldset>
{/if}
{#if stock}
{#if stock && (Object.keys(stock.items).length || Object.keys(stock.locations).length)}
<fieldset>
<legend>
{t('stock')}
@@ -376,7 +386,7 @@
<ul>
{#each Object.values(stock.items) as item}
<li>
<a href="/stock/{item.owner.type}/{item.owner.id}/item/{item.owner_number}" {onclick} >
<a target="_blank" href="/stock/{item.owner.type}/{item.owner.id}/item/{item.owner_number}" {onclick} >
{item.name} [{t('code')}: <span class="code">{item.code}</span>]
</a>
{@html item.description.rendered}
@@ -389,7 +399,7 @@
<ul>
{#each Object.values(stock.locations) as loc (loc.id)}
<li>
<a href="/stock/location/{loc.id}">{loc.name}</a>
<a target="_blank" href="/stock/location/{loc.id}">{loc.name}</a>
<br/> {@html loc.description.rendered}
</li>
{/each}
@@ -405,7 +415,7 @@
<ul>
{#each Object.values(times) as time}
<li>
<a href="/time/{time.id}/view" {onclick} >
<a target="_blank" href="/time/{time.id}/view" {onclick} >
{display(time.start_time)}{#if time.end_time}…{display(time.end_time)}{/if}
{time.subject}
</a>
@@ -424,7 +434,7 @@
<ul>
{#each Object.values(documents) as document}
<li>
<a href="/document/{document.id}/view" {onclick} >
<a target="_blank" href="/document/{document.id}/view" {onclick} >
{document.number}
({document.date})
{document.sender.name.split('\n')[0]}
@@ -444,7 +454,7 @@
<ul>
{#each Object.values(pages) as page}
<li>
<a href="/wiki/{page.id}/view" {onclick} >
<a target="_blank" href="/wiki/{page.id}/view" {onclick} >
{page.title}
</a>
</li>
@@ -461,7 +471,7 @@
{#each Object.values(notes) as note}
<li>
<b>
<a href="/{note.module}/{note.entity_id}/view" {onclick} >{note.title}</a>
<a target="_blank" href="/{note.module}/{note.entity_id}/view" {onclick} >{note.title}</a>
</b>
{@html target(note.text.rendered)}
</li>
@@ -469,26 +479,10 @@
</ul>
</fieldset>
{/if}
{#if tags}
<fieldset>
<legend>
{t('tags')}
</legend>
{#each Object.entries(tags) as [module,list]}
<h3>{t(module)}</h3>
<ul>
{#each Object.entries(list) as [id,item]}
<li>
<a href="/{module}/{id}/view" {onclick} >{module} {id} {item.name?item.name:(item.comment.source?item.comment.source:'')}</a>
</li>
{/each}
</ul>
{/each}
</fieldset>
{/if}
<!--
<pre>
<code>
{JSON.stringify(tags,null,2)}
</code>
</pre>
</pre>-->