-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for max_rounds for X01
- Loading branch information
Showing
13 changed files
with
266 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/pages/leg/components/pick-winner-modal/pick-winner-modal.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const _ = require("underscore"); | ||
const axios = require('axios'); | ||
|
||
module.exports = { | ||
onCreate(input) { | ||
this.state = { | ||
legId: input.legId, | ||
players: input.players, | ||
winner: undefined, | ||
submitting: false | ||
} | ||
}, | ||
|
||
onMount() { | ||
const modal = document.getElementById('pick-winner-modal'); | ||
modal.addEventListener("keydown", this.onKeyDown.bind(this), false); | ||
modal.addEventListener("keypress", this.onKeyPress.bind(this), false); | ||
}, | ||
onKeyPress(e) { | ||
e.stopPropagation(); | ||
}, | ||
onKeyDown(e) { | ||
if (e.key === 'Enter') { | ||
if (this.state.submitting) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
return; | ||
} | ||
this.confirmWinner(); | ||
|
||
// We don`t want to submit darts in the background | ||
e.preventDefault(); | ||
} else if (e.key == 'ESC') { | ||
// Don`t allow closing this modal | ||
e.preventDefault(); | ||
} else { | ||
const player = this.input.players[parseInt(e.key) - 1]; | ||
if (player) { | ||
const exist = _.findWhere(this.state.players, { player_id: player.player_id }); | ||
if (exist) { | ||
this.addPlayer(player); | ||
} else { | ||
this.removePlayer(player); | ||
} | ||
} | ||
} | ||
e.stopPropagation(); | ||
}, | ||
|
||
playerSelected(playerId) { | ||
const player = _.findWhere(this.input.players, { player_id: playerId }); | ||
this.addPlayer(player); | ||
}, | ||
|
||
addPlayer(player) { | ||
this.state.players = _.reject(this.input.players, (p) => p.player_id === player.player_id); | ||
this.setStateDirty('players'); | ||
|
||
this.state.winner = player; | ||
this.setStateDirty('winner'); | ||
}, | ||
|
||
removePlayer(player) { | ||
this.state.winner = undefined; | ||
this.setStateDirty('winner'); | ||
|
||
this.state.players.push(player); | ||
this.setStateDirty('players'); | ||
}, | ||
|
||
confirmWinner(event) { | ||
this.state.submitting = true; | ||
if (!this.state.winner) { | ||
alert("Please select a winner"); | ||
this.state.submitting = false; | ||
return; | ||
} | ||
axios.put(`${window.location.origin}/legs/${this.state.legId}/finish`, { winner_id: this.state.winner.player_id }) | ||
.then(response => { | ||
const match = response.data.match; | ||
if (match.is_finished) { | ||
location.href = `/matches/${match.id}/result?finished=true`; | ||
} else { | ||
location.href = `/legs/${response.data.leg_id}`; | ||
} | ||
}).catch(error => { | ||
this.state.submitting = false; | ||
alert('Error choosing winner. Please reload'); | ||
console.log(error); | ||
location.reload(); | ||
}); | ||
} | ||
}; |
53 changes: 53 additions & 0 deletions
53
src/pages/leg/components/pick-winner-modal/pick-winner-modal.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<div id="pick-winner-modal" class="modal fade modal-right" tabindex="-1" role="dialog" aria-labelledby="pick-winner-modal-label" aria-hidden="true" data-backdrop="static" data-keyboard="false"> | ||
<div class="modal-dialog modal-dialog-centered" role="document" style="height:100%;"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title">Select Winner</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<h5>Players</h5> | ||
<div class="table-responsive no-border" style="min-height: 75px;"> | ||
<table class="uv-table-players" id="table-players-select-order" style="table-layout: fixed;"> | ||
<tbody> | ||
<tr> | ||
<for|player| of=state.players> | ||
<td class="block-container-blue text-center" data-player-id=player.player_id on-click("playerSelected", player.player_id)> | ||
<div> | ||
<label class="key-small">${player.order}</label> | ||
</div> | ||
<label id=`player-name-${player.player_id}` class="label-player-name">${player.player.name}</label> | ||
</td> | ||
</for> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<h5>Winner</h5> | ||
<div class="table-responsive no-border" style="min-height: 75px;"> | ||
<table class="uv-table-players" id="table-players-selected-order" style="table-layout: fixed;"> | ||
<tbody> | ||
<tr> | ||
<if(state.winner)> | ||
<td class="block-container-blue text-center" data-player-id=state.winner.player_id on-click("removePlayer", state.winner)> | ||
<div class="text-center"> | ||
<label class="key-small">${state.winner.order}</label> | ||
</div> | ||
<label id=`player-name-${state.winner.player_id}` class="label-player-name">${state.winner.player.name}</label> | ||
</td> | ||
</if> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<div class="modal-footer text-center"> | ||
<button class="btn btn-primary" type="button" on-click("confirmWinner")> | ||
<div class="text-center"> | ||
<label class="key-small">ENTER</label> | ||
<label class="pl-10">Finish Match</label> | ||
</div> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
src/pages/leg/components/pick-winner-modal/pick-winner-modal.style.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.key-small { | ||
padding-left: 8px; | ||
padding-right: 8px; | ||
height: 25px; | ||
background-color: #eeeff1; | ||
color: #aaaaaa; | ||
font-weight: normal; | ||
line-height: 25px; | ||
border-radius: 5px; | ||
box-shadow: 0px 1px 0px 2px #999; | ||
} | ||
|
||
body { | ||
// Opening modal adds padding for some reason | ||
padding-right: 0px !important; | ||
} |
Oops, something went wrong.