1.1 --- a/freemarkerdor/pom.xml Fri Sep 11 20:32:15 2009 +0200
1.2 +++ b/freemarkerdor/pom.xml Fri Sep 11 22:25:21 2009 +0200
1.3 @@ -100,7 +100,8 @@
1.4 </plugin>
1.5 </plugins>
1.6 </build>
1.7 - <version>1.2</version>
1.8 + <version>1.3</version>
1.9 </project>
1.10
1.11
1.12 +
2.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Fri Sep 11 20:32:15 2009 +0200
2.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Fri Sep 11 22:25:21 2009 +0200
2.3 @@ -267,6 +267,7 @@
2.4 map.put("doc", doc);
2.5 map.put("user", user);
2.6 map.put("bundle", rb);
2.7 + map.put("now", System.currentTimeMillis());
2.8 for (int i = 0; i < more.length; i += 2) {
2.9 map.put((String)more[i],more[i + 1]);
2.10 }
3.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 20:32:15 2009 +0200
3.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 22:25:21 2009 +0200
3.3 @@ -7,8 +7,26 @@
3.4 <body>
3.5 <h1>${bundle.TITLE}</h1>
3.6
3.7 + <#macro past t>
3.8 + <#if t < 60000>
3.9 + <#assign unit="s"/>
3.10 + <#assign value= t?float / 1000.0/>
3.11 + <#elseif t < 3600000>
3.12 + <#assign unit="min"/>
3.13 + <#assign value=t?float / 60000.0/>
3.14 + <#elseif t < 24 * 3600 * 1000>
3.15 + <#assign unit="h"/>
3.16 + <#assign value=t?float / 3600000.0/>
3.17 + <#else>
3.18 + <#assign unit="day"/>
3.19 + <#assign value=t?float / (24.0 * 3600000.0)/>
3.20 + </#if>
3.21 + ${value?float?string("0")} ${unit}
3.22 + </#macro>
3.23 +
3.24 <#macro game game>
3.25 - ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)} <a href="/games/${game.@id}/">${bundle.BOARD}</a>
3.26 + ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)}
3.27 + <a href="/games/${game.@id}/">${bundle.before} <@past (now - game.@modified?number)/></a>
3.28 </#macro>
3.29
3.30 <#if message?? >
4.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 20:32:15 2009 +0200
4.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 22:25:21 2009 +0200
4.3 @@ -9,4 +9,5 @@
4.4 GAME_ALL=All games
4.5 WHITE=White
4.6 BLACK=Black
4.7 +before=Before
4.8
5.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 20:32:15 2009 +0200
5.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 22:25:21 2009 +0200
5.3 @@ -9,3 +9,5 @@
5.4 GAME_ALL=V\u0161echny hry
5.5 WHITE=B\u00EDl\u00FD
5.6 BLACK=\u010Cern\u00FD
5.7 +before=P\u0159ed
5.8 +
6.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 20:32:15 2009 +0200
6.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 22:25:21 2009 +0200
6.3 @@ -31,12 +31,12 @@
6.4 import cz.xelfi.quoridor.Move;
6.5 import cz.xelfi.quoridor.Player;
6.6 import java.util.ArrayList;
6.7 +import java.util.Date;
6.8 import java.util.List;
6.9 import javax.xml.bind.annotation.XmlAccessType;
6.10 import javax.xml.bind.annotation.XmlAccessorType;
6.11 import javax.xml.bind.annotation.XmlAttribute;
6.12 import javax.xml.bind.annotation.XmlElement;
6.13 -import javax.xml.bind.annotation.XmlElements;
6.14 import javax.xml.bind.annotation.XmlRootElement;
6.15 import javax.xml.bind.annotation.adapters.XmlAdapter;
6.16 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
6.17 @@ -101,7 +101,7 @@
6.18 }
6.19
6.20 board = getBoard().apply(m);
6.21 - id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), GameStatus.valueOf(board));
6.22 + id = new GameId(id.getId(), id.getWhite(), id.getBlack(), new Date(id.getStarted()), new Date(), GameStatus.valueOf(board));
6.23 getMoves().add(m);
6.24 }
6.25
7.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 20:32:15 2009 +0200
7.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 22:25:21 2009 +0200
7.3 @@ -46,7 +46,9 @@
7.4 @XmlAttribute
7.5 private String black;
7.6 @XmlAttribute
7.7 - private Date started;
7.8 + private long started;
7.9 + @XmlAttribute
7.10 + private long modified;
7.11 @XmlAttribute
7.12 private GameStatus status;
7.13 @XmlID @XmlAttribute
7.14 @@ -56,17 +58,21 @@
7.15 }
7.16
7.17 public GameId(String first, String second) {
7.18 + this(first, second, new Date());
7.19 + }
7.20 + private GameId(String first, String second, Date d) {
7.21 this(
7.22 UUID.randomUUID().toString(),
7.23 - first, second, new Date(), GameStatus.whiteMove
7.24 + first, second, d, d, GameStatus.whiteMove
7.25 );
7.26 }
7.27
7.28 - public GameId(String id, String first, String second, Date started, GameStatus result) {
7.29 + public GameId(String id, String first, String second, Date started, Date last, GameStatus result) {
7.30 this.white = first;
7.31 this.black = second;
7.32 this.id = id;
7.33 - this.started = started;
7.34 + this.started = started.getTime();
7.35 + this.modified = last.getTime();
7.36 this.status = result;
7.37 }
7.38
7.39 @@ -82,10 +88,14 @@
7.40 return black;
7.41 }
7.42
7.43 - public Date getStarted() {
7.44 + public long getStarted() {
7.45 return started;
7.46 }
7.47
7.48 + public long getModified() {
7.49 + return modified;
7.50 + }
7.51 +
7.52 public GameStatus getStatus() {
7.53 return status;
7.54 }
8.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 20:32:15 2009 +0200
8.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 22:25:21 2009 +0200
8.3 @@ -188,7 +188,7 @@
8.4 throw new IOException("Missing white and black identification in " + f);
8.5 }
8.6 if (g == null) {
8.7 - GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameStatus.whiteMove);
8.8 + GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), new Date(f.lastModified()), GameStatus.whiteMove);
8.9 g = new Game(id);
8.10 }
8.11 if (line.equals("finish")) {
9.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java Fri Sep 11 20:32:15 2009 +0200
9.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java Fri Sep 11 22:25:21 2009 +0200
9.3 @@ -96,6 +96,13 @@
9.4 GameId s = webResource.path("games").queryParam("white", "Jarda")
9.5 .queryParam("black", "Jirka").post(GameId.class);
9.6
9.7 + Thread.sleep(100);
9.8 + final long now = System.currentTimeMillis();
9.9 + if (s.getModified() >= now) {
9.10 + fail("The game is supposed to be modified in past");
9.11 + }
9.12 + Thread.sleep(100);
9.13 +
9.14 String msg = webResource.path("games").get(String.class);
9.15 //List<Game> games = webResource.path("games").get(new GenericType<List<Game>>() {});
9.16
9.17 @@ -125,6 +132,9 @@
9.18 }
9.19 GameId s2 = webResource.path("games/" + s.getId()).queryParam("player", "Jirka").queryParam("move", "S").put(GameId.class);
9.20 assertNotNull("Successful move", s2);
9.21 + if (s2.getModified() <= now) {
9.22 + fail("The game is newly modified");
9.23 + }
9.24
9.25 File game = new File(new File(dir, "games"), s2.getId());
9.26 assertTrue("File for game exists", game.exists());