added cache for task and wiki page markdown editor, reverted previous attempt
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m31s
Build Docker Image / Clean-Registry (push) Successful in -4s

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-03 16:15:09 +01:00
parent 9a27a501a8
commit ee7cf20202
7 changed files with 104 additions and 128 deletions

View File

@@ -6,9 +6,9 @@
let { let {
editable = true, editable = true,
onclick = evt => {}, onclick = evt => {},
onRender = src => {},
onSet = newVal => {return true;}, onSet = newVal => {return true;},
simple = false, simple = false,
store_id = null,
type = 'div', type = 'div',
value = $bindable({source:null,rendered:null}) value = $bindable({source:null,rendered:null})
} = $props(); } = $props();
@@ -16,6 +16,7 @@
let editing = $state(false); let editing = $state(false);
let editValue = $state({source:value.source,rendered:value.rendered}); let editValue = $state({source:value.source,rendered:value.rendered});
let start = 0; let start = 0;
let stored_source = $state(store_id ? localStorage.getItem(store_id) : null);
let timer = null; let timer = null;
async function applyEdit(){ async function applyEdit(){
@@ -28,6 +29,7 @@
} }
function doSave(){ function doSave(){
if (store_id) localStorage.removeItem(store_id);
if (simple){ if (simple){
onSet(editValue.source); onSet(editValue.source);
} else applyEdit(); } else applyEdit();
@@ -51,7 +53,7 @@
body : editValue.source body : editValue.source
}); });
editValue.rendered = await resp.text(); editValue.rendered = await resp.text();
onRender(editValue.source); if (store_id) localStorage.setItem(store_id,editValue.source);
} }
function typed(ev){ function typed(ev){
@@ -102,13 +104,37 @@
measured(evt, evt.timeStamp - start); measured(evt, evt.timeStamp - start);
} }
function restore(ev){
editValue.source = stored_source;
stored_source = null;
render();
}
activeField.subscribe((val) => resetEdit()); activeField.subscribe((val) => resetEdit());
if (simple) startEdit(); if (simple) startEdit();
</script> </script>
<style>
.markdown{
position: relative;
}
#restore_markdown{
position: absolute;
right: 50%;
top: -10px;
background: orange;
color: black;
padding: 5px;
border-radius: 5px;
}
</style>
<div class="markdown {editing?'editing':''}"> <div class="markdown {editing?'editing':''}">
{#if editing} {#if editing}
<span class="hint">{@html t('markdown_supported')}</span> <span class="hint">{@html t('markdown_supported')}</span>
{#if stored_source}
<span id="restore_markdown" onclick={restore} class="hint">{t('unsaved_content')}</span>
{/if}
<textarea bind:value={editValue.source} onkeyup={typed} autofocus={!simple}></textarea> <textarea bind:value={editValue.source} onkeyup={typed} autofocus={!simple}></textarea>
<div class="preview">{@html target(editValue.rendered)}</div> <div class="preview">{@html target(editValue.rendered)}</div>
{#if !simple} {#if !simple}

View File

@@ -16,8 +16,8 @@
let extendedSettings = $state(false); let extendedSettings = $state(false);
let parent_task = $state(null); let parent_task = $state(null);
let task = $state({ let task = $state({
name : localStorage.getItem('task.name'), name : '',
description : { source : localStorage.getItem('task.markdown'), rendered : '' }, description : { source:'',rendered:''},
due_date : null, due_date : null,
est_time : null, est_time : null,
members : {}, members : {},
@@ -110,8 +110,7 @@
body : JSON.stringify(task) body : JSON.stringify(task)
}); });
if (resp.ok) { if (resp.ok) {
localStorage.removeItem('task.markdown'); localStorage.removeItem(`task/${task.id}/description`);
localStorage.removeItem('task.name');
if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else! if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else!
task = await resp.json(); task = await resp.json();
if (task.parent_task_id){ if (task.parent_task_id){
@@ -124,12 +123,6 @@
} }
} }
function storeSource(markdown){
if (markdown) localStorage.setItem('task.markdown',markdown);
localStorage.setItem('task.name',task.name);
}
function toggleSettings(){ function toggleSettings(){
extendedSettings = !extendedSettings; extendedSettings = !extendedSettings;
} }
@@ -143,120 +136,74 @@
<fieldset> <fieldset>
<legend>{t('add_object',{object:t('task')})}</legend> <legend>{t('add_object',{object:t('task')})}</legend>
<table {onkeydown}> <div class="task grid2">
<tbody> <div>{t('name')}</div>
<tr> <div>
<th> <input bind:value={task.name} autofocus>
{t('name')} </div>
</th>
<td>
<input bind:value={task.name} autofocus>
</td>
</tr>
{#if project}
<tr>
<th>
{t('project')}
</th>
<td>
{project.name}
</td>
</tr>
{/if}
{#if parent_task}
<tr>
<th>
{t('parent_task')}
</th>
<td>
{parent_task.name}
</td>
</tr>
{/if}
<tr> {#if project}
<th> <div>{t('project')}</div>
{t('description')} <a href="/project/{project.id}/view">{project.name}</a>
</th> {/if}
<td>
<MarkdownEditor bind:value={task.description} onRender={storeSource} simple={true} /> {#if parent_task}
</td> <div>{t('parent_task')}</div>
</tr> <div>{parent_task.name}</div>
<tr> {/if}
<th>
{t('tags')} <div>{t('description')}</div>
</th> <div>
<td> <MarkdownEditor bind:value={task.description} simple={true} store_id="task/add_to/{project_id}"/>
<Tags module="task" bind:tags={task.tags} /> </div>
</td> <div>{t('tags')}</div>
</tr> <div>
{#if extendedSettings} <Tags module="task" bind:tags={task.tags} />
<tr> </div>
<th>
{t('members')} {#if extendedSettings}
</th> <div>{t('members')}</div>
<td> <div>
<PermissionEditor members={task.members} {addMember} {dropMember} {getCandidates} /> <PermissionEditor members={task.members} {addMember} {dropMember} {getCandidates} />
</td> </div>
</tr>
<tr> <div>{t('estimated_time')}</div>
<th> <div>
{t('estimated_time')} <input type="number" bind:value={task.est_time} /> {t('hours')}
</th> </div>
<td>
<input type="number" bind:value={task.est_time} /> {t('hours')} <div>{t('start_date')}</div>
</td> <div>
</tr> <input type="date" bind:value={task.start_date} />
<tr> </div>
<th>
{t('start_date')} <div>{t('due_date')}</div>
</th> <div>
<td> <input type="date" bind:value={task.due_date} />
<input type="date" bind:value={task.start_date} /> </div>
</td>
</tr> <div>{t('subtasks')}</div>
<tr> <div>
<th> <label>
{t('due_date')} <input type="checkbox" bind:checked={task.show_closed} >
</th> {t('display_closed_tasks')}
<td> </label>
<input type="date" bind:value={task.due_date} /> </div>
</td>
</tr> <div>
<tr> {t('index_page')}
<th> </div>
{t('subtasks')} <label>
</th> <input type="checkbox" bind:checked={task.no_index} >
<td> {t('hide_on_index_page')}
<label> </label>
<input type="checkbox" bind:checked={task.show_closed} > {:else}
{t('display_closed_tasks')} <div>{t('extended_settings')}</div>
</label> <div>
</td> <button onclick={toggleSettings}>{t('show')}</button>
</tr> </div>
<tr> {/if}
<th> </div>
{t('index_page')}
</th>
<td>
<label>
<input type="checkbox" bind:checked={task.no_index} >
{t('hide_on_index_page')}
</label>
</td>
</tr>
{:else}
<tr>
<th>
{t('extended_settings')}
</th>
<td>
<button onclick={toggleSettings}>{t('show')}</button>
</td>
</tr>
{/if}
</tbody>
</table>
<button onclick={saveTask}>{t('save_object',{object:t('task')})}</button> <button onclick={saveTask}>{t('save_object',{object:t('task')})}</button>
{#if on_abort} {#if on_abort}
<button onclick={on_abort}>{t('abort')}</button> <button onclick={on_abort}>{t('abort')}</button>

View File

@@ -241,7 +241,7 @@
</div> </div>
{#if task.description} {#if task.description}
<div>{t('description')}</div> <div>{t('description')}</div>
<MarkdownEditor bind:value={task.description} editable={true} onSet={val => update({description:val})} /> <MarkdownEditor store_id="task/{task.id}/description" bind:value={task.description} editable={true} onSet={val => update({description:val})} />
{/if} {/if}
{#if !showSettings && task.start_date} {#if !showSettings && task.start_date}
<div>{t('start_date')}</div> <div>{t('start_date')}</div>

View File

@@ -22,6 +22,7 @@
}); });
if (res.ok){ if (res.ok){
yikes(); yikes();
localStorage.removeItem('wiki/new/content');
router.navigate(`/wiki/${title}/view`); router.navigate(`/wiki/${title}/view`);
} else { } else {
error(res); error(res);
@@ -60,7 +61,7 @@
</label> </label>
<label> <label>
{t('content')} {t('content')}
<Markdown bind:value={content} simple={true} /> <Markdown bind:value={content} simple={true} store_id="wiki/new/content" />
<button type="submit">{t('save')}</button> <button type="submit">{t('save')}</button>
</label> </label>
</form> </form>

View File

@@ -188,7 +188,7 @@
</table> </table>
{/if} {/if}
{/if} {/if}
<MarkdownEditor {editable} value={page.content} onSet={s => patch({content:s})} /> <MarkdownEditor {editable} value={page.content} onSet={s => patch({content:s})} store_id="wiki/{page.id}/description" />
<TagList module="wiki" id={page.id} user_list={Object.keys(page.members).map(id => +id)} /> <TagList module="wiki" id={page.id} user_list={Object.keys(page.members).map(id => +id)} />
<div class="notes"> <div class="notes">
<h3>{t('notes')}</h3> <h3>{t('notes')}</h3>

View File

@@ -399,6 +399,7 @@
"unit_price": "Preis/Einheit", "unit_price": "Preis/Einheit",
"unknown_item_location": "Artikel {0} von {1} {2} ist verknüpft mit unbekanntem Lagerort {3}!", "unknown_item_location": "Artikel {0} von {1} {2} ist verknüpft mit unbekanntem Lagerort {3}!",
"unlink": "Trennen", "unlink": "Trennen",
"unsaved_content": "Hier klicken, um ungespeicherte Änderungen zu laden",
"update": "aktualisieren", "update": "aktualisieren",
"UPDATE_USERS" : "Nutzer aktualisieren", "UPDATE_USERS" : "Nutzer aktualisieren",
"upload_file": "Datei hochladen", "upload_file": "Datei hochladen",

View File

@@ -399,6 +399,7 @@
"unit_price": "price/unit", "unit_price": "price/unit",
"unknown_item_location": "Item {0} of {1} {2} refers to location {3}, which is unknown!", "unknown_item_location": "Item {0} of {1} {2} refers to location {3}, which is unknown!",
"unlink": "unlink", "unlink": "unlink",
"unsaved_content": "Click here to load unsaved changes",
"update": "update", "update": "update",
"UPDATE_USERS" : "update users", "UPDATE_USERS" : "update users",
"upload_file": "upload file", "upload_file": "upload file",