refactored timetracking to only use client-supplied times

This commit is contained in:
2025-08-28 22:52:04 +02:00
parent 3a43c5a7ba
commit dabd5eef0b
10 changed files with 176 additions and 124 deletions

View File

@@ -2,10 +2,11 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { dragged } from './dragndrop.svelte.js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { timetrack } from '../../user.svelte.js';
import { dragged } from './dragndrop.svelte';
import { api } from '../../urls.svelte';
import { t } from '../../translations.svelte';
import { timetrack } from '../../user.svelte';
import { now } from '../../time.svelte';
import TaskList from './TaskList.svelte';
import LineEditor from '../../Components/LineEditor.svelte';
@@ -29,11 +30,14 @@
async function addTime(){
const url = api(`time/track_task/${task.id}`);
const resp = await fetch(url,{credentials:'include'}); // create new time or return time with assigned tasks
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : now()
}); // create new time or return time with assigned tasks
if (resp.ok) {
const track = await resp.json();
timetrack.running = track;
console.log(track);
} else {
error = await resp.text();
}

View File

@@ -3,6 +3,7 @@
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { display } from '../../time.svelte.js';
import TimeEditor from '../../Components/TimeRecordEditor.svelte';
@@ -10,7 +11,7 @@
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)));
let sortedTimes = $derived.by(() => Object.values(times).sort((b, a) => a.start_time - b.start_time));
let selected = $state({});
let ranges = {};
let timeMap = $derived.by(calcYearMap);
@@ -29,7 +30,7 @@
let monthIndex = 0;
for (let idx in sortedTimes){
const time = sortedTimes[idx];
const start = time.start_time;
const start = display(time.start_time);
const year = start.substring(0,4);
const month = start.substring(5,7);
if (year != lastYear){
@@ -52,6 +53,7 @@
return result;
}
async function loadTimes(){
const url = api('time');
const resp = await fetch(url,{credentials:'include'});
@@ -88,8 +90,6 @@
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',
@@ -137,13 +137,13 @@
{#each sortedTimes as time,line}
<tr class={selected[time.id]?'selected':''}>
{#if timeMap.years[line]}
<td class="year" rowspan={timeMap.years[line]} onclick={e => toggleRange(time.start_time.substring(0,4))}>
{time.start_time.substring(0,4)}
<td class="year" rowspan={timeMap.years[line]} onclick={e => toggleRange(display(time.start_time).substring(0,4))}>
{display(time.start_time).substring(0,4)}
</td>
{/if}
{#if timeMap.months[line]}
<td class="month" rowspan={timeMap.months[line]} onclick={e => toggleRange(time.start_time.substring(0,7))}>
{time.start_time.substring(5,7)}
<td class="month" rowspan={timeMap.months[line]} onclick={e => toggleRange(display(time.start_time).substring(0,7))}>
{display(time.start_time).substring(5,7)}
</td>
{/if}
{#if detail == time.id}
@@ -152,7 +152,7 @@
</td>
{:else}
<td class="start_end" onclick={e => toggleSelect(time.id)}>
{time.start_time}{#if time.end_time}<wbr><wbr>{time.end_time}{/if}
{display(time.start_time)}{#if time.end_time}<wbr><wbr>{display(time.end_time)}{/if}
</td>
<td class="duration" onclick={e => {detail = time.id}}>
{#if time.duration}