optional analysis of imported games - closes #458

This commit is contained in:
Thibault Duplessis 2016-01-31 11:10:11 +07:00
parent f06941c769
commit 3755af9091
4 changed files with 25 additions and 11 deletions

View file

@ -21,7 +21,7 @@ object Importer extends LilaController {
Ok(html.game.importGame(failure))
},
data => env.importer(data, ctx.userId) map { game =>
if (game.analysable) Analyse.addCallbacks(game.id) {
if (data.analyse.isDefined && game.analysable) Analyse.addCallbacks(game.id) {
Env.analyse.analyser.getOrGenerate(
game.id,
ctx.userId | "lichess",

View file

@ -10,7 +10,7 @@ $("#import_game form").submit(function() {
var pgn = $(this).find('textarea').val();
var nbMoves = parseInt(pgn.replace(/\n/g, ' ').replace(/^.+\s(\d+)\..+$/, '$1'), 10);
var delay = 50;
var duration = nbMoves * delay * 2.1 + 1000;
var duration = nbMoves * delay * 2 + 500;
$(this).find('button').hide().end()
.find('.error').hide().end()
.find('.progression').show().animate({
@ -36,14 +36,21 @@ description = "When pasting a game PGN, you get a browsable replay, a computer a
a <strong>computer analysis</strong>, a <strong>game chat</strong> and a <strong>sharable URL</strong>.
</p>
<form class="import" action="@routes.Importer.sendGame()" method="post">
<label>
<label class="pgn">
<span>@trans.pasteThePgnStringHere() :</span>
@defining(form("pgn")) { field =>
<textarea name="@field.name" id="@field.id">@field.value</textarea>
@errMsg(field)
}
</label>
<button class="submit button" type="submit" data-icon="G"> @trans.importGame()</button>
<p class="analyse">
<span>
<input name="@form("analyse").name" id="import_analyse" class="cmn-toggle cmn-toggle-round" type="checkbox" />
<label for="import_analyse"></label>
</span>
<label for="import_analyse">@trans.requestAComputerAnalysis()</label>
</p>
<button class="submit text button" type="submit" data-icon="G">@trans.importGame()</button>
<div class="progression"></div>
</form>
</div>

View file

@ -12,17 +12,18 @@ import lila.game._
private[importer] final class DataForm {
lazy val importForm = Form(mapping(
"pgn" -> nonEmptyText.verifying("Invalid PGN", checkPgn _)
"pgn" -> nonEmptyText.verifying("Invalid PGN", checkPgn _),
"analyse" -> optional(nonEmptyText)
)(ImportData.apply)(ImportData.unapply))
private def checkPgn(pgn: String): Boolean =
ImportData(pgn).preprocess(none).isSuccess
ImportData(pgn, none).preprocess(none).isSuccess
}
private[importer] case class Result(status: Status, winner: Option[Color])
private[importer] case class Preprocessed(game: Game, moves: List[MoveOrDrop], result: Option[Result])
case class ImportData(pgn: String) {
case class ImportData(pgn: String, analyse: Option[String]) {
private type TagPicker = Tag.type => TagType

View file

@ -6,12 +6,12 @@
#import_game form {
font-size: 1.3em;
}
#import_game form label {
#import_game form label.pgn {
display: block;
margin-bottom: 2em;
margin-bottom: 1em;
}
#import_game form label span {
#import_game form label.pgn span {
display: block;
margin-bottom: 1em;
}
@ -22,8 +22,14 @@
padding: 0.5em;
font-size: 0.9em;
}
#import_game form .analyse > span {
float: left;
margin-right: 10px;
}
#import_game button.submit {
margin: auto;
margin: 1em auto 0 auto;
display: block;
font-size: 2em;
}