Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
feat(tournaments): Clicking on match title will display popup of matc…
Browse files Browse the repository at this point in the history
…h summary

closes #87
  • Loading branch information
Autalyst committed Nov 24, 2015
1 parent d6fe5f3 commit baea6b8
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 27 deletions.
15 changes: 15 additions & 0 deletions src/jade/partials/dialogs/bracket-information.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

script(type="text/ng-template", id="/dialog/bracket-information")
md-dialog

.md-dialog-content
h2.md-title Match {{ title }}

md-list
md-list-item.md-2-line(ng-repeat="player in players")
.md-avatar.subhead {{ player.ordinal }}
.md-list-item-text
h3 {{ player.displayName }}
Total Points Scored: {{ player.score }}
.md-actions
md-button.md-primary(ng-click="cancel()", aria-label="close") Close
6 changes: 2 additions & 4 deletions src/jade/partials/dialogs/results.jade
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

script(type="text/ng-template", id="/dialog/results")
md-dialog

h2.md-title Results for {{tournamentName}}
.md-dialog-content
h2.md-title Results for {{tournamentName}}

md-list
md-list-item.md-2-line(ng-repeat="result in results")
.md-avatar.subhead {{toOrdinal(result.pos)}}
Expand All @@ -13,4 +11,4 @@ script(type="text/ng-template", id="/dialog/results")
p Wins: {{result.wins}}, Total Points Scored: {{result.for}}

.md-actions
md-button.md-primary(ng-click="cancel()", aria-label="close") Close
md-button.md-primary(ng-click="cancel()", aria-label="close") Close
4 changes: 2 additions & 2 deletions src/jade/partials/tournaments/types/duel.jade
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ script(type="text/ng-template", id="tournament-duel")

.match-data(ng-if="!noRender(match) && shouldMatchBeShown(match)", layout="row", layout-align="center center")
.round-type(flex, layout="column", layout-align="space-around center", background-highlight="!invalidMatch(match) && !match.m")
.subhead {{getMatchIdString(match)}}
.subhead(ng-click="showBracketInformation($event, match)") {{getMatchIdString(match)}}
station(value="ref.stations[getMatchStationIdString(match)]", can-click="{{hasAccess}}", on-unedit="save()")

.match-name(layout="column")
Expand All @@ -40,4 +40,4 @@ script(type="text/ng-template", id="tournament-duel")
.score-value -

.margin-right-10.margin-left-10.confirm-score(flex, layout="column", layout-align="center center")
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
4 changes: 2 additions & 2 deletions src/jade/partials/tournaments/types/ffa.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ script(type="text/ng-template", id="tournament-ffa")

.match-data(ng-if="!noRender(match)", layout="row", layout-align="center center")
.round-type(flex, layout="column", layout-align="space-around center", background-highlight="!invalidMatch(match) && !match.m")
.subhead {{getMatchIdString(match)}}
.subhead(ng-click="showBracketInformation($event, match)") {{getMatchIdString(match)}}
station(value="ref.stations[getMatchStationIdString(match)]", can-click="{{hasAccess}}", on-unedit="save()")

.match-name(layout="column")
Expand All @@ -38,4 +38,4 @@ script(type="text/ng-template", id="tournament-ffa")
.score-value -

div.margin-right-10.margin-left-10.confirm-score
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
4 changes: 2 additions & 2 deletions src/jade/partials/tournaments/types/groupstage.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ script(type="text/ng-template", id="tournament-groupstage")

.match-data(ng-if="!noRender(match)", layout="row", layout-align="center center")
.round-type(flex, layout="column", layout-align="space-around center", background-highlight="!invalidMatch(match) && !match.m")
.subhead {{getMatchIdString(match)}}
.subhead(ng-click="showBracketInformation($event, match)") {{getMatchIdString(match)}}
station(value="ref.stations[getMatchStationIdString(match)]", can-click="{{hasAccess}}", on-unedit="save()")

.match-name(layout="column")
Expand All @@ -38,4 +38,4 @@ script(type="text/ng-template", id="tournament-groupstage")
.score-value -

div.margin-right-10.margin-left-10.confirm-score
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
4 changes: 2 additions & 2 deletions src/jade/partials/tournaments/types/masters.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ script(type="text/ng-template", id="tournament-masters")

.match-data(ng-if="!noRender(match)", layout="row", layout-align="center center")
.round-type(flex, layout="column", layout-align="space-around center", background-highlight="!invalidMatch(match) && !match.m")
.subhead {{getMatchIdString(match)}}
.subhead(ng-click="showBracketInformation($event, match)") {{getMatchIdString(match)}}
station(value="ref.stations[getMatchStationIdString(match)]", can-click="{{hasAccess}}", on-unedit="save()")

.match-name(layout="column")
Expand All @@ -38,4 +38,4 @@ script(type="text/ng-template", id="tournament-masters")
.score-value -

