Browse Source

Bulk insert of tasks

mj-deploy
Standa Lukeš 4 years ago
parent
commit
0ba8e229d2
  1. 25
      frontend/src/Editor.svelte
  2. 2
      frontend/src/task-status-cache.ts

25
frontend/src/Editor.svelte

@ -8,6 +8,8 @@
import TaskDisplay from "./TaskDisplay.svelte";
import TaskDetailEditor from "./TaskDetailEditor.svelte";
import { forceSimulation } from "./force-simulation";
import { refresh as refreshTaskStatuses, taskStatuses } from './task-status-cache'
import { isLoggedIn } from "./ksp-task-grabber";
export let tasks: TasksFile;
@ -155,6 +157,26 @@
tasks = tasks;
}
}
async function loadYear() {
if (!isLoggedIn()) {
alert("Musíš se přihlásit")
return
}
const y = prompt("Který ročník (číslo 26...X)")
await refreshTaskStatuses([`${y}-Z1-1`])
const newTasks = Array.from($taskStatuses.values()).filter(t => t.id.startsWith(y + "-") && !tasks.tasks.find(tt => tt.type == "open-data" && tt.taskReference == t.id))
const newDescriptors: TaskDescriptor[] =
newTasks.map(t => ({
type: "open-data",
id: t.id,
taskReference: t.id,
requires: [],
position: [0, 0],
title: t.name
}))
tasks.tasks = [...tasks.tasks, ...newDescriptors]
}
</script>
<style>
@ -309,6 +331,9 @@
Úhel rotace: <input bind:value={angle} type="range" max="360" min="0" on:change={setAngleToTheCurrentLabel} />
</div>
{/if}
<div>
<button on:click={loadYear} disabled={!isLoggedIn()} title={isLoggedIn() ? "Nahraje všechny úlohy z jednoho ročníku, které tu ještě nejsou" : "Je nutné být přihlášený a na stránce v KSP template."}>Nahrát celý ročník</button>
</div>
</div>
<div class="taskDetails">

2
frontend/src/task-status-cache.ts

@ -17,7 +17,7 @@ export const taskStatuses = readable(lastVal, write => {
export function refresh(ids: string[]) {
if (!isLoggedIn()) return;
grabTaskStates(ids).then(t => {
return grabTaskStates(ids).then(t => {
const tt = Array.from(t.entries())
writeFn(new Map(Array.from(lastVal.entries()).concat(tt)))
localStorage.setItem("taskStatuses-cache", JSON.stringify(tt))