generated from schreifuchs/wails-template
start on matches
This commit is contained in:
@ -1,17 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { GetTournament, SaveTournament } from "../../wailsjs/go/main/App";
|
||||
import {
|
||||
GetMatches,
|
||||
GetTournament,
|
||||
StartTournament,
|
||||
} from "../../wailsjs/go/main/App";
|
||||
import { model } from "../../wailsjs/go/models";
|
||||
import { Button } from "flowbite-svelte";
|
||||
import { Button, TabItem, Tabs } from "flowbite-svelte";
|
||||
|
||||
let { tournamentID }: { tournamentID: number } = $props();
|
||||
|
||||
let tournament: model.Tournament = $state(new model.Tournament());
|
||||
let matches: model.Match[][] = $state([]);
|
||||
|
||||
function update() {
|
||||
GetTournament(tournamentID).then((t) => {
|
||||
console.log(t);
|
||||
tournament = t;
|
||||
});
|
||||
|
||||
GetMatches(tournamentID).then((ms) => (matches = ms));
|
||||
}
|
||||
$effect(update);
|
||||
onMount(update);
|
||||
@ -20,8 +27,13 @@
|
||||
{#if tournament.TournamentState == 0}
|
||||
<Button
|
||||
onclick={() => {
|
||||
tournament.TournamentState++;
|
||||
SaveTournament(tournament).then(update);
|
||||
StartTournament(tournament).then(update);
|
||||
}}>Start</Button
|
||||
>
|
||||
{:else}{/if}
|
||||
{:else}
|
||||
<Tabs>
|
||||
{#each matches as ms, i}
|
||||
<TabItem title={`Stage: ${i}`}></TabItem>
|
||||
{/each}
|
||||
</Tabs>
|
||||
{/if}
|
||||
|
@ -1,8 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from "svelte/legacy";
|
||||
|
||||
import { Link, navigate } from "svelte-routing";
|
||||
import { GetTournament } from "../../wailsjs/go/main/App";
|
||||
import { GetTournament, ExportTournament } from "../../wailsjs/go/main/App";
|
||||
import { model } from "../../wailsjs/go/models";
|
||||
import { onMount } from "svelte";
|
||||
import { Button, Heading, TabItem, Tabs } from "flowbite-svelte";
|
||||
@ -22,10 +20,7 @@
|
||||
tournament = t;
|
||||
});
|
||||
}
|
||||
run(() => {
|
||||
id = id;
|
||||
update();
|
||||
});
|
||||
$effect(update);
|
||||
onMount(update);
|
||||
</script>
|
||||
|
||||
@ -33,7 +28,7 @@
|
||||
{#if tournament}
|
||||
<section class="grid grid-cols-2 p-5">
|
||||
<Heading>{tournament.Title}</Heading>
|
||||
<Button on:click={() => navigate("/", { replace: true })}>Export</Button>
|
||||
<Button on:click={() => ExportTournament(tournament)}>Export</Button>
|
||||
</section>
|
||||
<Tabs>
|
||||
<TabItem open title="Participants">
|
||||
|
6
frontend/wailsjs/go/main/App.d.ts
vendored
6
frontend/wailsjs/go/main/App.d.ts
vendored
@ -4,10 +4,14 @@ import {model} from '../models';
|
||||
|
||||
export function DeleteParticipat(arg1:model.Participant):Promise<void>;
|
||||
|
||||
export function ExportTournament(arg1:model.Tournament):Promise<void>;
|
||||
|
||||
export function FillRandom(arg1:model.Tournament):Promise<void>;
|
||||
|
||||
export function GetGames():Promise<Array<model.Game>>;
|
||||
|
||||
export function GetMatches(arg1:number):Promise<Array<any>>;
|
||||
|
||||
export function GetParticipants():Promise<Array<model.Participant>>;
|
||||
|
||||
export function GetTournament(arg1:number):Promise<model.Tournament>;
|
||||
@ -19,3 +23,5 @@ export function RemoveParticipantFromTournament(arg1:model.Participant,arg2:mode
|
||||
export function SaveParticipant(arg1:model.Participant):Promise<void>;
|
||||
|
||||
export function SaveTournament(arg1:model.Tournament):Promise<void>;
|
||||
|
||||
export function StartTournament(arg1:model.Tournament):Promise<void>;
|
||||
|
@ -6,6 +6,10 @@ export function DeleteParticipat(arg1) {
|
||||
return window['go']['main']['App']['DeleteParticipat'](arg1);
|
||||
}
|
||||
|
||||
export function ExportTournament(arg1) {
|
||||
return window['go']['main']['App']['ExportTournament'](arg1);
|
||||
}
|
||||
|
||||
export function FillRandom(arg1) {
|
||||
return window['go']['main']['App']['FillRandom'](arg1);
|
||||
}
|
||||
@ -14,6 +18,10 @@ export function GetGames() {
|
||||
return window['go']['main']['App']['GetGames']();
|
||||
}
|
||||
|
||||
export function GetMatches(arg1) {
|
||||
return window['go']['main']['App']['GetMatches'](arg1);
|
||||
}
|
||||
|
||||
export function GetParticipants() {
|
||||
return window['go']['main']['App']['GetParticipants']();
|
||||
}
|
||||
@ -37,3 +45,7 @@ export function SaveParticipant(arg1) {
|
||||
export function SaveTournament(arg1) {
|
||||
return window['go']['main']['App']['SaveTournament'](arg1);
|
||||
}
|
||||
|
||||
export function StartTournament(arg1) {
|
||||
return window['go']['main']['App']['StartTournament'](arg1);
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ export namespace model {
|
||||
WinnierParticipantID: number;
|
||||
WinnierParticipant: Participant;
|
||||
Participants: Participant[];
|
||||
Matches: Match[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Tournament(source);
|
||||
@ -76,6 +77,7 @@ export namespace model {
|
||||
this.WinnierParticipantID = source["WinnierParticipantID"];
|
||||
this.WinnierParticipant = this.convertValues(source["WinnierParticipant"], Participant);
|
||||
this.Participants = this.convertValues(source["Participants"], Participant);
|
||||
this.Matches = this.convertValues(source["Matches"], Match);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
@ -143,6 +145,64 @@ export namespace model {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export class Match {
|
||||
ID: number;
|
||||
// Go type: time
|
||||
CreatedAt: any;
|
||||
// Go type: time
|
||||
UpdatedAt: any;
|
||||
// Go type: gorm
|
||||
DeletedAt: any;
|
||||
TournamentID: number;
|
||||
Stage: number;
|
||||
Order: number;
|
||||
Participant1ID: number;
|
||||
Participant1: Participant;
|
||||
Participant2ID: number;
|
||||
Participant2: Participant;
|
||||
WinnierParticipantID: number;
|
||||
WinnierParticipant: Participant;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Match(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.ID = source["ID"];
|
||||
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
|
||||
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
|
||||
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
|
||||
this.TournamentID = source["TournamentID"];
|
||||
this.Stage = source["Stage"];
|
||||
this.Order = source["Order"];
|
||||
this.Participant1ID = source["Participant1ID"];
|
||||
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);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user