diff --git a/routes/tournaments.js b/routes/tournaments.js index cdd6cce..966c157 100644 --- a/routes/tournaments.js +++ b/routes/tournaments.js @@ -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`), @@ -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')}`; @@ -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, diff --git a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/add-player/add-player.marko b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/add-player/add-player.marko index 00d1eff..b13a6bc 100644 --- a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/add-player/add-player.marko +++ b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/add-player/add-player.marko @@ -1,7 +1,6 @@ $ const types = require('../../../../../../../../components/scorecard/components/match_types')
-

${input.group.name}

diff --git a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.component.js b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.component.js new file mode 100644 index 0000000..9900715 --- /dev/null +++ b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.component.js @@ -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'); + } +} \ No newline at end of file diff --git a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.marko b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.marko new file mode 100644 index 0000000..4f92f9e --- /dev/null +++ b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/components/group-selector/group-selector.marko @@ -0,0 +1,14 @@ +
+

${input.group.name}

+

Venue

+ + + +
\ No newline at end of file diff --git a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.component.js b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.component.js index 2ae1a8c..cc01741 100644 --- a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.component.js +++ b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.component.js @@ -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) { @@ -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; diff --git a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.marko b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.marko index 0790d03..4f83838 100644 --- a/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.marko +++ b/src/pages/tournaments-admin/components/tournaments-admin/components/generate-tournament-tab/generate-tournament-tab.marko @@ -43,28 +43,39 @@
- + on-remove-player("onRemovePlayer", "group1") /> - + on-remove-player("onRemovePlayer", "group2") />
2)> - + on-remove-player("onRemovePlayer", "group3") /> 3)> - + on-remove-player("onRemovePlayer", "group4") />
diff --git a/src/pages/tournaments-admin/components/tournaments-admin/tournaments-admin.marko b/src/pages/tournaments-admin/components/tournaments-admin/tournaments-admin.marko index e13e888..6d08d17 100644 --- a/src/pages/tournaments-admin/components/tournaments-admin/tournaments-admin.marko +++ b/src/pages/tournaments-admin/components/tournaments-admin/tournaments-admin.marko @@ -11,7 +11,7 @@
- +