working on tag search
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -9,11 +9,13 @@
|
|||||||
import Bookmark from '../bookmark/Template.svelte';
|
import Bookmark from '../bookmark/Template.svelte';
|
||||||
|
|
||||||
const router = useTinyRouter();
|
const router = useTinyRouter();
|
||||||
let counter = 10;
|
let fulltext = false;
|
||||||
|
search.key = router.getQueryParam('key');
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
let bookmarks = $state(null);
|
let bookmarks = $state(null);
|
||||||
let companies = $state(null);
|
let companies = $state(null);
|
||||||
let documents = $state(null);
|
let documents = $state(null);
|
||||||
let fulltext = false;
|
|
||||||
let notes = $state(null);
|
let notes = $state(null);
|
||||||
let pages = $state(null);
|
let pages = $state(null);
|
||||||
let projects = $state(null);
|
let projects = $state(null);
|
||||||
@@ -22,10 +24,12 @@
|
|||||||
let tasks = $state(null);
|
let tasks = $state(null);
|
||||||
let times = $state(null);
|
let times = $state(null);
|
||||||
|
|
||||||
function doSearch(key){
|
function doSearch(){
|
||||||
|
if (counter > 0) return;
|
||||||
|
counter = 10;
|
||||||
warn(t('searching…'));
|
warn(t('searching…'));
|
||||||
console.log("doSearch");
|
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('bookmark/search'),data).then(handleBookmarks);
|
||||||
post(api('company/search '),data).then(handleCompanies);
|
post(api('company/search '),data).then(handleCompanies);
|
||||||
post(api('document/search'),data).then(handleDocuments);
|
post(api('document/search'),data).then(handleDocuments);
|
||||||
@@ -33,7 +37,6 @@
|
|||||||
post(api('project/search' ),data).then(handleProjects);
|
post(api('project/search' ),data).then(handleProjects);
|
||||||
post(api('task/search' ),data).then(handleTasks);
|
post(api('task/search' ),data).then(handleTasks);
|
||||||
post(api('stock/search' ),data).then(handleStock);
|
post(api('stock/search' ),data).then(handleStock);
|
||||||
post(api('tags/search' ),data).then(handleTags);
|
|
||||||
post(api('time/search' ),data).then(handleTimes);
|
post(api('time/search' ),data).then(handleTimes);
|
||||||
post(api('wiki/search' ),data).then(handleWikiPages);
|
post(api('wiki/search' ),data).then(handleWikiPages);
|
||||||
}
|
}
|
||||||
@@ -110,15 +113,95 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchMissing(module, id){
|
||||||
|
}
|
||||||
|
|
||||||
async function handleTags(resp){
|
async function handleTags(resp){
|
||||||
quitOne();
|
quitOne();
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
const res = await resp.json();
|
const json = await resp.json();
|
||||||
tags = Object.keys(res).length ? res : null;
|
let map = {};
|
||||||
for (let [module, ids] of Object.entries(tags)){
|
for (let [module, ids] of Object.entries(json)){
|
||||||
console.log("found "+module+" with tags:");
|
let list = {};
|
||||||
// TODO: load entities from 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 = {};
|
||||||
|
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 {
|
} else {
|
||||||
error(resp);
|
error(resp);
|
||||||
}
|
}
|
||||||
@@ -165,7 +248,7 @@
|
|||||||
|
|
||||||
async function setKey(ev){
|
async function setKey(ev){
|
||||||
if (ev) ev.preventDefault();
|
if (ev) ev.preventDefault();
|
||||||
doSearch(search.key);
|
doSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setTitle(resp,key,module){
|
async function setTitle(resp,key,module){
|
||||||
@@ -183,22 +266,30 @@
|
|||||||
counter--;
|
counter--;
|
||||||
if (counter > 0) {
|
if (counter > 0) {
|
||||||
warn(t('searching…')+" "+counter);
|
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();
|
} else yikes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUrl(ev){
|
function updateUrl(ev){
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
console.log('updateUrl');
|
||||||
let url = window.location.origin + window.location.pathname;
|
let url = window.location.origin + window.location.pathname;
|
||||||
if (search.key) {
|
if (search.key) {
|
||||||
url += '?key=' + encodeURI(search.key);
|
url += '?key=' + encodeURI(search.key);
|
||||||
window.history.replaceState(history.state, '', url);
|
window.history.replaceState(history.state, '', url);
|
||||||
doSearch(search.key);
|
doSearch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
doSearch(router.getQueryParam('key'));
|
doSearch();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -383,15 +474,17 @@
|
|||||||
<legend>
|
<legend>
|
||||||
{t('tags')}
|
{t('tags')}
|
||||||
</legend>
|
</legend>
|
||||||
|
{#each Object.entries(tags) as [module,list]}
|
||||||
|
<h3>{t(module)}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{#each Object.entries(tags) as [module,items]}
|
{#each Object.entries(list) as [id,item]}
|
||||||
{#each items as item}
|
|
||||||
<li>
|
<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>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
|
||||||
</ul>
|
</ul>
|
||||||
|
{/each}
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/if}
|
{/if}
|
||||||
<pre>
|
<pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user