div.margin-right-10.margin-left-10.confirm-score
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
ng-md-icon(size="24", icon="check_circle", ng-click="confirmScore(match)", ng-if="!invalidMatch(match) && !scoresEqual(match)", style="fill: {{match.m ? '#ccc' : '#000'}}")
2 changes: 2 additions & 0 deletions src/js/_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import './services/auth';
import './services/shareToken';
import './services/tournamentInformation';
import './services/urlShorten';
import './services/placeService';

import './services/currents/currentUsers';
import './services/currents/currentEvents';
Expand Down Expand Up @@ -61,6 +62,7 @@ import './controllers/dialogs/inputPromptCtrl';
import './controllers/dialogs/sharePromptCtrl';
import './controllers/dialogs/selectPromptCtrl';
import './controllers/dialogs/resultsDialogCtrl';
import './controllers/dialogs/bracketInformationCtrl';

import './filters/rawHtml.js';
import './routes';
40 changes: 40 additions & 0 deletions src/js/controllers/dialogs/bracketInformationCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import site from '../../app';

site.controller('bracketInformationController', ($scope, $mdDialog, $filter, placeService, title, match, players) => {

$scope.title = title;
$scope.cancel = $mdDialog.cancel;
$scope.players = [];

for(let i = 0; i < match.score.length; i++) {
const player = players[match.p[i] - 1];
$scope.players.push({
displayName: player.alias ? `${player.alias} (${player.name})` : player.name,
score: match.score[i]
});
}

$scope.players = $filter('orderBy')($scope.players, 'score', true);

// state machine for determining ordinals ('1st', '2nd' and so on)
const state = (() => {
let lastScore = 0;
let currentPlace = 0;
let ordinal = placeService.getPlaceString(1);
return {
getOrdinal: (score) => {
currentPlace++;
if(lastScore === score) {
return ordinal;
}

lastScore = score;
return ordinal = placeService.getPlaceString(currentPlace);
}
};
})();

_.each($scope.players, (player) => {
player.ordinal = state.getOrdinal(player.score);
});
});
10 changes: 3 additions & 7 deletions src/js/controllers/dialogs/resultsDialogCtrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import site from '../../app';

site.controller('resultsDialogController', ($scope, $mdDialog, tournamentName, results, players) => {
site.controller('resultsDialogController', ($scope, $mdDialog, tournamentName, results, players, placeService) => {

$scope.cancel = $mdDialog.cancel;

Expand All @@ -14,9 +14,5 @@ site.controller('resultsDialogController', ($scope, $mdDialog, tournamentName, r
return player.name;
};

$scope.toOrdinal = (num) => {
const s = ['th', 'st', 'nd', 'rd'];
const v = num % 100;
return num + (s[(v-20)%10] || s[v] || s[0]);
};
});
$scope.toOrdinal = placeService.getPlaceString;
});
32 changes: 24 additions & 8 deletions src/js/controllers/tournaments/inProgressCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb

$scope.includedTemplate = 'duel';

$scope.doOrOpen = (event) => $scope.isOpen && $scope.trn.isDone() ? $scope.showResults(event) : $scope.isOpen = true;
const showResults = (event) => {
const mdDialogOptions = {
controller: 'resultsDialogController',
focusOnOpen: false,
templateUrl: '/dialog/results',
event,
locals: {
tournamentName: $scope.tournamentName,
results: $scope.trn.results(),
players: $scope.bucket
}
};

$mdDialog.show(mdDialogOptions);
};

$scope.doOrOpen = (event) => $scope.isOpen && $scope.trn.isDone() ? showResults(event) : $scope.isOpen = true;

$scope.share = (service) => {
const services = {
Expand All @@ -52,19 +68,19 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb
return hash[options.type];
};

$scope.showResults = (event) => {
$scope.showBracketInformation = (event, match) => {
const mdDialogOptions = {
controller: 'resultsDialogController',
controller: 'bracketInformationController',
focusOnOpen: false,
templateUrl: '/dialog/results',
templateUrl: '/dialog/bracket-information',
event,
locals: {
tournamentName: $scope.tournamentName,
results: $scope.trn.results(),
title: $scope.getMatchIdString(match),
match: match,
players: $scope.bucket
}
};

$mdDialog.show(mdDialogOptions);
};

Expand Down Expand Up @@ -165,4 +181,4 @@ site.controller('inProgressController', ($scope, $timeout, EnsureLoggedIn, Sideb
}
});

});
});
12 changes: 12 additions & 0 deletions src/js/services/placeService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import site from '../app';

site.service('placeService', () => {

This comment has been minimized.

Copy link
@seiyria

seiyria Nov 24, 2015

Owner

Bit of a gotcha, but all of the services are ProperCase, to distinguish them from other things (ie, locals) upon being injected.


return {
getPlaceString: (numberPlace) => {
const postStrings = ['th', 'st', 'nd', 'rd'];
const baseNumber = numberPlace % 100;
return numberPlace + (postStrings[(baseNumber - 20) % 10] || postStrings[baseNumber] || postStrings[0]);
}
};
});

0 comments on commit baea6b8

Please sign in to comment.