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

Adding flags to registrations

parent 59e82294
No related branches found
No related tags found
No related merge requests found
import type { Nation } from "../bindings/changeme/astro/services/models";
export function randomColor(brightness: number): string { export function randomColor(brightness: number): string {
function randomChannel(brightness: number): string { function randomChannel(brightness: number): string {
var r = 255-brightness; var r = 255-brightness;
...@@ -8,4 +10,23 @@ export function randomColor(brightness: number): string { ...@@ -8,4 +10,23 @@ export function randomColor(brightness: number): string {
return '#' + randomChannel(brightness) + randomChannel(brightness) + randomChannel(brightness); return '#' + randomChannel(brightness) + randomChannel(brightness) + randomChannel(brightness);
} }
export const rightBrighness = 240; export const rightBrighness = 240;
\ No newline at end of file
export function getNationFlag(nation: Nation | null): string {
if (!nation) {
return "https://flagsapi.com/FR/flat/64.png";
}
console.log(`"${nation.nation_code}"`);
return `https://flagsapi.com/${nation.nation_code}/flat/64.png`
}
export function getNationFlatAlt(nation: Nation | null): string {
if (!nation) {
return "FR";
}
return nation.nation_code;
}
\ No newline at end of file
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
import { SelectedCompetition } from "../../store"; import { SelectedCompetition } 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";
// Variables that will be used in the component // Variables that will be used in the component
let players: (Models.Player | null)[] = []; let players: (Models.Player | null)[] = [];
...@@ -124,23 +125,23 @@ ...@@ -124,23 +125,23 @@
key: "PlayerInitialRank", key: "PlayerInitialRank",
asc: !sortBy.asc, asc: !sortBy.asc,
}; };
}}>Initial Rank</th }}>Rank</th
> >
<th <th
on:click={() => { on:click={() => {
sortBy = { sortBy = {
key: "PlayerFirstname", key: "PlayerLastname",
asc: !sortBy.asc, asc: !sortBy.asc,
}; };
}}>Firstname</th }}>Lastname</th
> >
<th <th
on:click={() => { on:click={() => {
sortBy = { sortBy = {
key: "PlayerLastname", key: "PlayerFirstname",
asc: !sortBy.asc, asc: !sortBy.asc,
}; };
}}>Lastname</th }}>Firstname</th
> >
<th <th
on:click={() => { on:click={() => {
...@@ -213,12 +214,12 @@ ...@@ -213,12 +214,12 @@
> >
<td <td
on:dblclick={async () => { on:dblclick={async () => {
// Show a prompt to the user to change the firstname // Show a prompt to the user to change the lastname
let newFirstname = await swal({ let newLastname = await swal({
content: { content: {
element: "input", element: "input",
attributes: { attributes: {
placeholder: "New firstname", placeholder: "New lastname",
}, },
}, },
buttons: { buttons: {
...@@ -228,8 +229,8 @@ ...@@ -228,8 +229,8 @@
}); });
// Check if the user confirmed the prompt // Check if the user confirmed the prompt
if (newFirstname) { if (newLastname) {
player.PlayerFirstname = newFirstname; player.PlayerLastname = newLastname;
if (competition != undefined) if (competition != undefined)
await Session.UpdateCompetitionPlayer( await Session.UpdateCompetitionPlayer(
competition.CompetitionID, competition.CompetitionID,
...@@ -238,16 +239,17 @@ ...@@ -238,16 +239,17 @@
loadPlayers(); loadPlayers();
}); });
} }
}}>{player.PlayerFirstname}</td }}
>{player.PlayerLastname.toLocaleUpperCase()}</td
> >
<td <td
on:dblclick={async () => { on:dblclick={async () => {
// Show a prompt to the user to change the lastname // Show a prompt to the user to change the firstname
let newLastname = await swal({ let newFirstname = await swal({
content: { content: {
element: "input", element: "input",
attributes: { attributes: {
placeholder: "New lastname", placeholder: "New firstname",
}, },
}, },
buttons: { buttons: {
...@@ -257,8 +259,8 @@ ...@@ -257,8 +259,8 @@
}); });
// Check if the user confirmed the prompt // Check if the user confirmed the prompt
if (newLastname) { if (newFirstname) {
player.PlayerLastname = newLastname; player.PlayerFirstname = newFirstname;
if (competition != undefined) if (competition != undefined)
await Session.UpdateCompetitionPlayer( await Session.UpdateCompetitionPlayer(
competition.CompetitionID, competition.CompetitionID,
...@@ -267,7 +269,7 @@ ...@@ -267,7 +269,7 @@
loadPlayers(); loadPlayers();
}); });
} }
}}>{player.PlayerLastname}</td }}>{player.PlayerFirstname}</td
> >
<td <td
>{#if player.PlayerClub}{player.PlayerClub >{#if player.PlayerClub}{player.PlayerClub
...@@ -277,9 +279,14 @@ ...@@ -277,9 +279,14 @@
>{#if player.PlayerRegion}{player.PlayerRegion >{#if player.PlayerRegion}{player.PlayerRegion
.region_name}{:else}Sans Nom{/if}</td .region_name}{:else}Sans Nom{/if}</td
> >
<td <td class="flag-container"
>{#if player.PlayerNation}{player.PlayerNation ><img
.nation_name}{:else}Sans Nom{/if}</td src={getNationFlag(player.PlayerNation)}
alt="Player's flag : {getNationFlatAlt(
player.PlayerNation
)}"
class="flag"
/></td
> >
</tr> </tr>
{/if} {/if}
...@@ -348,4 +355,14 @@ ...@@ -348,4 +355,14 @@
color: red; color: red;
text-align: center; text-align: center;
} }
.flag-container {
text-align: left;
}
.flag {
width: 20px;
height: 20px;
vertical-align: middle;
}
</style> </style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment