bugfix: moving of tasks in tree now works as intended

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-05-07 18:26:37 +02:00
parent fe57749d9c
commit f35882c967
5 changed files with 27 additions and 74 deletions
+2 -6
View File
@@ -2,7 +2,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, get } from '../../urls.svelte.js'; import { api, get, 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 { user } from '../../user.svelte.js'; import { user } from '../../user.svelte.js';
@@ -104,11 +104,7 @@
async function saveTask(){ async function saveTask(){
const url = api('task/add'); const url = api('task/add');
const resp = await fetch(url,{ const resp = await post(url,task);
credentials : 'include',
method : 'POST',
body : JSON.stringify(task)
});
if (resp.ok) { if (resp.ok) {
localStorage.removeItem(`task/${task.id}/description`); localStorage.removeItem(`task/${task.id}/description`);
if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else! if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else!
+6 -23
View File
@@ -3,7 +3,7 @@
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { dragged } from './dragndrop.svelte'; import { dragged } from './dragndrop.svelte';
import { api } from '../../urls.svelte'; import { api, drop, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
import { timetrack } from '../../user.svelte'; import { timetrack } from '../../user.svelte';
@@ -47,10 +47,7 @@
async function deleteTask(){ async function deleteTask(){
if (confirm(t('confirm_delete',{element:task.name}))){ if (confirm(t('confirm_delete',{element:task.name}))){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await drop(url);
credentials : 'include',
method : 'DELETE'
});
if (resp.ok){ if (resp.ok){
deleted = true; deleted = true;
} else { } else {
@@ -70,11 +67,7 @@
ev.stopPropagation(); ev.stopPropagation();
if (dragged.element.id == task.id) return; if (dragged.element.id == task.id) return;
const url = api(`task/${dragged.element.id}`); const url = api(`task/${dragged.element.id}`);
const resp = await fetch(url,{ const resp = await patch(url, { parent_task_id : task.id});
credentials : 'include',
method : 'PATCH',
body : JSON.stringify({ parent_task_id : task.id})
});
if (resp.ok) { if (resp.ok) {
yikes(); yikes();
} else { } else {
@@ -90,11 +83,7 @@
show_closed : show_closed show_closed : show_closed
}; };
if (task.show_closed) data.show_closed = true; if (task.show_closed) data.show_closed = true;
const resp = await fetch(url,{ const resp = await post(url,data);
credentials : 'include',
method : 'POST',
body : JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
children = await resp.json(); children = await resp.json();
yikes(); yikes();
@@ -112,11 +101,7 @@
async function patchTask(changeset){ async function patchTask(changeset){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await patch(url,changeset);
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(changeset)
});
if (resp.ok){ if (resp.ok){
task = await resp.json(); task = await resp.json();
return true; return true;
@@ -145,9 +130,7 @@
if (children && lastEvent && lastEvent.task) { if (children && lastEvent && lastEvent.task) {
if (lastEvent.event == 'delete' || lastEvent.task.parent_task_id != task.id){ if (lastEvent.event == 'delete' || lastEvent.task.parent_task_id != task.id){
delete children[lastEvent.task.id]; delete children[lastEvent.task.id];
} else { } else children[lastEvent.task.id] = lastEvent.task;
children[lastEvent.task.id] = lastEvent.task;
}
} }
}); });
+8 -18
View File
@@ -2,7 +2,7 @@
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'; import { api, get, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
@@ -17,7 +17,7 @@
async function add(new_task_id){ async function add(new_task_id){
let url = api(`task/${new_task_id}`); let url = api(`task/${new_task_id}`);
let resp = await fetch(url,{ credentials : 'include' }); let resp = await get(url);
if (resp.ok){ if (resp.ok){
yikes(); yikes();
let newTask = await resp.json(); let newTask = await resp.json();
@@ -27,7 +27,7 @@
} }
task.required_tasks_ids.push(new_task_id); task.required_tasks_ids.push(new_task_id);
requiredTasks[new_task_id] = newTask; requiredTasks[new_task_id] = newTask;
await patch(); await update();
delete candidates[new_task_id]; delete candidates[new_task_id];
} else { } else {
error(resp); error(resp);
@@ -59,17 +59,11 @@
async function loadTasks(){ async function loadTasks(){
if (!task || !task.required_tasks_ids || !task.required_tasks_ids.length) return; if (!task || !task.required_tasks_ids || !task.required_tasks_ids.length) return;
const url = api('task/list'); const url = api('task/list');
const res = await fetch(url,{ const res = await post(url,{ids:task.required_tasks_ids});
credentials : 'include',
method : 'POST',
body : JSON.stringify({ids:task.required_tasks_ids})
});
if (res.ok){ if (res.ok){
yikes(); yikes();
requiredTasks = await res.json(); requiredTasks = await res.json();
} else { } else error(resp);
error(resp);
}
} }
function oninput(){ function oninput(){
@@ -84,19 +78,15 @@
return false; return false;
} }
async function patch(){ async function update(){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await patch(url,{required_tasks_ids:task.required_tasks_ids});
credentials : 'include',
method : 'PATCH',
body : JSON.stringify({required_tasks_ids:task.required_tasks_ids})
});
if (!resp.ok) error(resp); if (!resp.ok) error(resp);
} }
async function unlink(required_task){ async function unlink(required_task){
task.required_tasks_ids = task.required_tasks_ids.filter(item => item != required_task.id); task.required_tasks_ids = task.required_tasks_ids.filter(item => item != required_task.id);
patch(); update();
delete requiredTasks[required_task.id]; delete requiredTasks[required_task.id];
} }
+1 -1
View File
@@ -8,7 +8,7 @@
</script> </script>
<ul> <ul>
{#each sortedTasks as task} {#each sortedTasks as task (task.id)}
<ListTask {states} {task} {lastEvent} siblings={tasks} {est_time} show_closed={show_closed || task.show_closed} /> <ListTask {states} {task} {lastEvent} siblings={tasks} {est_time} show_closed={show_closed || task.show_closed} />
{/each} {/each}
</ul> </ul>
+10 -26
View File
@@ -2,7 +2,7 @@
import { onDestroy } from 'svelte'; import { onDestroy } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, eventStream } from '../../urls.svelte'; import { api, eventStream, get, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
import { timetrack } from '../../user.svelte.js'; import { timetrack } from '../../user.svelte.js';
@@ -99,32 +99,24 @@
parent_task_id : +task.id, parent_task_id : +task.id,
show_closed : show_closed show_closed : show_closed
}; };
const resp = await fetch(url,{ const resp = await post(url,data);
credentials : 'include',
method : 'POST',
body:JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
yikes(); yikes();
children = await resp.json(); children = await resp.json();
} else { } else error(resp);
error(resp);
}
} }
async function loadParent(){ async function loadParent(){
const url = api(`task/${task.parent_task_id}`); const url = api(`task/${task.parent_task_id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
task.parent = await resp.json(); task.parent = await resp.json();
} else { } else error(resp);
error(resp);
}
} }
async function loadTask(){ async function loadTask(){
const url = api(`task/${id}`); const url = api(`task/${id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
yikes(); yikes();
task = await resp.json(); task = await resp.json();
@@ -132,20 +124,16 @@
loadChildren(); loadChildren();
if (task.project_id) loadProject(); if (task.project_id) loadProject();
if (task.parent_task_id) loadParent(); if (task.parent_task_id) loadParent();
} else { } else error(resp);
error(resp);
}
} }
async function loadProject(){ async function loadProject(){
const url = api(`project/${task.project_id}`); const url = api(`project/${task.project_id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
project = await resp.json(); project = await resp.json();
yikes(); yikes();
} else { } else error(await resp.text());
error(await resp.text());
}
} }
function showClosed(){ function showClosed(){
@@ -169,11 +157,7 @@
async function update(data){ async function update(data){
const url = api(`task/${id}`); const url = api(`task/${id}`);
const resp = await fetch(url,{ const resp = await patch(url,data);
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
yikes(); yikes();
let json = await resp.json(); let json = await resp.json();