Add option to include unassigned players in events
							parent
							
								
									8654db9125
								
							
						
					
					
						commit
						a6ff9a7291
					
				| 
						 | 
					@ -250,6 +250,11 @@ input, textarea {
 | 
				
			||||||
    sans-serif;
 | 
					    sans-serif;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					input[type="checkbox"] {
 | 
				
			||||||
 | 
					  width: unset;
 | 
				
			||||||
 | 
					  display: inline-block;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
textarea {
 | 
					textarea {
 | 
				
			||||||
  resize: vertical;
 | 
					  resize: vertical;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
import type { PlayerRoleSchema } from './PlayerRoleSchema';
 | 
					import type { PlayerRoleSchema } from './PlayerRoleSchema';
 | 
				
			||||||
export type CreateEventJson = {
 | 
					export type CreateEventJson = {
 | 
				
			||||||
    description: (string | null);
 | 
					    description: (string | null);
 | 
				
			||||||
 | 
					    includePlayersWithoutRoles?: boolean;
 | 
				
			||||||
    name: string;
 | 
					    name: string;
 | 
				
			||||||
    playerRoles: Array<PlayerRoleSchema>;
 | 
					    playerRoles: Array<PlayerRoleSchema>;
 | 
				
			||||||
    startTime: string;
 | 
					    startTime: string;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,10 +54,6 @@ function saveRoster() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
onMounted(() => {
 | 
					onMounted(() => {
 | 
				
			||||||
  //if (!team.value) {
 | 
					 | 
				
			||||||
  //  teamsStore.fetchTeam(teamId.value);
 | 
					 | 
				
			||||||
  //}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (eventId.value) {
 | 
					  if (eventId.value) {
 | 
				
			||||||
    eventsStore.fetchEvent(eventId.value)
 | 
					    eventsStore.fetchEvent(eventId.value)
 | 
				
			||||||
      .then((response) => {
 | 
					      .then((response) => {
 | 
				
			||||||
| 
						 | 
					@ -89,6 +85,18 @@ onMounted(() => {
 | 
				
			||||||
      <h3>Description (optional)</h3>
 | 
					      <h3>Description (optional)</h3>
 | 
				
			||||||
      <input v-model="rosterStore.description" />
 | 
					      <input v-model="rosterStore.description" />
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div class="form-group margin" v-if="!eventId">
 | 
				
			||||||
 | 
					      <div>
 | 
				
			||||||
 | 
					        <input
 | 
				
			||||||
 | 
					          v-model="rosterStore.includePlayersWithoutRoles"
 | 
				
			||||||
 | 
					          type="checkbox"
 | 
				
			||||||
 | 
					          name="includePlayersWithoutRoles"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					        <label for="includePlayersWithoutRoles">
 | 
				
			||||||
 | 
					          Include attendance of players without assigned role
 | 
				
			||||||
 | 
					        </label>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
    <div class="form-group margin">
 | 
					    <div class="form-group margin">
 | 
				
			||||||
      <div class="action-buttons">
 | 
					      <div class="action-buttons">
 | 
				
			||||||
        <button class="accent" @click="saveRoster">Save roster</button>
 | 
					        <button class="accent" @click="saveRoster">Save roster</button>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,13 +8,14 @@ export function useEventForm() {
 | 
				
			||||||
  const title = ref("");
 | 
					  const title = ref("");
 | 
				
			||||||
  const description = ref<string | null>("");
 | 
					  const description = ref<string | null>("");
 | 
				
			||||||
  const players = ref<PlayerRoleSchema[]>([]);
 | 
					  const players = ref<PlayerRoleSchema[]>([]);
 | 
				
			||||||
 | 
					  const includePlayersWithoutRoles = ref(false);
 | 
				
			||||||
  const eventId = computed<number | undefined>(() => Number(route.params.eventId));
 | 
					  const eventId = computed<number | undefined>(() => Number(route.params.eventId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    title,
 | 
					    title,
 | 
				
			||||||
    description,
 | 
					    description,
 | 
				
			||||||
    players,
 | 
					    players,
 | 
				
			||||||
 | 
					    includePlayersWithoutRoles,
 | 
				
			||||||
    eventId,
 | 
					    eventId,
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,7 +176,7 @@ export const useRosterStore = defineStore("roster", () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const startTime = ref<number>();
 | 
					  const startTime = ref<number>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { title, description } = useEventForm();
 | 
					  const { title, description, includePlayersWithoutRoles } = useEventForm();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function saveRoster(teamId: number) {
 | 
					  function saveRoster(teamId: number) {
 | 
				
			||||||
    if (startTime.value == undefined) {
 | 
					    if (startTime.value == undefined) {
 | 
				
			||||||
| 
						 | 
					@ -187,6 +187,7 @@ export const useRosterStore = defineStore("roster", () => {
 | 
				
			||||||
      name: title.value,
 | 
					      name: title.value,
 | 
				
			||||||
      description: description.value,
 | 
					      description: description.value,
 | 
				
			||||||
      startTime: startTime.value.toString(),
 | 
					      startTime: startTime.value.toString(),
 | 
				
			||||||
 | 
					      includePlayersWithoutRoles: includePlayersWithoutRoles.value,
 | 
				
			||||||
      playerRoles: Object.values(selectedPlayers).map((player) => ({
 | 
					      playerRoles: Object.values(selectedPlayers).map((player) => ({
 | 
				
			||||||
        player: {
 | 
					        player: {
 | 
				
			||||||
          steamId: player.steamId,
 | 
					          steamId: player.steamId,
 | 
				
			||||||
| 
						 | 
					@ -241,5 +242,6 @@ export const useRosterStore = defineStore("roster", () => {
 | 
				
			||||||
    updateRoster,
 | 
					    updateRoster,
 | 
				
			||||||
    title,
 | 
					    title,
 | 
				
			||||||
    description,
 | 
					    description,
 | 
				
			||||||
 | 
					    includePlayersWithoutRoles,
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,6 +78,7 @@ class CreateEventJson(BaseModel):
 | 
				
			||||||
    name: str
 | 
					    name: str
 | 
				
			||||||
    description: Optional[str]
 | 
					    description: Optional[str]
 | 
				
			||||||
    start_time: datetime
 | 
					    start_time: datetime
 | 
				
			||||||
 | 
					    include_players_without_roles: bool = False
 | 
				
			||||||
    player_roles: list[PlayerRoleSchema]
 | 
					    player_roles: list[PlayerRoleSchema]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UpdateEventJson(BaseModel):
 | 
					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)
 | 
					        tuple_(PlayerTeam.player_id, PlayerTeamRole.role).in_(tuples)
 | 
				
			||||||
    ).all()
 | 
					    ).all()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    player_team_ids = []
 | 
				
			||||||
    for player_team, role_id, availability in map(lambda x: x.tuple(), results):
 | 
					    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 = PlayerEvent()
 | 
				
			||||||
        player_event.player_id = player_team.player_id
 | 
					        player_event.player_id = player_team.player_id
 | 
				
			||||||
        player_event.event_id = event.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)
 | 
					        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()
 | 
					    db.session.commit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    event.update_discord_message()
 | 
					    event.update_discord_message()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue