Browse Source

bugfix: changing states from task list was broken

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/timetracking
Stephan Richter 3 weeks ago
parent
commit
618eddbfda
  1. 39
      frontend/src/routes/task/Index.svelte

39
frontend/src/routes/task/Index.svelte

@ -14,8 +14,9 @@
let map = $state({}); let map = $state({});
let hidden = $state({}); let hidden = $state({});
async function changeState(tid,state){ async function changeState(idx,state){
const task = tasks[tid]; const task = tasks[idx];
const tid = task.id;
const prj = projects[task.project_id]; const prj = projects[task.project_id];
const stat = Object.keys(prj.allowed_states).find(k => prj.allowed_states[k] === state); const stat = Object.keys(prj.allowed_states).find(k => prj.allowed_states[k] === state);
const url = api(`task/${tid}`); const url = api(`task/${tid}`);
@ -25,18 +26,18 @@
body : JSON.stringify({status:stat}) body : JSON.stringify({status:stat})
}); });
if (resp.ok){ if (resp.ok){
tasks[tid] = await resp.json(); tasks[idx] = await resp.json();
} else { } else {
error(resp); error(resp);
} }
} }
function abort(tid){ function abort(idx){
changeState(tid,'CANCELLED'); changeState(idx,'CANCELLED');
} }
function complete(tid){ function complete(idx){
changeState(tid,'COMPLETE'); changeState(idx,'COMPLETE');
} }
function edit(tid){ function edit(tid){
@ -81,16 +82,16 @@
} }
} }
function open(tid){ function open(idx){
changeState(tid,'OPEN'); changeState(idx,'OPEN');
} }
function postpone(tid){ function postpone(idx){
changeState(tid,'PENDING'); changeState(idx,'PENDING');
} }
function start(tid){ function start(idx){
changeState(tid,'STARTED'); changeState(idx,'STARTED');
} }
onMount(load); onMount(load);
@ -115,7 +116,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{#each tasks as task (task.id)} {#each tasks as task,idx}
{#if task.status > 10 && task.status < 60 && !task.no_index && projects[task.project_id]?.status < 60 && !hidden[task.id]} {#if task.status > 10 && task.status < 60 && !task.no_index && projects[task.project_id]?.status < 60 && !hidden[task.id]}
<tr> <tr>
<td onclick={() => go('task',task.id)}>{task.name}</td> <td onclick={() => go('task',task.id)}>{task.name}</td>
@ -136,11 +137,11 @@
</td> </td>
<td> <td>
<button class="symbol" onclick={() => edit(task.id)} title={t('edit')} ></button> <button class="symbol" onclick={() => edit(task.id)} title={t('edit')} ></button>
<button class="symbol" onclick={() => postpone(task.id)} title={t('postpone')} ></button> <button class="symbol" onclick={() => postpone(idx)} title={t('postpone')} ></button>
<button class="symbol" onclick={() => open(task.id)} title={t('open')}></button> <button class="symbol" onclick={() => open(idx)} title={t('open')}></button>
<button class="symbol" onclick={() => start(task.id)} title={t('start')} ></button> <button class="symbol" onclick={() => start(idx)} title={t('start')} ></button>
<button class="symbol" onclick={() => complete(task.id)} title={t('complete')} ></button> <button class="symbol" onclick={() => complete(idx)} title={t('complete')} ></button>
<button class="symbol" onclick={() => abort(task.id)} title={t('abort')} ></button> <button class="symbol" onclick={() => abort(idx)} title={t('abort')} ></button>
</td> </td>
</tr> </tr>
{/if} {/if}

Loading…
Cancel
Save