editor: odstraňování a přidávání nodů (fixes #21)
This commit is contained in:
parent
fb192d5af7
commit
f094973865
1 changed files with 66 additions and 3 deletions
|
@ -53,14 +53,71 @@
|
|||
await saveTasks(tasks);
|
||||
}
|
||||
|
||||
function openTaskDetailEditor(e: CustomEvent<TaskDescriptor>) {
|
||||
function openTaskDetailEditorButton(e: CustomEvent<TaskDescriptor>) {
|
||||
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);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
@ -127,7 +184,7 @@
|
|||
on:preSelectTask={startHovering}
|
||||
bind:this={graph}
|
||||
{nodeDraggingEnabled}
|
||||
on:openTask={openTaskDetailEditor} />
|
||||
on:openTask={openTaskDetailEditorButton} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
|
@ -150,6 +207,12 @@
|
|||
<button on:click={saveCurrentStateWithPositions}>Uložit aktuální stav
|
||||
včetně pozic nodů</button>
|
||||
</div>
|
||||
<div>
|
||||
<button on:click={addTask}>Nový node</button>
|
||||
</div>
|
||||
<div>
|
||||
<button on:click={() => removeTask(clicked[clicked.length - 1])}>Odstranit {clicked[clicked.length - 1]}</button>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={nodeDraggingEnabled} /> Povolit přesouvání
|
||||
|
|
Reference in a new issue