X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitrpg/src/web.nit b/contrib/nitrpg/src/web.nit index 459df8c..5f4992e 100644 --- a/contrib/nitrpg/src/web.nit +++ b/contrib/nitrpg/src/web.nit @@ -56,8 +56,8 @@ class RpgAction # Returns the game with `name` or null if no game exists with this name. fun load_game(name: String): nullable Game do - var repo = new Repo(api, name) - if api.was_error then return null + var repo = api.load_repo(name) + if api.was_error or repo == null then return null var game = new Game(api, repo) game.root_url = root_url return game @@ -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 @@ -156,6 +175,11 @@ class GameAction # From where to start the display of events related lists. var list_from = 0 + + # TODO should also check 201, 203 ... + private fun is_response_error(response: HttpResponse): Bool do + return response.status_code != 200 + end end # Repo overview page. @@ -164,6 +188,7 @@ class RepoHome redef fun answer(request, url) do var rsp = prepare_response(request, url) + if is_response_error(rsp) then return rsp page.side_panels.add new ShortListPlayersPanel(game) page.flow_panels.add new PodiumPanel(game) page.flow_panels.add new EventListPanel(game, list_limit, list_from) @@ -179,6 +204,7 @@ class ListPlayers redef fun answer(request, url) do var rsp = prepare_response(request, url) + if is_response_error(rsp) then return rsp page.breadcrumbs.add_link(game.url / "players", "players") page.flow_panels.add new ListPlayersPanel(game) rsp.body = page.write_to_string @@ -192,6 +218,7 @@ class PlayerHome redef fun answer(request, url) do var rsp = prepare_response(request, url) + if is_response_error(rsp) then return rsp var name = request.param("player") if name == null then var msg = "Bad request: should look like /:owner/:repo/:players/:name." @@ -219,6 +246,7 @@ class ListAchievements redef fun answer(request, url) do var rsp = prepare_response(request, url) + if is_response_error(rsp) then return rsp page.breadcrumbs.add_link(game.url / "achievements", "achievements") page.flow_panels.add new AchievementsListPanel(game) rsp.body = page.write_to_string @@ -232,6 +260,7 @@ class AchievementHome redef fun answer(request, url) do var rsp = prepare_response(request, url) + if is_response_error(rsp) then return rsp var name = request.param("achievement") if name == null then var msg = "Bad request: should look like /:owner/:repo/achievements/:achievement." @@ -270,6 +299,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