Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring master into dev #52

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend-vite/src/components/SubmitReport.vue
Original file line number Diff line number Diff line change
@@ -75,16 +75,16 @@ async function uploadAllData() {
let updateDiAndInjuries = store.gameReports.map((gameReport) => {
if (gameReport.id) {
let tAdiP = gameReport.teamAReport.disciplinaryActions.map((da) => {
store.sendDisciplinaryAction(da, gameReport,true)
return store.sendDisciplinaryAction(da, gameReport,true)
})
let tBdiP = gameReport.teamBReport.disciplinaryActions.map((da) => {
store.sendDisciplinaryAction(da, gameReport,true)
return store.sendDisciplinaryAction(da, gameReport,true)
})
let tAinP = gameReport.teamAReport.injuries.map((injury) => {
store.sendInjury(injury, gameReport, true)
return store.sendInjury(injury, gameReport, true)
})
let tBinP = gameReport.teamBReport.injuries.map((injury) => {
store.sendInjury(injury, gameReport, true)
return store.sendInjury(injury, gameReport, true)
})
//concat all four arrays
let allPromises = tAdiP.concat(tBdiP).concat(tAinP).concat(tBinP)
121 changes: 89 additions & 32 deletions frontend-vite/src/components/public/PublicTournamentList.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<script setup lang="ts">
import {usePublicStore} from "@/utils/public_store";
import {RegionDEO} from "@/types/tournament_types";
import {computed, ref} from "vue";
import {type DatabaseTournament, PublicTournamentWithTeamsDEO, RegionDEO} from "@/types/tournament_types";
import {computed, onBeforeMount, ref} from "vue";
import {useRouter} from "vue-router";
import {loadAllTournamentsWithTeams} from "@/utils/api/tournament_api";
import type {Team} from "@/types/team_types";

const store = usePublicStore();

function regionIDToRegion(regionID: number): RegionDEO {
return store.regions.filter(it => it.id == regionID)[0]
}

const tournamentsWithTeams = ref<PublicTournamentWithTeamsDEO[]>([])


const tournamentsSortedByDate = computed(() => {
return store.tournaments.toSorted((a, b) => {
@@ -19,50 +24,102 @@ const tournamentsSortedByDate = computed(() => {
} else {
return true
}
})
}).filter(teamFilterPredicate)
})

const teamFilterPredicate = (tournament: DatabaseTournament) => {
if (selectedTeam.value) {
const teamsInTournament = tournamentsWithTeams.value.find(it => it.tournament.id == tournament.id)?.teams
if (!teamsInTournament) {
return false
}
return teamsInTournament.filter(it => {
if (it.isAmalgamation) {
return (it.amalgamationTeams
?.filter(amalgamationTeam => amalgamationTeam.id == selectedTeam.value?.id).length ?? 0) > 0
} else {
return it.id == selectedTeam.value?.id
}
}).length > 0
} else {
return true
}
}

const router = useRouter()

function navigateToReport(reportID: number) {
let id = reportID.toString()
router.push({path: `/tournament/${id}`})
}

function loadTournamentsWithTeams() {
loadAllTournamentsWithTeams().then(response => {
tournamentsWithTeams.value = response.tournaments
})
.catch(error => {
store.newError(error)
})
}

onBeforeMount(() => {
loadTournamentsWithTeams()
})
const selectedTeam = ref<Team | undefined>(undefined)
const allTeams = computed(() => {
return store.teams.filter(it => !it.isAmalgamation)
.sort((a, b) => {
return a.name.localeCompare(b.name)
})
})

const selectedRegion = ref<RegionDEO | undefined>(undefined)
</script>

<template>
<div class="flex-col w-full flex items-center">
<div class="flex flex-col w-full lg:w-7/12">
<div class="flex flex-row justify-center content-center">
<div>
<SelectButton
v-model="selectedRegion"
:options="store.regions"
optionLabel="name"
/>
</div>
<div v-if="selectedRegion">
<Button @click="selectedRegion = undefined">X</Button>
</div>
</div>
<div
v-for="tournament in tournamentsSortedByDate"
key="tournament.id"
class="single-tournament-row"
@click="navigateToReport(tournament.id)"
>
<div class="flex flex-row">
<div class="grow">{{ tournament.name }}</div>
<div>{{ tournament.location }}</div>
</div>
<div class="flex flex-row">
<div class="grow">{{ tournament.date.toISODate() }}</div>
<div>{{ regionIDToRegion(tournament.region).name }}</div>
</div>
</div>
<div class="flex flex-col w-full lg:w-7/12">
<div class="flex flex-row justify-center content-center">
<div>
<SelectButton
v-model="selectedRegion"
:options="store.regions"
optionLabel="name"
/>
</div>
<div v-if="selectedRegion">
<Button @click="selectedRegion = undefined">X</Button>
</div>
</div>
<div class="flex flex-row justify-center content-center m-2">
<Dropdown
v-model="selectedTeam"
:options="allTeams"
optionLabel="name"
placeholder="Filter by team"
filter
/>
<div v-if="selectedTeam" class="ml-2">
<Button @click="selectedTeam = undefined">X</Button>
</div>
</div>
<div
v-for="tournament in tournamentsSortedByDate"
key="tournament.id"
class="single-tournament-row"
@click="navigateToReport(tournament.id)"
>
<div class="flex flex-row">
<div class="grow">{{ tournament.name }}</div>
<div>{{ tournament.location }}</div>
</div>
<div class="flex flex-row">
<div class="grow">{{ tournament.date.toISODate() }}</div>
<div>{{ regionIDToRegion(tournament.region).name }}</div>
</div>
</div>

</div>
</div>
</div>
</template>

14 changes: 14 additions & 0 deletions frontend-vite/src/types/tournament_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {z} from "zod";
import {DateTime} from "luxon";
import {Team} from "@/types/team_types";

export const Tournament = z.object({
name: z.string().min(1),
@@ -54,3 +55,16 @@ export const TournamentTeamPreselectionDEO = z.object({

export type TournamentTeamPreselectionDEO = z.infer<typeof TournamentTeamPreselectionDEO>


export const PublicTournamentWithTeamsDEO = z.object({
tournament: DatabaseTournament,
teams: z.array(Team)
})

export type PublicTournamentWithTeamsDEO = z.infer<typeof PublicTournamentWithTeamsDEO>

export const PublicTournamentListDEO = z.object({
tournaments: z.array(PublicTournamentWithTeamsDEO)
})

export type PublicTournamentListDEO = z.infer<typeof PublicTournamentListDEO>
9 changes: 8 additions & 1 deletion frontend-vite/src/utils/api/tournament_api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {DateTime} from "luxon";
import {makePostRequest, parseAndHandleDEO} from "@/utils/api/api_utils";
import {
DatabaseTournament,
DatabaseTournament, PublicTournamentListDEO,
RegionDEO,
Tournament,
TournamentTeamPreselectionDEO,
@@ -81,3 +81,10 @@ export async function setTournamentPreselectedTeams(tournament: DatabaseTourname
} as TournamentTeamPreselectionDEO
).then(data => parseAndHandleDEO(data, TournamentTeamPreselectionDEO))
}


export async function loadAllTournamentsWithTeams():Promise<PublicTournamentListDEO> {
return fetch("/api/tournament/all_with_teams")
.then(response => response.json())
.then(data => parseAndHandleDEO(data, PublicTournamentListDEO))
}
Loading