working on tag search

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-11-09 18:53:24 +01:00
parent 6fa9f419d4
commit 7411bc1583
+110 -17
View File
@@ -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();
});
</script>
<svelte:head>
@@ -383,15 +474,17 @@
<legend>
{t('tags')}
</legend>
{#each Object.entries(tags) as [module,list]}
<h3>{t(module)}</h3>
<ul>
{#each Object.entries(tags) as [module,items]}
{#each items as item}
{#each Object.entries(list) as [id,item]}
<li>
<a href="/{module}/{item}/view" {onclick} >{module} {item}</a>
<a href="/{module}/{id}/view" {onclick} >{module} {id} {item.name?item.name:(item.comment.source?item.comment.source:'')}</a>
</li>
{/each}
{/each}
</ul>
{/each}
</fieldset>
{/if}
<pre>