generated from schreifuchs/wails-template
added matches
This commit is contained in:
@ -43,9 +43,7 @@
|
||||
<TableBodyCell>
|
||||
{t.Game.Name}
|
||||
</TableBodyCell>
|
||||
<TableBodyCell>
|
||||
{t.WinnierParticipant.Name}
|
||||
</TableBodyCell>
|
||||
<TableBodyCell>{t.WinnerParticipant.Name}</TableBodyCell>
|
||||
|
||||
<TableBodyCell>
|
||||
<Link class="text-primary-500 underline" to={`/tournament/${t.ID}`}
|
||||
@ -56,7 +54,6 @@
|
||||
{/each}
|
||||
</TableBody>
|
||||
<div class="flex-row justify-evenly p-5">
|
||||
<Button>View</Button>
|
||||
<Button on:click={(_) => (newThing = true)}>New Tournament</Button>
|
||||
</div>
|
||||
<Modal bind:open={newThing}>
|
||||
|
@ -1,24 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import {
|
||||
CreateStage,
|
||||
GetMatches,
|
||||
GetTournament,
|
||||
SaveMatch,
|
||||
SaveTournament,
|
||||
StartTournament,
|
||||
} from "../../wailsjs/go/main/App";
|
||||
import { model } from "../../wailsjs/go/models";
|
||||
import { Button, TabItem, Tabs } from "flowbite-svelte";
|
||||
import {
|
||||
Button,
|
||||
TabItem,
|
||||
Table,
|
||||
TableBody,
|
||||
TableBodyCell,
|
||||
TableBodyRow,
|
||||
TableHead,
|
||||
TableHeadCell,
|
||||
Tabs,
|
||||
Tooltip,
|
||||
} from "flowbite-svelte";
|
||||
|
||||
let { tournamentID }: { tournamentID: number } = $props();
|
||||
let tournament: model.Tournament = $state(new model.Tournament());
|
||||
let matches: model.Match[][] = $state([]);
|
||||
|
||||
function saveMatch(m: model.Match): Promise<void> {
|
||||
if (matches[matches.length - 1].length == 1) {
|
||||
tournament.WinnerParticipantID = m.WinnerParticipantID;
|
||||
SaveTournament(tournament).then(update);
|
||||
}
|
||||
return SaveMatch(m);
|
||||
}
|
||||
|
||||
function update() {
|
||||
GetTournament(tournamentID).then((t) => {
|
||||
console.log(t);
|
||||
tournament = t;
|
||||
});
|
||||
|
||||
GetMatches(tournamentID).then((ms) => (matches = ms));
|
||||
GetMatches(tournamentID).then((ms) => {
|
||||
console.log("ms:", ms);
|
||||
|
||||
matches = ms;
|
||||
});
|
||||
}
|
||||
$effect(update);
|
||||
onMount(update);
|
||||
@ -26,14 +51,67 @@
|
||||
|
||||
{#if tournament.TournamentState == 0}
|
||||
<Button
|
||||
disabled={tournament.Participants.length < tournament.Size}
|
||||
onclick={() => {
|
||||
StartTournament(tournament).then(update);
|
||||
}}>Start</Button
|
||||
>
|
||||
{#if tournament.Participants.length < tournament.Size}
|
||||
<Tooltip>Tournament must be filled</Tooltip>
|
||||
{/if}
|
||||
{:else}
|
||||
<Tabs>
|
||||
{#each matches as ms, i}
|
||||
<TabItem title={`Stage: ${i}`}></TabItem>
|
||||
<TabItem open={i + 1 == matches.length} title={`Stage: ${i + 1}`}>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableHeadCell>Participant1</TableHeadCell>
|
||||
<TableHeadCell>Participant2</TableHeadCell>
|
||||
<TableHeadCell>Winner</TableHeadCell>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{#each ms as m}
|
||||
<TableBodyRow>
|
||||
<TableBodyCell>
|
||||
{m.Participant1.Name}
|
||||
</TableBodyCell>
|
||||
<TableBodyCell>
|
||||
{m.Participant2.Name}
|
||||
</TableBodyCell>
|
||||
<TableBodyCell>
|
||||
{#if m.WinnerParticipant.Name == ""}
|
||||
<Button
|
||||
class="m-1"
|
||||
onclick={() => {
|
||||
m.WinnerParticipant = m.Participant1;
|
||||
saveMatch(m).then(update);
|
||||
}}
|
||||
>
|
||||
{m.Participant1.Name}
|
||||
</Button>
|
||||
<Button
|
||||
onclick={() => {
|
||||
m.WinnerParticipantID = m.Participant2ID;
|
||||
saveMatch(m).then(update);
|
||||
}}
|
||||
>
|
||||
{m.Participant2.Name}
|
||||
</Button>
|
||||
{:else}
|
||||
{m.WinnerParticipant.Name}
|
||||
{/if}
|
||||
</TableBodyCell>
|
||||
</TableBodyRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TabItem>
|
||||
{/each}
|
||||
{#if matches.length > 0 && matches[matches.length - 1].length > 1 && matches[matches.length - 1].reduce( (acc, m) => {
|
||||
return acc && m.WinnerParticipant.Name != "";
|
||||
}, )}
|
||||
<Button onclick={() => CreateStage(tournamentID).then(update)}>new</Button
|
||||
>
|
||||
{/if}
|
||||
</Tabs>
|
||||
{/if}
|
||||
|
@ -26,12 +26,11 @@
|
||||
</script>
|
||||
|
||||
<form onsubmit={submit}>
|
||||
<div>
|
||||
<div class="m-5">
|
||||
<Label>Title</Label>
|
||||
<Input type="text" bind:value={tournament.Title} />
|
||||
</div>
|
||||
<div>
|
||||
e
|
||||
<div class="m-5">
|
||||
<Label>Game</Label>
|
||||
<Select
|
||||
items={games.map((g) => {
|
||||
@ -40,9 +39,11 @@
|
||||
bind:value={tournament.GameID}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div class="m-5">
|
||||
<Label>Size</Label>
|
||||
<Input type="number" step="1" min="1" bind:value={tournament.Size} />
|
||||
</div>
|
||||
<Button type="submit">Save</Button>
|
||||
<div class="m-5">
|
||||
<Button type="submit">Save</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
4
frontend/wailsjs/go/main/App.d.ts
vendored
4
frontend/wailsjs/go/main/App.d.ts
vendored
@ -2,6 +2,8 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {model} from '../models';
|
||||
|
||||
export function CreateStage(arg1:number):Promise<void>;
|
||||
|
||||
export function DeleteParticipat(arg1:model.Participant):Promise<void>;
|
||||
|
||||
export function ExportTournament(arg1:model.Tournament):Promise<void>;
|
||||
@ -20,6 +22,8 @@ export function GetTournaments():Promise<Array<model.Tournament>>;
|
||||
|
||||
export function RemoveParticipantFromTournament(arg1:model.Participant,arg2:model.Tournament):Promise<void>;
|
||||
|
||||
export function SaveMatch(arg1:model.Match):Promise<void>;
|
||||
|
||||
export function SaveParticipant(arg1:model.Participant):Promise<void>;
|
||||
|
||||
export function SaveTournament(arg1:model.Tournament):Promise<void>;
|
||||
|
@ -2,6 +2,10 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function CreateStage(arg1) {
|
||||
return window['go']['main']['App']['CreateStage'](arg1);
|
||||
}
|
||||
|
||||
export function DeleteParticipat(arg1) {
|
||||
return window['go']['main']['App']['DeleteParticipat'](arg1);
|
||||
}
|
||||
@ -38,6 +42,10 @@ export function RemoveParticipantFromTournament(arg1, arg2) {
|
||||
return window['go']['main']['App']['RemoveParticipantFromTournament'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function SaveMatch(arg1) {
|
||||
return window['go']['main']['App']['SaveMatch'](arg1);
|
||||
}
|
||||
|
||||
export function SaveParticipant(arg1) {
|
||||
return window['go']['main']['App']['SaveParticipant'](arg1);
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ export namespace model {
|
||||
Game: Game;
|
||||
Size: number;
|
||||
TournamentState: number;
|
||||
WinnierParticipantID: number;
|
||||
WinnierParticipant: Participant;
|
||||
WinnerParticipantID: number;
|
||||
WinnerParticipant: Participant;
|
||||
Participants: Participant[];
|
||||
Matches: Match[];
|
||||
|
||||
@ -74,8 +74,8 @@ export namespace model {
|
||||
this.Game = this.convertValues(source["Game"], Game);
|
||||
this.Size = source["Size"];
|
||||
this.TournamentState = source["TournamentState"];
|
||||
this.WinnierParticipantID = source["WinnierParticipantID"];
|
||||
this.WinnierParticipant = this.convertValues(source["WinnierParticipant"], Participant);
|
||||
this.WinnerParticipantID = source["WinnerParticipantID"];
|
||||
this.WinnerParticipant = this.convertValues(source["WinnerParticipant"], Participant);
|
||||
this.Participants = this.convertValues(source["Participants"], Participant);
|
||||
this.Matches = this.convertValues(source["Matches"], Match);
|
||||
}
|
||||
@ -160,8 +160,8 @@ export namespace model {
|
||||
Participant1: Participant;
|
||||
Participant2ID: number;
|
||||
Participant2: Participant;
|
||||
WinnierParticipantID: number;
|
||||
WinnierParticipant: Participant;
|
||||
WinnerParticipantID: number;
|
||||
WinnerParticipant: Participant;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Match(source);
|
||||
@ -180,8 +180,8 @@ export namespace model {
|
||||
this.Participant1 = this.convertValues(source["Participant1"], Participant);
|
||||
this.Participant2ID = source["Participant2ID"];
|
||||
this.Participant2 = this.convertValues(source["Participant2"], Participant);
|
||||
this.WinnierParticipantID = source["WinnierParticipantID"];
|
||||
this.WinnierParticipant = this.convertValues(source["WinnierParticipant"], Participant);
|
||||
this.WinnerParticipantID = source["WinnerParticipantID"];
|
||||
this.WinnerParticipant = this.convertValues(source["WinnerParticipant"], Participant);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
|
Reference in New Issue
Block a user