# HG changeset patch # User Jaroslav Tulach # Date 1252700721 -7200 # Node ID 5ea4172dcf8b53e297362187eb73851547c53b9a # Parent d574ac6e44cc36db51e420cb5c8db522c3a63e59 Showing the time that has passed since the last move on the board diff -r d574ac6e44cc -r 5ea4172dcf8b freemarkerdor/pom.xml --- a/freemarkerdor/pom.xml Fri Sep 11 20:32:15 2009 +0200 +++ b/freemarkerdor/pom.xml Fri Sep 11 22:25:21 2009 +0200 @@ -100,7 +100,8 @@ - 1.2 + 1.3 + diff -r d574ac6e44cc -r 5ea4172dcf8b freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Fri Sep 11 20:32:15 2009 +0200 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Fri Sep 11 22:25:21 2009 +0200 @@ -267,6 +267,7 @@ map.put("doc", doc); map.put("user", user); map.put("bundle", rb); + map.put("now", System.currentTimeMillis()); for (int i = 0; i < more.length; i += 2) { map.put((String)more[i],more[i + 1]); } diff -r d574ac6e44cc -r 5ea4172dcf8b freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 20:32:15 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 22:25:21 2009 +0200 @@ -7,8 +7,26 @@

${bundle.TITLE}

+ <#macro past t> + <#if t < 60000> + <#assign unit="s"/> + <#assign value= t?float / 1000.0/> + <#elseif t < 3600000> + <#assign unit="min"/> + <#assign value=t?float / 60000.0/> + <#elseif t < 24 * 3600 * 1000> + <#assign unit="h"/> + <#assign value=t?float / 3600000.0/> + <#else> + <#assign unit="day"/> + <#assign value=t?float / (24.0 * 3600000.0)/> + + ${value?float?string("0")} ${unit} + + <#macro game game> - ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)} ${bundle.BOARD} + ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)} + ${bundle.before} <@past (now - game.@modified?number)/> <#if message?? > diff -r d574ac6e44cc -r 5ea4172dcf8b freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 20:32:15 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 22:25:21 2009 +0200 @@ -9,4 +9,5 @@ GAME_ALL=All games WHITE=White BLACK=Black +before=Before diff -r d574ac6e44cc -r 5ea4172dcf8b freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 20:32:15 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 22:25:21 2009 +0200 @@ -9,3 +9,5 @@ GAME_ALL=V\u0161echny hry WHITE=B\u00EDl\u00FD BLACK=\u010Cern\u00FD +before=P\u0159ed + diff -r d574ac6e44cc -r 5ea4172dcf8b webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 20:32:15 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 22:25:21 2009 +0200 @@ -31,12 +31,12 @@ import cz.xelfi.quoridor.Move; import cz.xelfi.quoridor.Player; import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -101,7 +101,7 @@ } board = getBoard().apply(m); - id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), GameStatus.valueOf(board)); + id = new GameId(id.getId(), id.getWhite(), id.getBlack(), new Date(id.getStarted()), new Date(), GameStatus.valueOf(board)); getMoves().add(m); } diff -r d574ac6e44cc -r 5ea4172dcf8b webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 20:32:15 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 22:25:21 2009 +0200 @@ -46,7 +46,9 @@ @XmlAttribute private String black; @XmlAttribute - private Date started; + private long started; + @XmlAttribute + private long modified; @XmlAttribute private GameStatus status; @XmlID @XmlAttribute @@ -56,17 +58,21 @@ } public GameId(String first, String second) { + this(first, second, new Date()); + } + private GameId(String first, String second, Date d) { this( UUID.randomUUID().toString(), - first, second, new Date(), GameStatus.whiteMove + first, second, d, d, GameStatus.whiteMove ); } - public GameId(String id, String first, String second, Date started, GameStatus result) { + public GameId(String id, String first, String second, Date started, Date last, GameStatus result) { this.white = first; this.black = second; this.id = id; - this.started = started; + this.started = started.getTime(); + this.modified = last.getTime(); this.status = result; } @@ -82,10 +88,14 @@ return black; } - public Date getStarted() { + public long getStarted() { return started; } + public long getModified() { + return modified; + } + public GameStatus getStatus() { return status; } diff -r d574ac6e44cc -r 5ea4172dcf8b webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 20:32:15 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 22:25:21 2009 +0200 @@ -188,7 +188,7 @@ throw new IOException("Missing white and black identification in " + f); } if (g == null) { - GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameStatus.whiteMove); + GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), new Date(f.lastModified()), GameStatus.whiteMove); g = new Game(id); } if (line.equals("finish")) { diff -r d574ac6e44cc -r 5ea4172dcf8b webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java Fri Sep 11 20:32:15 2009 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java Fri Sep 11 22:25:21 2009 +0200 @@ -96,6 +96,13 @@ GameId s = webResource.path("games").queryParam("white", "Jarda") .queryParam("black", "Jirka").post(GameId.class); + Thread.sleep(100); + final long now = System.currentTimeMillis(); + if (s.getModified() >= now) { + fail("The game is supposed to be modified in past"); + } + Thread.sleep(100); + String msg = webResource.path("games").get(String.class); //List games = webResource.path("games").get(new GenericType>() {}); @@ -125,6 +132,9 @@ } GameId s2 = webResource.path("games/" + s.getId()).queryParam("player", "Jirka").queryParam("move", "S").put(GameId.class); assertNotNull("Successful move", s2); + if (s2.getModified() <= now) { + fail("The game is newly modified"); + } File game = new File(new File(dir, "games"), s2.getId()); assertTrue("File for game exists", game.exists());