implemented editor for times

This commit is contained in:
2025-08-28 10:18:50 +02:00
parent 5abfa96dc2
commit 49461199cd
5 changed files with 67 additions and 50 deletions

View File

@@ -4,14 +4,13 @@
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import DateTimeEditor from '../../Components/DateTimeEditor.svelte';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import TimeEditor from '../../Components/TimeRecordEditor.svelte';
let error = $state(null);
let router = useTinyRouter();
let times = $state(null);
let detail = $state(null);
let sortedTimes = $derived.by(() => Object.values(times).sort((b, a) => a.start_time.localeCompare(b.start_time)));
async function loadTimes(){
const url = api('time');
@@ -27,17 +26,20 @@
router.navigate(`task/${tid}/view`);
}
async function update(tid,field,newVal){
times[tid][field] = newVal;
detail = null;
const url = api(`time/${tid}`);
async function update(time){
const url = api(`time/${time.id}`);
time.start_time = time.start_time.split(':').slice(0,2).join(':');
time.end_time = time.end_time.split(':').slice(0,2).join(':');
const res = await fetch(url,{
credentials:'include',
method:'PATCH',
body:JSON.stringify(times[tid])
body:JSON.stringify(time)
});
if (res.ok){
times[tid] = await res.json();
let json = await res.json();
let id = json.id;
for (let key of Object.keys(json)) times[id][key] = json[key];
detail = null;
error = null;
return true;
} else {
@@ -69,23 +71,15 @@
</tr>
</thead>
<tbody>
{#each Object.entries(times) as [tid,time]}
{#if detail == tid}
{#each sortedTimes as time}
{#if detail == time.id}
<tr>
<td>
<div>
<DateTimeEditor value={time.start_time} onSet={dateTime => update(tid,'start_time',dateTime)} />
<DateTimeEditor value={time.end_time} onSet={dateTime => update(tid,'end_time',dateTime)} />
</div>
</td>
<td colspan="2">
<LineEditor simple={true} value={time.subject} onSet={subject => update(tid,'subject',subject)} />
<MarkdownEditor simple={true} value={time.description} onSet={desc => update(tid,'description',desc)} />
<td colspan="5">
<TimeEditor record={time} onSet={update} />
</td>
</tr>
{:else}
<tr onclick={e => {detail = tid}}>
<tr onclick={e => {detail = time.id}}>
<td class="start_end">
{time.start_time}{#if time.end_time}{time.end_time}{/if}
</td>