Skip to content

Commit

Permalink
Support setting venue when generating tournaments
Browse files Browse the repository at this point in the history
  • Loading branch information
thordy committed Dec 2, 2024
1 parent 6b81bc5 commit fa207e6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 15 deletions.
9 changes: 8 additions & 1 deletion routes/tournaments.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ router.get('/current', function (req, res, next) {
});
});

/* Get current active tournament */
/* Get tournament admin */
router.get('/admin', function (req, res, next) {
axios.all([
axios.get(`${req.app.locals.kcapp.api}/tournament/groups`),
Expand Down Expand Up @@ -214,6 +214,12 @@ router.post('/admin/generate', function (req, res, next) {
});
}
});
const venues = {};
["group1", "group2", "group3", "group4"].forEach(key => {
if (body[key]) {
venues[body[key].group.id] = body[key].venueId;
}
});

const name = body.name;
const shortName = `${name.substring(0, 1)}${moment().format('DDMM')}`;
Expand All @@ -225,6 +231,7 @@ router.post('/admin/generate', function (req, res, next) {
match_type_id: body.match_type_id,
starting_score: body.starting_score,
max_rounds: body.max_rounds,
venues: venues,
is_playoffs: false,
players: players,
manual_admin: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$ const types = require('../../../../../../../../components/scorecard/components/match_types')
<div style="flex: 1;">
<div style="display: flex;">
<h2 style="text-align: center">${input.group.name}</h2>
<if(input.remove)>
<button class="btn btn-primary" type="button" style="display: inline-block;" on-click("removeGroup")>Remove</button>
</if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
onAddPlayer(player) {
this.emit('add-player', player);
},
onRemovePlayer(player) {
this.emit('remove-player', player);
},
onVenueChange(event, selected) {
this.emit('venue-change', parseInt(event.target.value));
},
onRemoveGroup(event) {
this.emit('remove-group');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div style="width: 50%;">
<h2 style="text-align: center">${input.group.name}</h2>
<p>Venue</p>
<select on-change("onVenueChange")>
<option value=undefined selected=!input.venue>-</option>
<for|venue| of=input.venues>
<option value=`${venue.id}` selected=(venue.id == input.venue)>${venue.name}</option>
</for>
</select>

<add-player selected=input.selected available=input.playersAvailable
on-add-player("onAddPlayer")
on-remove-player("onRemovePlayer")/>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ module.exports = {
this.state.playersAvailable = _.sortBy(this.state.playersAvailable, "name");
this.setStateDirty('playersAvailable');
},
onVenueChange(group, venue) {
this.state.selected[group].venueId = venue;
},
onAddGroup() {
const numGroups = Object.keys(this.state.selected).length;
if (numGroups >= 4) {
Expand All @@ -91,8 +94,16 @@ module.exports = {
this.state.office = parseInt(event.target.value);
this.state.playersAvailable = _.reject(this.input.players, (player) => player.office_id !== this.state.office );
this.setStateDirty('playersAvailable');

this.state.venues = _.reject(this.input.venues, (venue) => venue.office_id != this.state.office );
this.setStateDirty("venues");
},
generateTournament() {
// Validate that group1 contains at least 2 players
if (this.state.selected.group1.players.length < 2) {
alert("Group 1 must contain at least 2 players");
return;
}
// Validate that each group contains either no players, or at least 2 players
for (let group in this.state.selected) {
let players = this.state.selected[group].players;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,39 @@
</select>

<div style="display: flex;">
<add-player group=state.selected.group1.group selected=state.selected.group1.players available=state.playersAvailable
<group-selector group=state.selected.group1.group
venues=state.venues
selected=state.selected.group1.players
playersAvailable=state.playersAvailable
on-venue-change("onVenueChange", "group1")
on-add-player("onAddPlayer", "group1")
on-remove-player("onRemovePlayer", "group1")/>
on-remove-player("onRemovePlayer", "group1") />

<add-player group=state.selected.group2.group selected=state.selected.group2.players available=state.playersAvailable
<group-selector group=state.selected.group2.group
venues=state.venues
selected=state.selected.group2.players
playersAvailable=state.playersAvailable
on-venue-change("onVenueChange", "group2")
on-add-player("onAddPlayer", "group2")
on-remove-player("onRemovePlayer", "group2")/>
on-remove-player("onRemovePlayer", "group2") />
</div>
<div style="display: flex;">
<if(Object.keys(state.selected).length > 2)>
<add-player group=state.selected.group3.group selected=state.selected.group3.players available=state.playersAvailable
remove=true
<group-selector group=state.selected.group3.group
venues=state.venues
selected=state.selected.group3.players
playersAvailable=state.playersAvailable
on-venue-change("onVenueChange", "group3")
on-add-player("onAddPlayer", "group3")
on-remove-player("onRemovePlayer", "group3")
on-remove-group("onRemoveGroup", "group3") />
on-remove-player("onRemovePlayer", "group3") />
</if>
<if(Object.keys(state.selected).length > 3)>
<add-player group=state.selected.group4.group selected=state.selected.group4.players available=state.playersAvailable
remove=true
<group-selector group=state.selected.group4.group
venues=state.venues
selected=state.selected.group4.players
on-venue-change("onVenueChange", "group4")
on-add-player("onAddPlayer", "group4")
on-remove-player("onRemovePlayer", "group4")
on-remove-group("onRemoveGroup", "group4")/>
on-remove-player("onRemovePlayer", "group4") />
</if>
</div>
<button class="btn btn-primary" type="button" on-click("onAddGroup")>Add Group</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ul>
</div>
<div class="tab-content" style="width: 100%;">
<generate-tournament-tab players=input.players presets=input.presets offices=input.offices groups=input.groups types=input.types modes=input.modes maxRounds=input.maxRounds/>
<generate-tournament-tab players=input.players presets=input.presets offices=input.offices venues=input.venues groups=input.groups types=input.types modes=input.modes maxRounds=input.maxRounds/>
<create-tournament-tab players=input.players types=input.types modes=input.modes offices=input.offices groups=input.groups/>
</div>
</div>
Expand Down

0 comments on commit fa207e6

Please sign in to comment.