Browse Source

editor: reset state button and error messages

mj-deploy
Vašek Šraier 4 years ago
parent
commit
013f805128
  1. 17
      frontend/src/Editor.svelte
  2. 13
      frontend/src/tasks.ts

17
frontend/src/Editor.svelte

@ -4,7 +4,7 @@
import Graph from "./Graph.svelte"; import Graph from "./Graph.svelte";
import { nonNull, saveToLocalDisk } from "./helpers"; import { nonNull, saveToLocalDisk } from "./helpers";
import type { TaskDescriptor, TasksFile } from "./tasks"; import type { TaskDescriptor, TasksFile } from "./tasks";
import { saveTasks, getCategories, tasksToString } from "./tasks"; import { resetTasks, saveTasks, getCategories, tasksToString } from "./tasks";
import TaskDisplay from "./TaskDisplay.svelte"; import TaskDisplay from "./TaskDisplay.svelte";
import TaskDetailEditor from "./TaskDetailEditor.svelte"; import TaskDetailEditor from "./TaskDetailEditor.svelte";
import { forceSimulation } from "./force-simulation"; import { forceSimulation } from "./force-simulation";
@ -64,7 +64,15 @@
} }
async function saveCurrentState() { async function saveCurrentState() {
await saveTasks(tasks); await saveTasks(tasks).catch((val) => {
alert(val);
});
}
async function resetCurrentState() {
await resetTasks().catch((val) => {
alert(val);
});
} }
// autosave ;) // autosave ;)
@ -356,14 +364,15 @@
<h3>Toolbox</h3> <h3>Toolbox</h3>
<div> <div>
<button on:click={saveCurrentState}>Uložit aktuální stav</button> <button on:click={saveCurrentState}>Uložit aktuální stav</button>
<button on:click={saveLocally}>Stáhnout data</button> <button on:click={resetCurrentState}>Resetovat aktuální stav</button>
</div> </div>
<button on:click={saveLocally}>Stáhnout data lokálně</button>
<div class="gap" /> <div class="gap" />
<div> <div>
<button on:click={addTask}>Nový node</button> <button on:click={addTask}>Nový node</button>
<button <button
disabled={clicked.length == 0} disabled={clicked.length == 0}
on:click={() => removeTask(clicked[clicked.length - 1])}>Odstranit {clicked[clicked.length - 1] ?? '???'}</button> on:click={() => removeTask(clicked[clicked.length - 1])}>Odstranit "{clicked[clicked.length - 1] ?? '???'}"</button>
</div> </div>
<div class="gap" /> <div class="gap" />
<div> <div>

13
frontend/src/tasks.ts

@ -74,7 +74,18 @@ export async function saveTasks(tasks: TasksFile) {
} }
} }
await fetch("/tasks.json", options) const result = await fetch("/tasks.json", options)
if (result.status != 200) throw `Failed to save tasks.json. ${result.status} ${result.statusText}`
}
export async function resetTasks() {
// request options
const options = {
method: 'DELETE',
}
const result = await fetch("/tasks.json", options)
if (result.status != 200) throw `Failed to reset tasks.json. ${result.status} ${result.statusText}`
} }
export function createTaskMap(tasks: TasksFile): TaskMap { export function createTaskMap(tasks: TasksFile): TaskMap {