Browse Source

preparing to patch multiple (selected) times in one call

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/document
Stephan Richter 1 week ago
parent
commit
8239bfefab
  1. 1
      frontend/src/routes/stock/Index.svelte
  2. 38
      frontend/src/routes/time/Index.svelte
  3. 17
      frontend/src/urls.svelte.js

1
frontend/src/routes/stock/Index.svelte

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

38
frontend/src/routes/time/Index.svelte

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

17
frontend/src/urls.svelte.js

@ -4,7 +4,22 @@ export function api(rel_path){
return `${location.protocol}//${location.host.replace('5173','8080')}/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,{ return fetch(url,{
credentials : 'include', credentials : 'include',
method : 'POST', method : 'POST',

Loading…
Cancel
Save