improved time selector in document editor
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m23s
Build Docker Image / Clean-Registry (push) Successful in -11s

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-03-26 10:52:22 +01:00
parent 03b9a472c3
commit dba2657894
4 changed files with 52 additions and 49 deletions

View File

@@ -1,12 +1,13 @@
<script>
import { onMount } from 'svelte';
import { api, target } from '../../urls.svelte.js';
import { api, post, target } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
let {
company_id,
hide = {},
onSelect = (time) => {}
} = $props();
@@ -16,11 +17,7 @@
async function loadProjects(){
const url = api('project/list');
let data = { company_id: company_id };
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : JSON.stringify(data)
});
const resp = await post(url,data);
if (resp.ok){
projects = await resp.json();
yikes();
@@ -29,19 +26,25 @@
}
}
function filter(newTimes, excluded_ids){
times = newTimes.filter(time => !excluded_ids.includes(time.id));
}
async function loadTimes(projectId){
const url = api('time/list');
let data = { company_id: company_id, project_id: projectId };
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : JSON.stringify(data)
});
const resp = await post(url,data);
if (resp.ok){
times = await resp.json();
} else {
error(resp);
}
yikes();
let newTimes = await resp.json();
let present_times = Object.values(hide).filter(pos => pos.time_id).map(pos => pos.time_id)
filter(newTimes,present_times);
} else error(resp);
}
function select(time){
filter(times,[time.id]);
onSelect(time);
}
onMount(loadProjects);
@@ -56,12 +59,13 @@
{/if}
{#if times}
{#each times as time,idx2}
<div class="time" onclick={() => onSelect(time)}>
<div class="time" onclick={() => select(time)}>
<span class="duration">{(time.duration).toFixed(3)} {t('hours')}</span>
<span class="subject">{time.subject}</span>
<span class="start_time">{time.start_time}</span>
<span class="start_time">{new Date(time.start_time*1000).toUTCString()}</span>
<span class="description">{@html target(time.description.rendered)}</span>
</div>
<hr/>
{/each}
{/if}
</div>