Refactor event handling and introduce TeamSelector component for improved fight management
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
@@ -134,7 +134,7 @@
|
||||
<DialogTitle>Fight Erstellen</DialogTitle>
|
||||
<DialogDescription>Hier kannst du einen neuen Fight erstellen</DialogDescription>
|
||||
</DialogHeader>
|
||||
<FightEdit fight={null} teams={data.teams} event={data.event} groups={data.groups} onSave={handleSave}>
|
||||
<FightEdit fight={null} {data} onSave={handleSave}>
|
||||
{#snippet actions(dirty, submit)}
|
||||
<DialogFooter>
|
||||
<Button disabled={!dirty} onclick={submit}>Speichern</Button>
|
||||
@@ -291,14 +291,7 @@
|
||||
</TableCell>
|
||||
{/each}
|
||||
<TableCell class="text-right">
|
||||
<FightEditRow
|
||||
fight={row.original}
|
||||
teams={data.teams}
|
||||
bind:groups={data.groups}
|
||||
event={data.event}
|
||||
onupdate={(update) => (data.fights = data.fights.map((v) => (v.id === update.id ? update : v)))}
|
||||
{refresh}
|
||||
></FightEditRow>
|
||||
<FightEditRow fight={row.original} {data} onupdate={(update) => (data._fights = data._fights.map((v) => (v.id === update.id ? update : v)))} {refresh}></FightEditRow>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { EventFight, EventFightEdit, ResponseGroups, SWEvent } from "@type/event";
|
||||
import type { EventFight, EventFightEdit, ResponseGroups, ResponseRelation, SWEvent } from "@type/event";
|
||||
import { Button } from "@components/ui/button";
|
||||
import { EditIcon, CopyIcon } from "lucide-svelte";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@components/ui/dialog";
|
||||
@@ -7,21 +7,15 @@
|
||||
import type { Team } from "@components/types/team";
|
||||
import { fightRepo } from "@components/repo/fight";
|
||||
import { eventRepo } from "@components/repo/event";
|
||||
import type { EventModel } from "./eventmodel.svelte";
|
||||
|
||||
let {
|
||||
fight,
|
||||
teams,
|
||||
groups = $bindable(),
|
||||
event,
|
||||
onupdate,
|
||||
refresh,
|
||||
}: { fight: EventFight; teams: Team[]; groups: ResponseGroups[]; event: SWEvent; onupdate: (update: EventFight) => void; refresh: () => void } = $props();
|
||||
let { fight, onupdate, refresh, data }: { fight: EventFight; onupdate: (update: EventFight) => void; refresh: () => void; data: EventModel } = $props();
|
||||
|
||||
let editOpen = $state(false);
|
||||
let duplicateOpen = $state(false);
|
||||
|
||||
async function handleSave(fightData: EventFightEdit) {
|
||||
let f = await $fightRepo.updateFight(event.id, fight.id, {
|
||||
let f = await $fightRepo.updateFight(data.event.id, fight.id, {
|
||||
...fightData,
|
||||
blueTeam: fightData.blueTeam.id,
|
||||
redTeam: fightData.redTeam.id,
|
||||
@@ -34,7 +28,7 @@
|
||||
}
|
||||
|
||||
async function handlyCopy(fightData: EventFightEdit) {
|
||||
await $eventRepo.createFight(event.id.toString(), {
|
||||
await $eventRepo.createFight(data.event.id.toString(), {
|
||||
...fightData,
|
||||
blueTeam: fightData.blueTeam.id,
|
||||
redTeam: fightData.redTeam.id,
|
||||
@@ -58,7 +52,7 @@
|
||||
<DialogTitle>Fight bearbeiten</DialogTitle>
|
||||
<DialogDescription>Hier kannst du die Daten des Kampfes bearbeiten.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<FightEdit {fight} {teams} bind:groups {event} onSave={handleSave}>
|
||||
<FightEdit {fight} {data} onSave={handleSave}>
|
||||
{#snippet actions(dirty, submit)}
|
||||
<DialogFooter>
|
||||
<Button disabled={!dirty} onclick={submit}>Speichern</Button>
|
||||
@@ -78,7 +72,7 @@
|
||||
<DialogTitle>Fight duplizieren</DialogTitle>
|
||||
<DialogDescription>Hier kannst du die Daten des duplizierten Fights ändern</DialogDescription>
|
||||
</DialogHeader>
|
||||
<FightEdit {fight} {teams} bind:groups {event} onSave={handlyCopy}>
|
||||
<FightEdit {fight} {data} onSave={handlyCopy}>
|
||||
{#snippet actions(dirty, submit)}
|
||||
<DialogFooter>
|
||||
<Button onclick={submit}>Speichern</Button>
|
||||
|
||||
@@ -1,21 +1,52 @@
|
||||
import type { ResponseUser } from "@components/repo/event";
|
||||
import type { EventFight, ExtendedEvent, ResponseGroups, ResponseRelation, SWEvent } from "@components/types/event";
|
||||
import type { Team } from "@components/types/team";
|
||||
import { derived } from "svelte/store";
|
||||
|
||||
export class EventModel {
|
||||
public event: SWEvent = $state({} as SWEvent);
|
||||
public teams: Array<Team> = $state([]);
|
||||
public groups: Array<ResponseGroups> = $state([]);
|
||||
public fights: Array<EventFight> = $state([]);
|
||||
public _fights: Array<EventFight> = $state([]);
|
||||
public referees: Array<ResponseUser> = $state([]);
|
||||
public relations: Array<ResponseRelation> = $state([]);
|
||||
|
||||
public fights = $derived(this.remapFights(this._fights, this.relations));
|
||||
|
||||
constructor(data: ExtendedEvent) {
|
||||
this.event = data.event;
|
||||
this.relations = data.relations;
|
||||
this.teams = data.teams;
|
||||
this.groups = data.groups;
|
||||
this.fights = data.fights;
|
||||
this._fights = data.fights;
|
||||
this.referees = data.referees;
|
||||
this.relations = data.relations;
|
||||
}
|
||||
|
||||
private remapFights(v: Array<EventFight>, rels: Array<ResponseRelation>) {
|
||||
return v.map((fight) => {
|
||||
let f = JSON.parse(JSON.stringify(fight)) as EventFight;
|
||||
let relations = rels.filter((relation) => relation.fight === f.id);
|
||||
|
||||
relations.forEach((relation) => {
|
||||
let str = "";
|
||||
if (relation.type === "FIGHT") {
|
||||
str += `${relation.fromPlace === 0 ? "Gewinner" : "Verlierer"} von ${relation.fromFight?.blueTeam.name} vs ${relation.fromFight?.redTeam.name} (${new Date(
|
||||
relation.fromFight?.start ?? 0
|
||||
).toLocaleTimeString("de-DE", {
|
||||
timeStyle: "short",
|
||||
})})`;
|
||||
} else {
|
||||
str += `${relation.fromPlace + 1}. Platz von ${relation.fromGroup?.name}`;
|
||||
}
|
||||
|
||||
if (relation.team === "BLUE") {
|
||||
f.blueTeam.name += ` (${str})`;
|
||||
} else {
|
||||
f.redTeam.name += ` (${str})`;
|
||||
}
|
||||
});
|
||||
|
||||
return f;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user