|
|
|
@ -2,16 +2,16 @@ |
|
|
|
import { onMount } from 'svelte'; |
|
|
|
import { onMount } from 'svelte'; |
|
|
|
import { api } from '../../urls.svelte.js'; |
|
|
|
import { api } from '../../urls.svelte.js'; |
|
|
|
import { t } from '../../translations.svelte.js'; |
|
|
|
import { t } from '../../translations.svelte.js'; |
|
|
|
|
|
|
|
import { user } from '../../user.svelte.js'; |
|
|
|
import Editor from '../../Components/MarkdownEditor.svelte'; |
|
|
|
import Editor from '../../Components/MarkdownEditor.svelte'; |
|
|
|
|
|
|
|
|
|
|
|
let error = $state(null); |
|
|
|
let error = $state(null); |
|
|
|
let { module = null, entity_id = null } = $props(); |
|
|
|
let { module = null, entity_id = null } = $props(); |
|
|
|
let note = $state({source:null,rendered:null}); |
|
|
|
let note = $state({source:null,rendered:null}); |
|
|
|
let notes = $state(null); |
|
|
|
let notes = $state(null); |
|
|
|
|
|
|
|
let authors = $state(null); |
|
|
|
|
|
|
|
|
|
|
|
async function onclick(){ |
|
|
|
async function saveNote(){ |
|
|
|
alert(note.source); |
|
|
|
|
|
|
|
const url = api(`notes/${module}/${entity_id}`); |
|
|
|
const url = api(`notes/${module}/${entity_id}`); |
|
|
|
const resp = await fetch(url,{ |
|
|
|
const resp = await fetch(url,{ |
|
|
|
credentials:'include', |
|
|
|
credentials:'include', |
|
|
|
@ -19,8 +19,15 @@ |
|
|
|
body:note.source |
|
|
|
body:note.source |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (resp.ok){ |
|
|
|
if (resp.ok){ |
|
|
|
|
|
|
|
let newNote = await resp.json(); |
|
|
|
|
|
|
|
authors[user.id] = user; |
|
|
|
|
|
|
|
notes[newNote.id] = newNote; |
|
|
|
|
|
|
|
note = {source:'',rendered:''}; |
|
|
|
|
|
|
|
error = null; |
|
|
|
|
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
error = await resp.text(); |
|
|
|
error = await resp.text(); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -28,7 +35,9 @@ |
|
|
|
const url = api(`notes/${module}/${entity_id}`); |
|
|
|
const url = api(`notes/${module}/${entity_id}`); |
|
|
|
const resp = await fetch(url,{credentials:'include'}); |
|
|
|
const resp = await fetch(url,{credentials:'include'}); |
|
|
|
if (resp.ok){ |
|
|
|
if (resp.ok){ |
|
|
|
notes = await resp.json(); |
|
|
|
const data = await resp.json(); |
|
|
|
|
|
|
|
notes = data.notes; |
|
|
|
|
|
|
|
authors = data.authors; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
error = await resp.text(); |
|
|
|
error = await resp.text(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -37,19 +46,31 @@ |
|
|
|
onMount(load) |
|
|
|
onMount(load) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<h1>{t('notes')}</h1> |
|
|
|
<style> |
|
|
|
|
|
|
|
fieldset{ |
|
|
|
|
|
|
|
position: relative; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
legend.time{ |
|
|
|
|
|
|
|
position: absolute; |
|
|
|
|
|
|
|
top: -19px; |
|
|
|
|
|
|
|
right: 20px; |
|
|
|
|
|
|
|
background: black; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
|
|
{#if error} |
|
|
|
{#if error} |
|
|
|
<span class="error">{error}</span> |
|
|
|
<span class="error">{error}</span> |
|
|
|
{/if} |
|
|
|
{/if} |
|
|
|
|
|
|
|
|
|
|
|
{#if notes} |
|
|
|
{#if notes} |
|
|
|
{#each Object.entries(notes) as [a,b]} |
|
|
|
{#each Object.entries(notes) as [a,b]} |
|
|
|
<fieldset> |
|
|
|
<fieldset> |
|
|
|
<legend>User {b.user_id} – {b.timestamp.replace('T',' ')}</legend> |
|
|
|
<legend class="author">{authors[b.user_id].name}</legend> |
|
|
|
|
|
|
|
<legend class="time">{b.timestamp.replace('T',' ')}</legend> |
|
|
|
{@html b.rendered} |
|
|
|
{@html b.rendered} |
|
|
|
</fieldset> |
|
|
|
</fieldset> |
|
|
|
{/each} |
|
|
|
{/each} |
|
|
|
{/if} |
|
|
|
{/if} |
|
|
|
|
|
|
|
<div class="editor"> |
|
|
|
<Editor simple={true} bind:value={note} /> |
|
|
|
<Editor simple={true} bind:value={note} onSet={saveNote} /> |
|
|
|
<button {onclick}>{t('save_note')}</button> |
|
|
|
<button onclick={saveNote}>{t('save_note')}</button> |
|
|
|
|
|
|
|
</div> |