diff --git a/availabili.tf/src/assets/main.css b/availabili.tf/src/assets/main.css index 9c34cd5..4d72884 100644 --- a/availabili.tf/src/assets/main.css +++ b/availabili.tf/src/assets/main.css @@ -250,6 +250,11 @@ input, textarea { sans-serif; } +input[type="checkbox"] { + width: unset; + display: inline-block; +} + textarea { resize: vertical; } diff --git a/availabili.tf/src/client/models/CreateEventJson.ts b/availabili.tf/src/client/models/CreateEventJson.ts index e770eed..3fd76a9 100644 --- a/availabili.tf/src/client/models/CreateEventJson.ts +++ b/availabili.tf/src/client/models/CreateEventJson.ts @@ -5,6 +5,7 @@ import type { PlayerRoleSchema } from './PlayerRoleSchema'; export type CreateEventJson = { description: (string | null); + includePlayersWithoutRoles?: boolean; name: string; playerRoles: Array; startTime: string; diff --git a/availabili.tf/src/components/EventSchedulerForm.vue b/availabili.tf/src/components/EventSchedulerForm.vue index a89c37e..0594a25 100644 --- a/availabili.tf/src/components/EventSchedulerForm.vue +++ b/availabili.tf/src/components/EventSchedulerForm.vue @@ -54,10 +54,6 @@ function saveRoster() { } onMounted(() => { - //if (!team.value) { - // teamsStore.fetchTeam(teamId.value); - //} - if (eventId.value) { eventsStore.fetchEvent(eventId.value) .then((response) => { @@ -89,6 +85,18 @@ onMounted(() => {

Description (optional)

+
+
+ + +
+
diff --git a/availabili.tf/src/composables/event-form.ts b/availabili.tf/src/composables/event-form.ts index eb862ed..57f9a35 100644 --- a/availabili.tf/src/composables/event-form.ts +++ b/availabili.tf/src/composables/event-form.ts @@ -8,13 +8,14 @@ export function useEventForm() { const title = ref(""); const description = ref(""); const players = ref([]); + const includePlayersWithoutRoles = ref(false); const eventId = computed(() => Number(route.params.eventId)); - return { title, description, players, + includePlayersWithoutRoles, eventId, } } diff --git a/availabili.tf/src/stores/roster.ts b/availabili.tf/src/stores/roster.ts index d9a09a0..acf01bc 100644 --- a/availabili.tf/src/stores/roster.ts +++ b/availabili.tf/src/stores/roster.ts @@ -176,7 +176,7 @@ export const useRosterStore = defineStore("roster", () => { const startTime = ref(); - const { title, description } = useEventForm(); + const { title, description, includePlayersWithoutRoles } = useEventForm(); function saveRoster(teamId: number) { if (startTime.value == undefined) { @@ -187,6 +187,7 @@ export const useRosterStore = defineStore("roster", () => { name: title.value, description: description.value, startTime: startTime.value.toString(), + includePlayersWithoutRoles: includePlayersWithoutRoles.value, playerRoles: Object.values(selectedPlayers).map((player) => ({ player: { steamId: player.steamId, @@ -241,5 +242,6 @@ export const useRosterStore = defineStore("roster", () => { updateRoster, title, description, + includePlayersWithoutRoles, } }); diff --git a/backend-flask/events.py b/backend-flask/events.py index 4a8f3c4..394fee0 100644 --- a/backend-flask/events.py +++ b/backend-flask/events.py @@ -78,6 +78,7 @@ class CreateEventJson(BaseModel): name: str description: Optional[str] start_time: datetime + include_players_without_roles: bool = False player_roles: list[PlayerRoleSchema] class UpdateEventJson(BaseModel): @@ -126,7 +127,10 @@ def create_event(player_team: PlayerTeam, team_id: int, json: CreateEventJson, * tuple_(PlayerTeam.player_id, PlayerTeamRole.role).in_(tuples) ).all() + player_team_ids = [] for player_team, role_id, availability in map(lambda x: x.tuple(), results): + player_team_ids.append(player_team.player_id) + player_event = PlayerEvent() player_event.player_id = player_team.player_id player_event.event_id = event.id @@ -137,6 +141,30 @@ def create_event(player_team: PlayerTeam, team_id: int, json: CreateEventJson, * db.session.add(player_event) + if json.include_players_without_roles: + # add players without roles, but with availability + + players_without_roles = db.session.query( + PlayerTeam, PlayerTeamAvailability.availability + ).join( + PlayerTeamAvailability, + (PlayerTeamAvailability.player_team_id == PlayerTeam.id) & + (PlayerTeamAvailability.start_time <= event.start_time) & + (PlayerTeamAvailability.end_time > event.start_time) + ).where( + # player_team.player_id NOT IN (ids of processed players) + PlayerTeam.player_id.notin_(player_team_ids), + PlayerTeam.team_id == team_id + ).all() + + for player_team, availability in map(lambda x: x.tuple(), players_without_roles): + player_event = PlayerEvent() + player_event.player_id = player_team.player_id + player_event.event_id = event.id + # autoconfirm if availability = 2 + player_event.has_confirmed = (availability == 2) + db.session.add(player_event) + db.session.commit() event.update_discord_message()