get rid of round play JS router - closes #964

This commit is contained in:
Thibault Duplessis 2015-09-19 16:35:12 +02:00
parent 18688a3646
commit 316fbbba16
17 changed files with 32 additions and 46 deletions

View file

@ -11,12 +11,10 @@
@moreJs = {
@jsTagCompiled("chart2.js")
@jsAt(s"compiled/lichess.analyse${isProd??(".min")}.js")
@round.jsRoutes()
@embedJs {
lichess = lichess || {};
lichess.analyse = {
data: @Html(play.api.libs.json.Json.stringify(data)),
routes: roundRoutes.controllers,
i18n: @round.jsI18n(),
userId: @Html(ctx.userId.fold("null")(id => s""""$id""""))
};

View file

@ -6,12 +6,10 @@
@moreJs = {
@jsAt(s"compiled/lichess.analyse${isProd??(".min")}.js")
@round.jsRoutes()
@embedJs {
lichess = lichess || {};
lichess.user_analysis = {
data: @Html(play.api.libs.json.Json.stringify(data)),
routes: roundRoutes.controllers,
i18n: @Html(J.stringify(i18nJsObject(
trans.flipBoard,
trans.backToGame,

View file

@ -1,12 +0,0 @@
@()(implicit ctx: Context)
@helper.javascriptRouter("roundRoutes")(
routes.javascript.Round.watcher,
routes.javascript.Round.playerText,
routes.javascript.Round.watcherText,
routes.javascript.Round.sidesWatcher,
routes.javascript.Round.sidesPlayer,
routes.javascript.Round.continue,
routes.javascript.Round.next,
routes.javascript.Round.whatsNext,
routes.javascript.UserAnalysis.game
)(ctx.req)

View file

@ -6,12 +6,10 @@
@moreJs = {
@jsAt(s"compiled/lichess.round${isProd??(".min")}.js")
@jsRoutes()
@embedJs {
$(function() {
lichess.startRound(document.getElementById('lichess'), {
data: @Html(J.stringify(data)),
routes: roundRoutes.controllers,
i18n: @jsI18n(),
userId: @Html(ctx.userId.fold("null")(id => s""""$id""""))
});

View file

@ -4,12 +4,10 @@
@moreJs = {
@jsAt(s"compiled/lichess.round${isProd??(".min")}.js")
@jsRoutes()
@embedJs {
$(function() {
lichess.startRound(document.getElementById('lichess'), {
data: @Html(J.stringify(data)),
routes: roundRoutes.controllers,
i18n: @jsI18n()
});
});

View file

@ -4,12 +4,10 @@
@moreJs = {
@jsAt(s"compiled/lichess.round${isProd??(".min")}.js")
@round.jsRoutes()
@embedJs {
$(function() {
lichess.startRound(document.getElementById('lichess'), {
data: @Html(play.api.libs.json.Json.stringify(data)),
routes: roundRoutes.controllers,
i18n: @round.jsI18n()
});
});

View file

@ -1277,9 +1277,7 @@ lichess.unique = function(xs) {
o.player ? o.player.name + ' (' + o.player.rating + ')' : 'Anonymous');
},
end: function() {
var url = data.tv ? ['/tv', data.tv.channel, data.game.id, data.player.color, 'sides'].join('/') : ((
data.player.spectator ? cfg.routes.Round.sidesWatcher : cfg.routes.Round.sidesPlayer
)(data.game.id, data.player.color).url);
var url = '/' + (data.tv ? ['tv', data.tv.channel, data.game.id, data.player.color, 'sides'] : [data.game.id, data.player.color, 'sides', data.player.spectator ? 'watcher' : 'player']).join('/');
$.ajax({
url: url,
cache: false,

View file

@ -1,4 +1,5 @@
var partial = require('chessground').util.partial;
var router = require('game').router;
var m = require('mithril');
var baseSpeeds = [{
@ -45,7 +46,7 @@ module.exports = {
view: function(ctrl) {
var flipAttrs = {};
if (ctrl.data.userAnalysis) flipAttrs.onclick = ctrl.flip;
else flipAttrs.href = ctrl.router.Round.watcher(ctrl.data.game.id, ctrl.data.opponent.color).url + '#' + ctrl.vm.step.ply;
else flipAttrs.href = router.game(ctrl.data, ctrl.data.opponent.color) + '#' + ctrl.vm.step.ply;
return m('div.action_menu',
m('div.inner', [
@ -69,12 +70,12 @@ module.exports = {
deleteButton(ctrl.data, ctrl.userId),
m('div.continue_with.' + ctrl.data.game.id, [
m('a.button', {
href: ctrl.data.userAnalysis ? '/?fen=' + ctrl.encodeStepFen() + '#ai' : ctrl.router.Round.continue(ctrl.data.game.id, 'ai').url + '?fen=' + ctrl.vm.step.fen,
href: ctrl.data.userAnalysis ? '/?fen=' + ctrl.encodeStepFen() + '#ai' : router.continue(ctrl.data, 'ai') + '?fen=' + ctrl.vm.step.fen,
rel: 'nofollow'
}, ctrl.trans('playWithTheMachine')),
m('br'),
m('a.button', {
href: ctrl.data.userAnalysis ? '/?fen=' + ctrl.encodeStepFen() + '#friend' : ctrl.router.Round.continue(ctrl.data.game.id, 'friend').url + '?fen=' + ctrl.vm.step.fen,
href: ctrl.data.userAnalysis ? '/?fen=' + ctrl.encodeStepFen() + '#friend' : router.continue(ctrl.data, 'friend') + '?fen=' + ctrl.vm.step.fen,
rel: 'nofollow'
}, ctrl.trans('playWithAFriend'))
])

View file

@ -1,6 +1,9 @@
// #FIXME jQuery crap here
module.exports = function(el, ctrl) {
var route = ctrl.data.player.spectator ? ctrl.router.Round.watcherText(ctrl.data.game.id, ctrl.data.player.color) : ctrl.router.Round.playerText(ctrl.data.game.id + ctrl.data.player.id);
$(el).load(route.url);
var url = ctrl.data.player.spectator ?
router.game(ctrl.data, ctrl.data.player.color) :
router.player(ctrl.data);
url += '/text';
$(el).load(url);
};

View file

@ -189,8 +189,6 @@ module.exports = function(opts) {
this.socket = new socket(opts.socketSend, this);
this.router = opts.routes;
this.forecast = opts.data.forecast ? forecastCtrl(
opts.data.forecast,
router.forecasts(this.data)) : null;

View file

@ -2,7 +2,7 @@ var player = function(data) {
return '/' + data.game.id + data.player.id;
};
var game = function(data, color) {
return '/' + data.game.id + (color ? '/' + color : '');
return '/' + (data.game ? data.game.id : data) + (color ? '/' + color : '');
};
module.exports = {
@ -10,5 +10,8 @@ module.exports = {
player: player,
forecasts: function(data) {
return player(data) + '/forecasts';
},
continue: function(data, mode) {
return game(data) + '/continue/' + mode;
}
};

View file

@ -1,11 +1,15 @@
var throttle = require('./util').throttle;
var router = require('game').router;
// #FIXME jQuery crap here
var element;
var reload = throttle(1000, false, function(ctrl) {
var route = ctrl.data.player.spectator ? ctrl.router.Round.watcherText(ctrl.data.game.id, ctrl.data.player.color) : ctrl.router.Round.playerText(ctrl.data.game.id + ctrl.data.player.id);
var route = (ctrl.data.player.spectator ?
router.game(ctrl.data, ctrl.data.player.color) :
router.player(ctrl.data)
) + '/text';
$.ajax({
url: route.url,
cache: false,

View file

@ -334,8 +334,6 @@ module.exports = function(opts) {
return false;
}.bind(this);
this.router = opts.routes;
this.trans = function(key) {
var str = opts.i18n[key] || key;
Array.prototype.slice.call(arguments, 1).forEach(function(arg) {

View file

@ -1,5 +1,6 @@
var game = require('game').game;
var xhr = require('./xhr');
var router = require('game').router;
var m = require('mithril');
module.exports = function(ctrl, key) {
@ -35,10 +36,10 @@ module.exports = function(ctrl, key) {
this.next = function(force) {
if (!this.value || ctrl.data.player.spectator || ctrl.data.game.tournamentId || game.isPlayerTurn(ctrl.data)) return;
if (force) redirect(ctrl.router.Round.next(ctrl.data.game.id).url);
if (force) redirect('/round-next/' + ctrl.data.game.id);
else if (ctrl.data.simul) {
if (ctrl.data.simul.hostId === ctrl.userId && ctrl.data.simul.nbPlaying > 1)
redirect(ctrl.router.Round.next(ctrl.data.game.id).url)
redirect('/round-next/' + ctrl.data.game.id);
} else xhr.whatsNext(ctrl).then(function(data) {
if (data.next) redirect('/' + data.next);
}.bind(this));

View file

@ -3,6 +3,7 @@ var classSet = chessground.util.classSet;
var game = require('game').game;
var status = require('game').status;
var partial = chessground.util.partial;
var router = require('game').router;
var m = require('mithril');
module.exports = {
@ -145,7 +146,7 @@ module.exports = {
},
viewRematch: function(ctrl) {
if (ctrl.data.game.rematch) return m('a.viewRematch.button.text[data-icon=v]', {
href: ctrl.router.Round.watcher(ctrl.data.game.rematch, ctrl.data.opponent.color).url
href: router.game(ctrl.data.game.rematch, ctrl.data.opponent.color)
}, ctrl.trans('viewRematch'));
},
joinRematch: function(ctrl) {
@ -153,7 +154,7 @@ module.exports = {
ctrl.trans('rematchOfferAccepted'),
m('a.button.fat.hint--bottom', {
'data-hint': ctrl.trans('playWithTheSameOpponentAgain'),
href: ctrl.router.Round.watcher(ctrl.data.game.rematch, ctrl.data.opponent.color).url
href: router.game(ctrl.data.game.rematch, ctrl.data.opponent.color)
}, ctrl.trans('joinTheGame'))
];
},
@ -185,7 +186,7 @@ module.exports = {
var hash = ctrl.replaying() ? '#' + ctrl.vm.ply : '';
if (game.replayable(ctrl.data)) return m('a.button.replay_and_analyse', {
onclick: partial(ctrl.socket.send, 'rematch-no', null),
href: ctrl.router.Round.watcher(ctrl.data.game.id, ctrl.data.player.color).url + hash
href: router.game(ctrl.data, ctrl.data.player.color) + hash
}, ctrl.trans('analysis'));
},
newOpponent: function(ctrl) {

View file

@ -3,6 +3,7 @@ var classSet = require('chessground').util.classSet;
var game = require('game').game;
var status = require('game').status;
var renderStatus = require('game').view.status;
var router = require('game').router;
var m = require('mithril');
var emptyTd = m('td.move', '...');
@ -92,7 +93,7 @@ function analyseButton(ctrl) {
'glowed': showInfo
}),
'data-hint': ctrl.trans('analysis'),
href: ctrl.router.UserAnalysis.game(ctrl.data.game.id, ctrl.data.player.color).url + '#' + ctrl.vm.ply,
href: router.game(ctrl.data, ctrl.data.player.color) + '/analysis#' + ctrl.vm.ply,
config: showInfo ? function(el) {
setTimeout(function() {
$(el).powerTip({
@ -119,7 +120,7 @@ function renderButtons(ctrl) {
'data-hint': ctrl.trans('flipBoard'),
};
if (ctrl.data.tv) flipAttrs.href = '/tv/' + ctrl.data.tv.channel + (ctrl.data.tv.flip ? '' : '?flip=1');
else if (ctrl.data.player.spectator) flipAttrs.href = ctrl.router.Round.watcher(ctrl.data.game.id, ctrl.data.opponent.color).url;
else if (ctrl.data.player.spectator) flipAttrs.href = router.game(ctrl.data, ctrl.data.opponent.color);
else flipAttrs.onclick = ctrl.flip;
return m('div.buttons', [
m('a', flipAttrs, m('span[data-icon=B]')), [

View file

@ -1,4 +1,5 @@
var m = require('mithril');
var router = require('game').router;
var xhrConfig = function(xhr) {
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
@ -15,8 +16,7 @@ function reload(ctrl) {
url: uncache(ctrl.data.url.round),
config: xhrConfig
});
req.then(function() {
}, function(err) {
req.then(function() {}, function(err) {
lichess.reload();
});
return req;
@ -25,7 +25,7 @@ function reload(ctrl) {
function whatsNext(ctrl) {
return m.request({
method: 'GET',
url: uncache(ctrl.router.Round.whatsNext(ctrl.data.game.id).url),
url: uncache('/whats-next/' + ctrl.data.game.id),
config: xhrConfig
});
}