improved search: motes now showing name/title of related entities
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
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 { t } from '../../translations.svelte.js';
|
||||
import { display } from '../../time.svelte';
|
||||
@@ -52,6 +52,20 @@
|
||||
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){
|
||||
e.preventDefault();
|
||||
var target = e.target;
|
||||
@@ -95,7 +109,15 @@
|
||||
quitOne();
|
||||
if (resp.ok){
|
||||
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 {
|
||||
error(resp);
|
||||
}
|
||||
@@ -317,7 +339,7 @@
|
||||
{#each Object.values(notes) as note}
|
||||
<li>
|
||||
<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>
|
||||
{@html target(note.text.rendered)}
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user