From f094973865d1518766e71afd4993109ddb13b99c Mon Sep 17 00:00:00 2001 From: Vasek Sraier Date: Wed, 30 Sep 2020 18:14:45 +0200 Subject: [PATCH] =?UTF-8?q?editor:=20odstra=C5=88ov=C3=A1n=C3=AD=20a=20p?= =?UTF-8?q?=C5=99id=C3=A1v=C3=A1n=C3=AD=20nod=C5=AF=20(fixes=20#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/Editor.svelte | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/frontend/src/Editor.svelte b/frontend/src/Editor.svelte index aaeb2dd..6ad492d 100644 --- a/frontend/src/Editor.svelte +++ b/frontend/src/Editor.svelte @@ -53,14 +53,71 @@ await saveTasks(tasks); } - function openTaskDetailEditor(e: CustomEvent) { + function openTaskDetailEditorButton(e: CustomEvent) { + openTaskDetailEditor(e.detail); + } + + function openTaskDetailEditor(t: TaskDescriptor) { open( TaskDetailEditor, - { task: e.detail, tasks: tasks }, + { task: t, tasks: tasks }, { closeButton: false }, { onClose: () => { tasks = tasks; }} ); } + + function addTask() { + let id = prompt("Zadej ID nové úlohy (nepůjde nikdy změnit):"); + if (id == null || id == "") { + alert("Něco tam zadat musíš!"); + return; + } + + let novaUloha: TaskDescriptor = { + id: id, + type: "label", + comment: "...", + requires: [] + }; + + tasks.tasks = [...tasks.tasks, novaUloha]; + + openTaskDetailEditor(novaUloha); + } + + function removeTask(id: string) { + // zkontrolovat existenci + let found = false; + for (const t of tasks.tasks) { + if (t.id == id) { + found = true; + break; + } + } + + if (! found) { + alert("Pokoušíš se smazat úlohu, která neexistuje. To je docela divné!"); + return; + } + + // existují závislosti na tuhle úlohu? + let dependencyExists = false; + for (const t of tasks.tasks) { + for (const r of t.requires) { + if (r == id) { + dependencyExists = true; + break; + } + } + } + if (dependencyExists) { + alert("Pokoušíš se smazat úlohu, na které je někdo jiný závislý! To nejde! Smaž první závislost."); + return; + } + + // je to bezpečné, mažeme + tasks.tasks = tasks.tasks.filter((t) => t.id != id); + }