Implement DTOs, add managed state for schedule, export to txt
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { Button } from "$lib/components/ui/button/index.js";
|
||||
import { rota, steps } from "../../state.svelte.js";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { type MonthlyScheduleDTO, rota, steps, type ShiftPosition } from "../../state.svelte.js";
|
||||
|
||||
function getResidentName(day: number, slot: number) {
|
||||
function getResidentName(day: number, pos: ShiftPosition) {
|
||||
const residentId = rota.solution[`${day}-${pos}`];
|
||||
const r = rota.findResident(residentId);
|
||||
if (r) return r.name;
|
||||
|
||||
// check for manual
|
||||
const assignedResidents = rota.residents.filter((resident) =>
|
||||
resident.manualShifts.some(
|
||||
(shift) =>
|
||||
@@ -12,6 +18,13 @@
|
||||
)
|
||||
);
|
||||
|
||||
let slot;
|
||||
if (pos == "First") {
|
||||
slot = 1;
|
||||
} else {
|
||||
slot = 2;
|
||||
}
|
||||
|
||||
const resident = assignedResidents[slot - 1];
|
||||
return resident ? resident.name : "-";
|
||||
}
|
||||
@@ -21,23 +34,31 @@
|
||||
return day % 2 === 0 ? 1 : 2;
|
||||
}
|
||||
|
||||
//TODO: invoke rust?
|
||||
// const resident = {
|
||||
// id: crypto.randomUUID(),
|
||||
// name: "",
|
||||
// negativeShifts: [] as CalendarDate[],
|
||||
// manualShifts: [] as CalendarDate[]
|
||||
// };
|
||||
async function generate() {
|
||||
let config = rota.toDTO();
|
||||
console.log(config);
|
||||
|
||||
// try {
|
||||
// let replyFrom = await invoke("add_resident", { resident });
|
||||
// console.log("Result:", replyFrom);
|
||||
// residents = [...residents, resident];
|
||||
// } catch (error) {
|
||||
// console.error("Error:", error);
|
||||
// }
|
||||
try {
|
||||
let schedule = await invoke<MonthlyScheduleDTO>("generate", { config });
|
||||
console.log("replyFromGenerate:", schedule);
|
||||
rota.solution = schedule;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function export_file() {
|
||||
let config = rota.toDTO();
|
||||
let schedule = rota.solution;
|
||||
|
||||
try {
|
||||
await invoke("export", { config, schedule });
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<h2 class="text-2xl font-bold text-zinc-800">{steps[rota.currentStep - 1].title}</h2>
|
||||
<div class="justify-end">
|
||||
@@ -78,15 +99,15 @@
|
||||
onclick={() => "handleCellClick(day, 1)"}
|
||||
class="w-full overflow-hidden rounded border border-pink-200 bg-pink-50 px-1.5 py-1 text-left text-[10px] font-bold text-pink-600 transition-colors hover:bg-pink-100"
|
||||
>
|
||||
{getResidentName(day, 1)}
|
||||
{getResidentName(day, "First")}
|
||||
</button>
|
||||
{/if}
|
||||
{#if slotCount == 2}
|
||||
{#if slotCount > 1}
|
||||
<button
|
||||
onclick={() => "handleCellClick(day, 2)"}
|
||||
class="w-full overflow-hidden rounded border border-emerald-200 bg-emerald-50 px-1.5 py-1 text-left text-[10px] font-bold text-emerald-600 transition-colors hover:bg-emerald-100"
|
||||
>
|
||||
{getResidentName(day, 2)}
|
||||
{getResidentName(day, "Second")}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -99,13 +120,14 @@
|
||||
<Button
|
||||
variant="outline"
|
||||
class="border-zinc-200 bg-white text-zinc-600 shadow-sm transition-all hover:bg-zinc-50 hover:text-zinc-900 active:scale-95"
|
||||
onclick={() => generate()}
|
||||
>
|
||||
Ανακατανομή
|
||||
</Button>
|
||||
<Button
|
||||
onclick={() => "export adasds"}
|
||||
variant="outline"
|
||||
class="border-zinc-200 bg-white text-zinc-600 shadow-sm transition-all hover:bg-zinc-50 hover:text-zinc-900 active:scale-95"
|
||||
onclick={() => export_file()}
|
||||
>
|
||||
Εξαγωγή</Button
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user