Refactor EventFight handling to include team relation names and update type definitions
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
@ -258,10 +258,10 @@
|
|||||||
{group?.name ?? "Keine Gruppe"}
|
{group?.name ?? "Keine Gruppe"}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell class="text-right">
|
<TableCell class="text-right">
|
||||||
<Button variant="ghost" size="icon" onclick={() => openGroupEditDialog(group)}>
|
<Button variant="ghost" size="icon" onclick={() => openGroupEditDialog(group!)}>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="icon" onclick={() => openGroupResultsDialog(group)}>
|
<Button variant="ghost" size="icon" onclick={() => openGroupResultsDialog(group!)}>
|
||||||
<GroupIcon />
|
<GroupIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
|
|||||||
@ -20,9 +20,9 @@
|
|||||||
import { Checkbox } from "@components/ui/checkbox";
|
import { Checkbox } from "@components/ui/checkbox";
|
||||||
import { renderComponent } from "@components/ui/data-table";
|
import { renderComponent } from "@components/ui/data-table";
|
||||||
import type { ColumnDef } from "@tanstack/table-core";
|
import type { ColumnDef } from "@tanstack/table-core";
|
||||||
import type { EventFight } from "@type/event.ts";
|
import type { EventFightModel } from "./eventmodel.svelte";
|
||||||
|
|
||||||
export const columns: ColumnDef<EventFight> = [
|
export const columns: ColumnDef<EventFightModel>[] = [
|
||||||
{
|
{
|
||||||
id: "auswahl",
|
id: "auswahl",
|
||||||
header: ({ table }) => {
|
header: ({ table }) => {
|
||||||
@ -32,7 +32,7 @@ export const columns: ColumnDef<EventFight> = [
|
|||||||
onCheckedChange: () => {
|
onCheckedChange: () => {
|
||||||
if (!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()) {
|
if (!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const rows = table.getRowModel().rows.filter((row) => new Date(row.original.date) > now);
|
const rows = table.getRowModel().rows.filter((row) => new Date(row.original.start) > now);
|
||||||
|
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
rows.forEach((row) => {
|
rows.forEach((row) => {
|
||||||
@ -57,7 +57,7 @@ export const columns: ColumnDef<EventFight> = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (r) => r.blueTeam.name + " vs " + r.redTeam.name,
|
accessorFn: (r) => r.blueTeam.nameWithRelation + " vs " + r.redTeam.nameWithRelation,
|
||||||
id: "begegnung",
|
id: "begegnung",
|
||||||
header: "Begegnung",
|
header: "Begegnung",
|
||||||
},
|
},
|
||||||
|
|||||||
@ -25,28 +25,44 @@ export class EventModel {
|
|||||||
private remapFights(v: Array<EventFight>, rels: Array<ResponseRelation>) {
|
private remapFights(v: Array<EventFight>, rels: Array<ResponseRelation>) {
|
||||||
return v.map((fight) => {
|
return v.map((fight) => {
|
||||||
let f = JSON.parse(JSON.stringify(fight)) as EventFight;
|
let f = JSON.parse(JSON.stringify(fight)) as EventFight;
|
||||||
|
|
||||||
|
let blueTeamRelation = f.blueTeam.name;
|
||||||
|
let redTeamRelation = f.redTeam.name;
|
||||||
|
|
||||||
let relations = rels.filter((relation) => relation.fight === f.id);
|
let relations = rels.filter((relation) => relation.fight === f.id);
|
||||||
|
|
||||||
relations.forEach((relation) => {
|
relations.forEach((relation) => {
|
||||||
let str = "";
|
let str = "";
|
||||||
if (relation.type === "FIGHT") {
|
if (relation.type === "FIGHT") {
|
||||||
str += `${relation.fromPlace === 0 ? "Gewinner" : "Verlierer"} von ${relation.fromFight?.blueTeam.name} vs ${relation.fromFight?.redTeam.name} (${new Date(
|
str = `${relation.fromPlace === 0 ? "Gewinner" : "Verlierer"} von ${relation.fromFight?.blueTeam.name} vs ${relation.fromFight?.redTeam.name} (${new Date(
|
||||||
relation.fromFight?.start ?? 0
|
relation.fromFight?.start ?? 0
|
||||||
).toLocaleTimeString("de-DE", {
|
).toLocaleTimeString("de-DE", {
|
||||||
timeStyle: "short",
|
timeStyle: "short",
|
||||||
})})`;
|
})})`;
|
||||||
} else {
|
} else {
|
||||||
str += `${relation.fromPlace + 1}. Platz von ${relation.fromGroup?.name}`;
|
str = `${relation.fromPlace + 1}. Platz von ${relation.fromGroup?.name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relation.team === "BLUE") {
|
if (relation.team === "BLUE") {
|
||||||
f.blueTeam.name += ` (${str})`;
|
blueTeamRelation = str;
|
||||||
} else {
|
} else {
|
||||||
f.redTeam.name += ` (${str})`;
|
redTeamRelation = str;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return f;
|
return {
|
||||||
|
...f,
|
||||||
|
blueTeam: {
|
||||||
|
...f.blueTeam,
|
||||||
|
nameWithRelation: `${f.blueTeam.name} (${blueTeamRelation})`,
|
||||||
|
},
|
||||||
|
redTeam: {
|
||||||
|
...f.redTeam,
|
||||||
|
nameWithRelation: `${f.redTeam.name} (${redTeamRelation})`,
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EventFightModel = (typeof EventModel.prototype.fights)[number];
|
||||||
|
|||||||
Reference in New Issue
Block a user