working on form to add subtask

This commit is contained in:
2025-07-25 20:11:19 +02:00
parent 8c7921b1c4
commit be0435db1b
4 changed files with 36 additions and 13 deletions

View File

@@ -74,6 +74,6 @@
</style> </style>
{#if editing} {#if editing}
<textarea bind:value={editValue.source} onkeyup={typed} autofocus></textarea> <textarea bind:value={editValue.source} onkeyup={typed} autofocus={!simple}></textarea>
{/if} {/if}
<div ondblclick={startEdit} class={{editable}} title={t('double_click_to_edit')} >{@html editValue.rendered}</div> <div ondblclick={startEdit} class={{editable}} title={t('double_click_to_edit')} >{@html editValue.rendered}</div>

View File

@@ -91,7 +91,7 @@
{companies[project.company_id].name} {companies[project.company_id].name}
{/if} {/if}
</td> </td>
<td> <td class="state" onclick={() => show(project.id)} >
{t("state_"+project.status.name.toLowerCase())} {t("state_"+project.status.name.toLowerCase())}
</td> </td>
<td class="members" onclick={() => show(project.id)} > <td class="members" onclick={() => show(project.id)} >

View File

@@ -25,11 +25,6 @@
}); });
let router = useTinyRouter(); let router = useTinyRouter();
async function load(){
if (parent_task_id) await loadParent();
if (project_id) loadProject();
}
function addMember(member){ function addMember(member){
for (let uid of Object.keys(member)) task.members[uid] = project.members[uid]; for (let uid of Object.keys(member)) task.members[uid] = project.members[uid];
} }
@@ -39,6 +34,11 @@
console.log({drop:member.user.id}); console.log({drop:member.user.id});
} }
async function load(){
if (parent_task_id) await loadParent();
if (project_id) loadProject();
}
async function loadParent(){ async function loadParent(){
const url = api(`task/${parent_task_id}`); const url = api(`task/${parent_task_id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await fetch(url,{credentials:'include'});
@@ -60,7 +60,7 @@
if (resp.ok){ if (resp.ok){
project = await resp.json(); project = await resp.json();
task.project_id = +project_id; task.project_id = +project_id;
task.members = JSON.parse(JSON.stringify(project.members)); // deep copy task.members = JSON.parse(JSON.stringify(parent_task?parent_task.members:project.members)); // deep copy
error = null; error = null;
} else { } else {
error = await resp.text(); error = await resp.text();
@@ -68,7 +68,8 @@
} }
async function getCandidates(text){ async function getCandidates(text){
const candidates = Object.values(project.members) const origin = parent_task ? parent_task.members : project.members;
const candidates = Object.values(origin)
.filter(member => member.user.name.toLowerCase().includes(text.toLowerCase())) .filter(member => member.user.name.toLowerCase().includes(text.toLowerCase()))
.map(member => [member.user.id,member.user.name]); .map(member => [member.user.id,member.user.name]);
return Object.fromEntries(candidates); return Object.fromEntries(candidates);
@@ -107,7 +108,7 @@
{t('name')} {t('name')}
</th> </th>
<td> <td>
<input bind:value={task.name}> <input bind:value={task.name} autofocus>
</td> </td>
</tr> </tr>
{#if project} {#if project}

View File

@@ -55,6 +55,16 @@
} }
} }
async function loadParent(){
const url = api(`task/${task.parent_task_id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
task.parent = await resp.json();
} else {
error = await resp.text();
}
}
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 fetch(url,{credentials:'include'});
@@ -65,6 +75,7 @@
children = null; children = null;
loadChildren(); loadChildren();
if (task.project_id) loadProject(); if (task.project_id) loadProject();
if (task.parent_task_id) loadParent();
} else { } else {
error = await resp.text(); error = await resp.text();
} }
@@ -74,6 +85,11 @@
if (!project) return; if (!project) return;
router.navigate(`/project/${project.id}/view`) router.navigate(`/project/${project.id}/view`)
} }
function gotoParent(){
if (!task.parent_task_id) return;
router.navigate(`/task/${task.parent_task_id}/view`)
}
</script> </script>
{#if error} {#if error}
@@ -88,9 +104,15 @@
<td class="project name" onclick={gotoProject}>{project.name}</td> <td class="project name" onclick={gotoProject}>{project.name}</td>
</tr> </tr>
{/if} {/if}
{#if task.parent}
<tr>
<th>{t('parent_task')}</th>
<td class="parent task" onclick={gotoParent}>{task.parent.name}</td>
</tr>
{/if}
<tr> <tr>
<th>{t('task')}</th> <th>{t('task')}</th>
<td class="task name">{task.name}</td> <td class="task name" >{task.name}</td>
</tr> </tr>
{#if task.description.rendered} {#if task.description.rendered}
<tr> <tr>
@@ -127,15 +149,15 @@
</ul> </ul>
</td> </td>
</tr> </tr>
{#if children}
<tr> <tr>
<th>{t('subtasks')}</th> <th>{t('subtasks')}</th>
<td class="task children"> <td class="task children">
<button onclick={addChild} >{t('add_subtask')}</button> <button onclick={addChild} >{t('add_subtask')}</button>
{#if children}
<TaskList tasks={children} {estimated_time} /> <TaskList tasks={children} {estimated_time} />
{/if}
</td> </td>
</tr> </tr>
{/if}
</tbody> </tbody>
</table> </table>
{/if} {/if}