Bulk insert of tasks
This commit is contained in:
parent
1af13c38ed
commit
0ba8e229d2
2 changed files with 26 additions and 1 deletions
|
@ -8,6 +8,8 @@
|
||||||
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";
|
||||||
|
import { refresh as refreshTaskStatuses, taskStatuses } from './task-status-cache'
|
||||||
|
import { isLoggedIn } from "./ksp-task-grabber";
|
||||||
|
|
||||||
export let tasks: TasksFile;
|
export let tasks: TasksFile;
|
||||||
|
|
||||||
|
@ -155,6 +157,26 @@
|
||||||
tasks = tasks;
|
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>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -309,6 +331,9 @@
|
||||||
Úhel rotace: <input bind:value={angle} type="range" max="360" min="0" on:change={setAngleToTheCurrentLabel} />
|
Úhel rotace: <input bind:value={angle} type="range" max="360" min="0" on:change={setAngleToTheCurrentLabel} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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>
|
||||||
|
|
||||||
<div class="taskDetails">
|
<div class="taskDetails">
|
||||||
|
|
|
@ -17,7 +17,7 @@ export const taskStatuses = readable(lastVal, write => {
|
||||||
export function refresh(ids: string[]) {
|
export function refresh(ids: string[]) {
|
||||||
if (!isLoggedIn()) return;
|
if (!isLoggedIn()) return;
|
||||||
|
|
||||||
grabTaskStates(ids).then(t => {
|
return grabTaskStates(ids).then(t => {
|
||||||
const tt = Array.from(t.entries())
|
const tt = Array.from(t.entries())
|
||||||
writeFn(new Map(Array.from(lastVal.entries()).concat(tt)))
|
writeFn(new Map(Array.from(lastVal.entries()).concat(tt)))
|
||||||
localStorage.setItem("taskStatuses-cache", JSON.stringify(tt))
|
localStorage.setItem("taskStatuses-cache", JSON.stringify(tt))
|
||||||
|
|
Reference in a new issue