improved search: motes now showing name/title of related entities

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-28 15:22:20 +01:00
parent 4339e4fd98
commit f402122d0c
2 changed files with 42 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, post, target } from '../../urls.svelte.js'; import { api, get, post, target } from '../../urls.svelte.js';
import { error, warn, yikes } from '../../warn.svelte'; import { error, warn, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
import { display } from '../../time.svelte'; import { display } from '../../time.svelte';
@@ -52,6 +52,20 @@
post(api('wiki/search' ),data).then(handleWikiPages); post(api('wiki/search' ),data).then(handleWikiPages);
} }
async function getTitle(key,module,entity_id){
get(api(module+'/'+entity_id)).then(res => setTitle(res,key,module))
}
async function setTitle(resp,key,module){
if (resp.ok){
const json = await resp.json();
if (json.name) notes[key].title = t(module)+": "+json.name;
if (json.title) notes[key].title = t(module)+": "+json.title;
}
}
function onclick(e){ function onclick(e){
e.preventDefault(); e.preventDefault();
var target = e.target; var target = e.target;
@@ -95,7 +109,15 @@
quitOne(); quitOne();
if (resp.ok){ if (resp.ok){
const json = await resp.json(); const json = await resp.json();
notes = Object.keys(json).length ? json : null; if ( Object.keys(json).length ) {
for (let key of Object.keys(json)){
let module = json[key].module;
let entity_id = json[key].entity_id;
json[key].title = t(module)+' '+entity_id;
getTitle(key,module,entity_id);
}
notes = json;
} else notes = null;
} else { } else {
error(resp); error(resp);
} }
@@ -317,7 +339,7 @@
{#each Object.values(notes) as note} {#each Object.values(notes) as note}
<li> <li>
<b> <b>
<a href="/{note.module}/{note.entity_id}/view" {onclick} >{t(note.module)} {note.entity_id}:</a> <a href="/{note.module}/{note.entity_id}/view" {onclick} >{note.title}</a>
</b> </b>
{@html target(note.text.rendered)} {@html target(note.text.rendered)}
</li> </li>

View File

@@ -132,7 +132,23 @@ public class StockModule extends BaseHandler implements StockService {
yield super.doGet(path,ex); yield super.doGet(path,ex);
} }
} }
case null, default -> super.doGet(path,ex); case null -> super.doGet(path,ex);
default -> {
try {
var id = Long.parseLong(head);
Item item = stockDb.loadItem(id);
Owner owner = item.owner().resolve();
if (owner instanceof Company company) {
if (!companyService().membership(company.id(),user.get().id())) throw forbidden("You are not allowed to access {0}",OBJECT);
}
if (owner instanceof UmbrellaUser u){
if (u.id() != user.get().id()) throw forbidden("You are not allowed to access {0}",OBJECT);
}
yield sendContent(ex,item);
} catch (NumberFormatException nfe){
yield super.doGet(path,ex);
}
}
}; };
} catch (UmbrellaException e){ } catch (UmbrellaException e){
return send(ex,e); return send(ex,e);