Skip to content
Snippets Groups Projects
Commit feb06530 authored by ForkBench's avatar ForkBench
Browse files

Now Registrations are based on stage, not in competition

parent 9860067d
Branches
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ func (c *Competition) InitCompetition() bool { ...@@ -43,6 +43,7 @@ func (c *Competition) InitCompetition() bool {
var seedingStage = CreateSeedingStage(0, 300, 300) var seedingStage = CreateSeedingStage(0, 300, 300)
// TODO: Max player number should be dynamic // TODO: Max player number should be dynamic
seedingStage.Register()
c.AddStage(seedingStage) c.AddStage(seedingStage)
c.CompetitionCurrentStageID = 0 c.CompetitionCurrentStageID = 0
......
...@@ -4,6 +4,7 @@ package services ...@@ -4,6 +4,7 @@ package services
type Seeding struct { type Seeding struct {
SeedingPosition uint16 SeedingPosition uint16
SeedingPlayer *Player SeedingPlayer *Player
SeedingPlayerPresent bool
} }
type SeedingStage struct { type SeedingStage struct {
......
...@@ -74,7 +74,7 @@ func (s *Session) AddPlayerToCompetition(competitionID uint8, player *Player) bo ...@@ -74,7 +74,7 @@ func (s *Session) AddPlayerToCompetition(competitionID uint8, player *Player) bo
func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player *Player) bool { func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player *Player) bool {
competition := s.GetCompetition(competitionID) competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" { if competition == nil {
return false return false
} }
...@@ -83,7 +83,7 @@ func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player *Playe ...@@ -83,7 +83,7 @@ func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player *Playe
func (s *Session) GetAllPlayersFromCompetition(competitionID uint8) []*Player { func (s *Session) GetAllPlayersFromCompetition(competitionID uint8) []*Player {
competition := s.GetCompetition(competitionID) competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" { if competition == nil {
return []*Player{} return []*Player{}
} }
...@@ -96,16 +96,18 @@ func (s *Session) GetAllPlayersFromCompetition(competitionID uint8) []*Player { ...@@ -96,16 +96,18 @@ func (s *Session) GetAllPlayersFromCompetition(competitionID uint8) []*Player {
func (s *Session) UpdateCompetitionPlayer(competitionID uint8, player *Player) bool { func (s *Session) UpdateCompetitionPlayer(competitionID uint8, player *Player) bool {
competition := s.GetCompetition(competitionID) competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" { if competition == nil {
return false return false
} }
// TODO: Check if player is in competition
return competition.UpdatePlayer(player) return competition.UpdatePlayer(player)
} }
func (s *Session) GetStageKind(competitionID uint8, stageID uint8) StageKind { func (s *Session) GetStageKind(competitionID uint8, stageID uint8) StageKind {
competition := s.GetCompetition(competitionID) competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" { if competition == nil {
return UNKNOWN return UNKNOWN
} }
...@@ -116,3 +118,45 @@ func (s *Session) GetStageKind(competitionID uint8, stageID uint8) StageKind { ...@@ -116,3 +118,45 @@ func (s *Session) GetStageKind(competitionID uint8, stageID uint8) StageKind {
return (*stage).GetKind() return (*stage).GetKind()
} }
func (s *Session) AddPlayerToCompetitionStage(competitionID uint8, stageID uint8, player *Player) bool {
competition := s.GetCompetition(competitionID)
if competition == nil {
return false
}
stage := competition.GetStage(stageID)
if stage == nil {
return false
}
return s.AddPlayerToCompetition(competitionID, player) && (*stage).AddPlayer(player)
}
func (s *Session) RemovePlayerFromCompetitionStage(competitionID uint8, stageID uint8, player *Player) bool {
competition := s.GetCompetition(competitionID)
if competition == nil {
return false
}
stage := competition.GetStage(stageID)
if stage == nil {
return false
}
return (*stage).RemovePlayer(player)
}
func (s *Session) GetPlayersFromCompetitionStage(competitionID uint8, stageID uint8) []*Player {
competition := s.GetCompetition(competitionID)
if competition == nil {
return []*Player{}
}
stage := competition.GetStage(stageID)
if stage == nil {
return []*Player{}
}
return (*stage).GetPlayers()
}
...@@ -24,6 +24,11 @@ export function AddPlayerToCompetition(competitionID: number, player: $models.Pl ...@@ -24,6 +24,11 @@ export function AddPlayerToCompetition(competitionID: number, player: $models.Pl
return $resultPromise; return $resultPromise;
} }
export function AddPlayerToCompetitionStage(competitionID: number, stageID: number, player: $models.Player | null): Promise<boolean> & { cancel(): void } {
let $resultPromise = $Call.ByID(2910612480, competitionID, stageID, player) as any;
return $resultPromise;
}
export function GetAllPlayersFromCompetition(competitionID: number): Promise<($models.Player | null)[]> & { cancel(): void } { export function GetAllPlayersFromCompetition(competitionID: number): Promise<($models.Player | null)[]> & { cancel(): void } {
let $resultPromise = $Call.ByID(3547487506, competitionID) as any; let $resultPromise = $Call.ByID(3547487506, competitionID) as any;
let $typingPromise = $resultPromise.then(($result) => { let $typingPromise = $resultPromise.then(($result) => {
...@@ -51,6 +56,15 @@ export function GetCompetitions(): Promise<$models.Competition[]> & { cancel(): ...@@ -51,6 +56,15 @@ export function GetCompetitions(): Promise<$models.Competition[]> & { cancel():
return $typingPromise; return $typingPromise;
} }
export function GetPlayersFromCompetitionStage(competitionID: number, stageID: number): Promise<($models.Player | null)[]> & { cancel(): void } {
let $resultPromise = $Call.ByID(145932197, competitionID, stageID) as any;
let $typingPromise = $resultPromise.then(($result) => {
return $$createType2($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
return $typingPromise;
}
export function GetStageKind(competitionID: number, stageID: number): Promise<$models.StageKind> & { cancel(): void } { export function GetStageKind(competitionID: number, stageID: number): Promise<$models.StageKind> & { cancel(): void } {
let $resultPromise = $Call.ByID(3392771308, competitionID, stageID) as any; let $resultPromise = $Call.ByID(3392771308, competitionID, stageID) as any;
return $resultPromise; return $resultPromise;
...@@ -66,6 +80,11 @@ export function RemovePlayerFromCompetition(competitionID: number, player: $mode ...@@ -66,6 +80,11 @@ export function RemovePlayerFromCompetition(competitionID: number, player: $mode
return $resultPromise; return $resultPromise;
} }
export function RemovePlayerFromCompetitionStage(competitionID: number, stageID: number, player: $models.Player | null): Promise<boolean> & { cancel(): void } {
let $resultPromise = $Call.ByID(4015938334, competitionID, stageID, player) as any;
return $resultPromise;
}
export function UpdateCompetitionPlayer(competitionID: number, player: $models.Player | null): Promise<boolean> & { cancel(): void } { export function UpdateCompetitionPlayer(competitionID: number, player: $models.Player | null): Promise<boolean> & { cancel(): void } {
let $resultPromise = $Call.ByID(3540307881, competitionID, player) as any; let $resultPromise = $Call.ByID(3540307881, competitionID, player) as any;
return $resultPromise; return $resultPromise;
......
<script lang="ts"> <script lang="ts">
import Registrations from "./components/Registrations/Registrations.svelte"; import Registrations from "./components/Registrations/Registrations.svelte";
import * as Models from "./../bindings/changeme/astro/services/models"; import * as Models from "./../bindings/changeme/astro/services/models";
import { SelectedCompetition } from "./store"; import { SelectedCompetition, CurrentStage } from "./store";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { GetStageKind } from "./../bindings/changeme/astro/services/session"; import { GetStageKind } from "./../bindings/changeme/astro/services/session";
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
competition.CompetitionStages[ competition.CompetitionStages[
`${competition.CompetitionCurrentStageID}` `${competition.CompetitionCurrentStageID}`
]; ];
CurrentStage.set(currentStage);
GetStageKind( GetStageKind(
competition.CompetitionID, competition.CompetitionID,
currentStage.StageID currentStage.StageID
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import * as Models from "../../../bindings/changeme/astro/services/models"; import * as Models from "../../../bindings/changeme/astro/services/models";
import * as Session from "../../../bindings/changeme/astro/services/session"; import * as Session from "../../../bindings/changeme/astro/services/session";
import { SelectedCompetition } from "../../store"; import { SelectedCompetition, CurrentStage } from "../../store";
import { GenerateRandomPlayer } from "../../../bindings/changeme/astro/services/player"; import { GenerateRandomPlayer } from "../../../bindings/changeme/astro/services/player";
import swal from "sweetalert"; import swal from "sweetalert";
import { getNationFlag, getNationFlatAlt } from "../../Util"; import { getNationFlag, getNationFlatAlt } from "../../Util";
...@@ -17,12 +17,18 @@ ...@@ -17,12 +17,18 @@
let players: (Models.Player | null)[] = []; let players: (Models.Player | null)[] = [];
let filteredPlayers: (Models.Player | null)[] = []; let filteredPlayers: (Models.Player | null)[] = [];
let competition: Models.Competition | undefined; let competition: Models.Competition | undefined;
let stage: Models.Stage | undefined;
let sortBy = { key: "", asc: true }; let sortBy = { key: "", asc: true };
let searchTerms = ""; let searchTerms = "";
// Listen to any change in the selected competition // Listen to any change in the selected competition
SelectedCompetition.subscribe((value) => { SelectedCompetition.subscribe((value) => {
competition = value; competition = value;
});
// Listen to any change in the current stage
CurrentStage.subscribe((value) => {
stage = value;
loadPlayers(); loadPlayers();
}); });
...@@ -32,11 +38,12 @@ ...@@ -32,11 +38,12 @@
return; return;
} }
Session.GetAllPlayersFromCompetition(competition.CompetitionID).then( Session.GetPlayersFromCompetitionStage(
(result) => { competition.CompetitionID,
stage?.StageID
).then((result) => {
players = result; players = result;
} });
);
} }
// When the page is loaded, load the players, and set the default sorting // When the page is loaded, load the players, and set the default sorting
...@@ -61,7 +68,11 @@ ...@@ -61,7 +68,11 @@
case "PlayerLastname": case "PlayerLastname":
return player.PlayerLastname; return player.PlayerLastname;
case "PlayerClub": case "PlayerClub":
return player.PlayerClub; return player.PlayerClub?.club_name;
case "PlayerRegion":
return player.PlayerRegion?.region_name;
case "PlayerCountry":
return player.PlayerNation?.nation_name;
default: default:
return ""; return "";
} }
...@@ -74,6 +85,10 @@ ...@@ -74,6 +85,10 @@
if (aValue === null || bValue === null) { if (aValue === null || bValue === null) {
return 0; return 0;
} }
if (aValue === undefined || bValue === undefined) {
return 0;
}
if (aValue < bValue) { if (aValue < bValue) {
return sortBy.asc ? -1 : 1; return sortBy.asc ? -1 : 1;
} }
...@@ -119,6 +134,13 @@ ...@@ -119,6 +134,13 @@
<!-- <!--
The following code is used to sort the players by the column clicked. The following code is used to sort the players by the column clicked.
--> -->
<th
on:click={() => {
sortBy = { key: "PlayerPresent", asc: !sortBy.asc };
}}
>
Present
</th>
<th <th
on:click={() => { on:click={() => {
sortBy = { sortBy = {
...@@ -169,6 +191,9 @@ ...@@ -169,6 +191,9 @@
class:silver={player.PlayerInitialRank == 2} class:silver={player.PlayerInitialRank == 2}
class:bronze={player.PlayerInitialRank == 3} class:bronze={player.PlayerInitialRank == 3}
> >
<td>
<!-- TODO: input checkbox -->
</td>
<td <td
on:dblclick={async () => { on:dblclick={async () => {
// Show a prompt to the user to change the rank // Show a prompt to the user to change the rank
...@@ -209,6 +234,7 @@ ...@@ -209,6 +234,7 @@
).then(() => { ).then(() => {
loadPlayers(); loadPlayers();
}); });
// TODO: Backend wise, change it
} }
}}>{player.PlayerInitialRank}</td }}>{player.PlayerInitialRank}</td
> >
...@@ -238,6 +264,7 @@ ...@@ -238,6 +264,7 @@
).then(() => { ).then(() => {
loadPlayers(); loadPlayers();
}); });
// TODO: Backend wise, change it
} }
}} }}
>{player.PlayerLastname.toLocaleUpperCase()}</td >{player.PlayerLastname.toLocaleUpperCase()}</td
...@@ -268,6 +295,7 @@ ...@@ -268,6 +295,7 @@
).then(() => { ).then(() => {
loadPlayers(); loadPlayers();
}); });
// TODO: Backend wise, change it
} }
}}>{player.PlayerFirstname}</td }}>{player.PlayerFirstname}</td
> >
...@@ -305,8 +333,9 @@ ...@@ -305,8 +333,9 @@
// Add the player to the competition // Add the player to the competition
if (competition != undefined) if (competition != undefined)
await Session.AddPlayerToCompetition( await Session.AddPlayerToCompetitionStage(
competition.CompetitionID, competition.CompetitionID,
stage?.SeedingStageID,
player player
).then(() => { ).then(() => {
loadPlayers(); loadPlayers();
......
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type { Competition } from '../bindings/changeme/astro/services/models'; import type { Stage } from '../bindings/changeme/astro/services/models';
import { type Competition } from '../bindings/changeme/astro/services/models';
export const SelectedCompetition = writable<Competition | undefined>(undefined); export const SelectedCompetition = writable<Competition | undefined>(undefined);
export const CurrentStage = writable<Stage | undefined>(undefined);
export const Competitions = writable<(Competition | undefined)[]>([]); export const Competitions = writable<(Competition | undefined)[]>([]);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment