contrib/nitrpg: display the list of active games in /games
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 23 Feb 2015 12:54:23 +0000 (13:54 +0100)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 21 Apr 2015 23:37:49 +0000 (19:37 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

contrib/nitrpg/src/web.nit

index 459df8c..766af1a 100644 (file)
@@ -109,6 +109,25 @@ class RpgHome
        end
 end
 
+# Display the list of active game.
+class ListGames
+       super RpgAction
+
+       # Response page stub.
+       var page: NitRpgPage is noinit
+
+       redef fun answer(request, url) do
+               var games = load_games
+               var response = new HttpResponse(200)
+               page = new NitRpgPage(root_url)
+               page.breadcrumbs = new Breadcrumbs
+               page.breadcrumbs.add_link(root_url / "games", "games")
+               page.flow_panels.add new GamesListPanel(root_url, games)
+               response.body = page.write_to_string
+               return response
+       end
+end
+
 # An action that require a game.
 class GameAction
        super RpgAction
@@ -270,6 +289,7 @@ vh.routes.add new Route("/games/:owner/:repo/players", new ListPlayers(root))
 vh.routes.add new Route("/games/:owner/:repo/achievements/:achievement", new AchievementHome(root))
 vh.routes.add new Route("/games/:owner/:repo/achievements", new ListAchievements(root))
 vh.routes.add new Route("/games/:owner/:repo", new RepoHome(root))
+vh.routes.add new Route("/games", new ListGames(root))
 vh.routes.add new Route("/", new RpgHome(root))
 
 var fac = new HttpFactory.and_libevent