implemented editing of notes

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-07-30 18:48:29 +02:00
parent fccec9865a
commit e08bcf17a5
5 changed files with 70 additions and 16 deletions

View File

@@ -16,6 +16,18 @@
entity_id = null
} = $props();
async function load(){
const url = api(`notes/${module}/${entity_id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const data = await resp.json();
notes = data.notes;
authors = data.authors;
} else {
error = await resp.text();
}
}
async function saveNote(){
const url = api(`notes/${module}/${entity_id}`);
const resp = await fetch(url,{
@@ -36,13 +48,16 @@
}
}
async function load(){
const url = api(`notes/${module}/${entity_id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const data = await resp.json();
notes = data.notes;
authors = data.authors;
async function update(nid,src){
const url = api(`notes/${nid}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'PATCH',
body : src
});
if (resp.ok) {
error = false;
return true;
} else {
error = await resp.text();
}
@@ -67,11 +82,11 @@
<span class="error">{error}</span>
{/if}
{#if notes}
{#each Object.entries(notes) as [a,b]}
{#each Object.entries(notes) as [nid,note]}
<fieldset>
<legend class="author">{authors[b.user_id].name}</legend>
<legend class="time">{b.timestamp.replace('T',' ')}</legend>
{@html b.rendered}
<legend class="author">{authors[note.user_id].name}</legend>
<legend class="time">{note.timestamp.replace('T',' ')}</legend>
<Editor value={note.text} onSet={(newVal) => update(nid,newVal)} editable={user.id == note.user_id} />
</fieldset>
{/each}
{/if}