Skip to content

Commit f1539e9

Browse files
committed
Merge branch 'match_type_leaderboard' into develop
2 parents 14a1529 + 2c75787 commit f1539e9

File tree

15 files changed

+484
-131
lines changed

15 files changed

+484
-131
lines changed
Lines changed: 90 additions & 0 deletions
Loading

routes/players.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ router.get('/:id/statistics', function (req, res, next) {
6262
axios.get(`${req.app.locals.kcapp.api}/player/${playerId}/checkouts`),
6363
axios.get(`${req.app.locals.kcapp.api}/player/${playerId}/tournament`),
6464
axios.get(`${req.app.locals.kcapp.api}/player/${playerId}/badges`),
65-
axios.get(`${req.app.locals.kcapp.api}/statistics/x01/player/50`),
65+
axios.get(`${req.app.locals.kcapp.api}/statistics/x01/player/`),
6666
axios.get(`${req.app.locals.kcapp.api}/badge`),
6767
axios.get(`${req.app.locals.kcapp.api}/tournament`)
6868
]).then(axios.spread((players, playerData, statistics, previous, progression, checkouts, playerTournament, playerBadges, leaderboardData, badges, tournaments) => {

routes/statistics.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ router.get('/leaderboard', function (req, res, next) {
3030
axios.all([
3131
axios.get(`${req.app.locals.kcapp.api}/player`),
3232
axios.get(`${req.app.locals.kcapp.api}/office`),
33+
axios.get(`${req.app.locals.kcapp.api}/match/types`),
3334
axios.get(`${req.app.locals.kcapp.api}/option/default`),
34-
axios.get(`${req.app.locals.kcapp.api}/statistics/x01/player/50`)
35-
]).then(axios.spread((players, offices, defaults, leaderboardData) => {
36-
const leaderboard = leaderboardData.data;
35+
axios.get(`${req.app.locals.kcapp.api}/statistics/x01/player/`),
36+
axios.get(`${req.app.locals.kcapp.api}/leaderboard/matchtypes`)
37+
]).then(axios.spread((players, offices, matchTypes, defaults, x01LeaderboardData, matchTypesLeaderboard) => {
38+
const x01Leaderboard = x01LeaderboardData.data;
3739

38-
const kings = _.chain(leaderboard)
40+
const kings = _.chain(x01Leaderboard)
3941
.groupBy('office_id')
4042
.mapObject(players => _.first(players).player_id)
4143
.value();
4244

43-
_.each(leaderboard, player => {
45+
_.each(x01Leaderboard, player => {
4446
player.isKing = kings[player.office_id] === player.player_id;
4547
});
4648
res.marko(leaderboardTemplate, {
4749
players: players.data,
4850
offices: offices.data,
4951
defaults: defaults.data,
50-
leaderboard: leaderboard
52+
matchTypes: matchTypes.data,
53+
x01Leaderboard: x01Leaderboard,
54+
matchTypesLeaderboard: matchTypesLeaderboard.data
5155
});
5256
})).catch(error => {
5357
debug(`Error when getting data for leaderboard ${error}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
$ const showScore = input.showScore === undefined || input.showScore;
2+
$ const showDartsThrown = input.showDartsThrown === undefined || input.showDartsThrown;
3+
4+
<div class="col-sm-6 no-gutter">
5+
<div class="table-container">
6+
<if(!input.stats || input.stats.length === 0)>
7+
<div class="text-center block-container-red">${input.heading} - no legs played</div>
8+
</if>
9+
<else>
10+
<div style="margin-bottom: 0;" class=`${input.heading ? "block-container-red" : ''} text-center`>${input.heading}</div>
11+
<div class="block-container no-padding">
12+
<div class="table table-responsive">
13+
<table class="table-statistics">
14+
<thead>
15+
<tr>
16+
<th class="text-right">Rank</th>
17+
<th class="text-left">Player</th>
18+
<if(showDartsThrown)>
19+
<th class="text-center">Darts Thrown</th>
20+
</if>
21+
<if(showScore)>
22+
<th class="text-center">Score</th>
23+
</if>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<for|stats, idx| of=input.stats>
28+
$ let player = input.players[stats.player_id];
29+
<tr>
30+
<td class="pl-10 text-left">${idx + 1}</td>
31+
<td>
32+
<a href=`/players/${player.id}/statistics`>${player.name}</a>
33+
</td>
34+
<if(showDartsThrown)>
35+
<if(showScore)>
36+
<td class="text-center">${stats.darts_thrown}</td>
37+
</if>
38+
<else>
39+
<td class="text-center">
40+
<a href=`/legs/${stats.leg_id}/result`>${stats.darts_thrown}</a>
41+
</td>
42+
</else>
43+
</if>
44+
<if(showScore)>
45+
<td class="text-center">
46+
<a href=`/legs/${stats.leg_id}/result`>${stats.score}</a>
47+
</td>
48+
</if>
49+
</tr>
50+
</for>
51+
</tbody>
52+
</table>
53+
</div>
54+
</div>
55+
</else>
56+
</div>
57+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.no-gutter {
2+
margin-right: 0;
3+
margin-left: 0;
4+
padding-left: 1em;
5+
padding-right: 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const _ = require('underscore');
2+
3+
module.exports = {
4+
onCreate(input) {
5+
const shootout = _.filter(input.leaderboard[2], (stats) => stats.darts_thrown > 9);
6+
const shootoutMax9 = _.filter(input.leaderboard[2], (stats) => stats.darts_thrown === 9);
7+
this.state = {
8+
shootout: shootout,
9+
shootoutMax9: shootoutMax9
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Table from "./components/match-type-leaderboard-table/match-type-leaderboard-table.marko";
2+
3+
<div class="row">
4+
<${Table} heading="9 Dart Shootout" players=input.players stats=state.shootoutMax9 />
5+
<${Table} heading="9 Dart Shootout (>9 darts thrown)" players=input.players stats=state.shootout />
6+
</div>
7+
<div class="row">
8+
<${Table} heading="99 Darts" showDartsThrown=false players=input.players stats=input.leaderboard[5] />
9+
<${Table} heading="Around the World" showDartsThrown=false players=input.players stats=input.leaderboard[6] />
10+
</div>
11+
<div class="row">
12+
<${Table} heading="Shanghai" players=input.players stats=input.leaderboard[7] />
13+
<${Table} heading="Around the Clock" showScore=false players=input.players stats=input.leaderboard[8] />
14+
</div>
15+
<div class="row">
16+
<${Table} heading="Tic-Tac-Toe" players=input.players stats=input.leaderboard[9] />
17+
<${Table} heading="Bermuda Triangle" showDartsThrown=false players=input.players stats=input.leaderboard[10] />
18+
</div>
19+
<div class="row">
20+
<${Table} heading="420" showDartsThrown=false players=input.players stats=input.leaderboard[11] />
21+
<${Table} heading="Kill Bull" players=input.players stats=input.leaderboard[12] />
22+
</div>
23+
<div class="row">
24+
<${Table} heading="JDC Practice" showDartsThrown=false players=input.players stats=input.leaderboard[14] />
25+
</div>

src/pages/leaderboard/components/leaderboard/leaderboard.component.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ const _ = require('underscore');
22

33
module.exports = {
44
onCreate(input) {
5-
const leaderboard = _.sortBy(input.leaderboard, 'three_dart_avg').reverse();
6-
const checkouts = _.sortBy(input.leaderboard, 'checkout').reverse();
5+
const x01Leaderboard = _.sortBy(input.x01Leaderboard, 'three_dart_avg').reverse();
6+
const checkouts = _.sortBy(input.x01Leaderboard, 'checkout').reverse();
77

88
this.state = {
99
officeId: 0,
10-
statistics: leaderboard,
11-
checkouts: checkouts
10+
statistics: x01Leaderboard,
11+
checkouts: checkouts,
12+
matchTypesLeaderboard: input.matchTypesLeaderboard
1213
}
1314
},
1415
officeChanged(officeId) {
15-
let statistics = this.input.leaderboard;
16-
let checkouts = this.input.leaderboard;
16+
let statistics = this.input.x01Leaderboard;
17+
let checkouts = this.input.x01Leaderboard;
1718
if (officeId != 0) {
18-
statistics = _.reject(this.input.leaderboard, (stats) => stats.office_id != officeId);
19-
checkouts = _.reject(this.input.leaderboard, (stats) => stats.office_id != officeId);
19+
statistics = _.reject(this.input.x01Leaderboard, (stats) => stats.office_id != officeId);
20+
checkouts = _.reject(this.input.x01Leaderboard, (stats) => stats.office_id != officeId);
2021
}
2122
this.state.statistics = _.sortBy(statistics, 'three_dart_avg').reverse();
2223
this.state.checkouts = _.sortBy(checkouts, 'checkout').reverse();

src/pages/leaderboard/components/leaderboard/leaderboard.marko

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ $ let weeks_str = input.defaults.leaderboard_active_period_weeks == 1 ? `week` :
66
<ul class="nav nav-tabs">
77
<li role="presentation" class="active"><a href="#overall" data-toggle="tab">Overall</a></li>
88
<li role="presentation"><a href="#checkouts" data-toggle="tab">Checkouts</a></li>
9+
<li role="presentation"><a href="#match-types" data-toggle="tab">Match Types</a></li>
910
</ul>
1011
</div>
1112
<div class="tab-content" style="width: 100%;">
@@ -15,5 +16,8 @@ $ let weeks_str = input.defaults.leaderboard_active_period_weeks == 1 ? `week` :
1516
<div class=`tab-pane` role="tabpanel" id="checkouts">
1617
<checkouts-table statistics=state.checkouts players=input.players />
1718
</div>
19+
<div class=`tab-pane` role="tabpanel" id="match-types">
20+
<match-type-leaderboard leaderboard=state.matchTypesLeaderboard matchTypes=input.matchTypes players=input.players />
21+
</div>
1822
</div>
1923
</div>

src/pages/leaderboard/leaderboard-template.marko

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import Layout from "../layout.marko"
22

33
<${Layout}>
44
<@body>
5-
<leaderboard players=input.players offices=input.offices defaults=input.defaults leaderboard=input.leaderboard />
5+
<leaderboard players=input.players offices=input.offices matchTypes=input.matchTypes defaults=input.defaults x01Leaderboard=input.x01Leaderboard matchTypesLeaderboard=input.matchTypesLeaderboard />
66
</@body>
77
</>

0 commit comments

Comments
 (0)