preparing to patch multiple (selected) times in one call

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-27 08:47:13 +01:00
parent 0e551f45b6
commit 8239bfefab
3 changed files with 36 additions and 20 deletions

View File

@@ -139,7 +139,6 @@
async function patchLocation(location,field,newValue){
const data = {};
data[field] = newValue;
console.log(data);
const url = api(`stock/location/${location.id}`);
const res = await fetch(url,{
credentials: 'include',

View File

@@ -1,8 +1,8 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, drop, patch, post } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
import { timetrack } from '../../user.svelte.js';
import { display } from '../../time.svelte.js';
@@ -33,11 +33,7 @@
async function addTime(task_id){
const url = api(`time/track_task/${task_id}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : now()
}); // create new time or return time with assigned tasks
const resp = await post(url,now()); // create new time or return time with assigned tasks
if (resp.ok) {
const track = await resp.json();
timetrack.running = track;
@@ -85,11 +81,7 @@
evt.preventDefault();
evt.stopPropagation();
const url = api('time/join');
const res = await fetch(url,{
credentials : 'include',
method : 'POST',
body : `${id1}+${id2}`
});
const res = await post(url,`${id1}+${id2}`);
if (res.ok){
yikes();
let json = await res.json();
@@ -139,10 +131,7 @@
async function onDrop(time_id){
const url = api(`time/${time_id}`);
const res = await fetch(url,{
credentials:'include',
method:'DELETE'
});
const res = await drop(url);
if (res.ok){
delete times[time_id];
yikes();
@@ -151,6 +140,16 @@
}
}
async function multi_update(changeSet){
console.log({ids:Object.keys(selected),patch:patch});
const url = api('time');
const res = await patch(url,changeSet);
if (res.ok){
yikes();
alert('todo');
} else error(res);
}
function openProject(pid){
router.navigate(`/project/${pid}/view`);
}
@@ -211,6 +210,9 @@
{#if selectionSum}
<div class="timetracks sum">
{t('sum_of_records')}: <span>{selectionSum.toFixed(3)}&nbsp;{t('hours')}</span>
<button class="symbol" title={t('open')} onclick={e => multi_update({status:'open'})} ></button>
<button class="symbol" title={t('waiting')} onclick={e => multi_update({status:'waiting'})} ></button>
<button class="symbol" title={t('closed')} onclick={e => multi_update({status:'closed'})} ></button>
</div>
{/if}
<table class="timetracks">

View File

@@ -4,7 +4,22 @@ export function api(rel_path){
return `${location.protocol}//${location.host.replace('5173','8080')}/api/${rel_path}`;
}
export async function post(url,data){
export function drop(url){
return fetch(url,{
credentials:'include',
method:'DELETE'
});
}
export function patch(url,data){
return fetch(url,{
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
}
export function post(url,data){
return fetch(url,{
credentials : 'include',
method : 'POST',