# This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2014-2015 Alexandre Terrasa # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Panels templates for `nitpg`. module panels import templates_events import markdown # A panel can be displayed in a html page. # # This display a Bootstrap panel. class Panel super Template redef fun rendering do add """

""" render_title add """

""" render_body add """
""" end # Render the panel title. # Betweem `

` tags. fun render_title do end # Render the panel body. fun render_body do end end # A panel that contain only a table as body. class TablePanel super Panel redef fun rendering do add """

""" render_title add """

""" render_body add """
""" end end # Display an error message within a panel. class ErrorPanel super Panel redef fun rendering do add """

""" render_title add """

""" render_body add """
""" end # The error message to display as panel body. var msg: String redef fun render_title do add "  " add "Error" end redef fun render_body do add msg.html_escape end end # A panel that display a markdown content rendered as HTML. class MDPanel super Panel # Markdown text to display. var text: String redef fun rendering do add """
{{{text.md_to_html}}}
""" end end # Display a list of active game. # # Used for NitRPG homepage. class GamesShortListPanel super Panel # Root url used for links. var root_url: String # List of NitRPG games to display. var games: Array[Game] redef fun render_title do add "  " add "Active games" end redef fun render_body do if games.is_empty then add "No game yet..." return end var sorted = games.to_a (new GamePlayersComparator).sort(sorted) for game in sorted do add "{game.link} ({game.load_players.length} players)
" end end end # A panel that display a list of player in a repo. class GamesListPanel super GamesShortListPanel super TablePanel redef fun render_title do add "  " add "Active games" end redef fun render_body do if games.is_empty then add "
" add "No player yet..." add "
" return end var sorted = games.to_a (new GamePlayersComparator).sort(sorted) add """""" for game in sorted do add "" add " " add " " add " " add "" end add "
Game Players Achievements
{game.link}{game.load_players.length}{game.load_achievements.length}
" end end # A panel that display repo statistics. class GameStatusPanel super Panel # Repo to display. var game: Game redef fun render_title do add "  " add "{game.link}" end redef fun render_body do add "{game.load_players.length}" add " players
" add "{game.stats["achievements"]}" add " achievements

" add "{game.stats["pulls"]} pull requests" add " ({game.stats["pulls_open"]} open)
" add "{game.stats["issues"]} issues" add " ({game.stats["issues_open"]} open)
" add "{game.stats["commits"]} commits" end end # Player status panel. class PlayerStatusPanel super Panel # Game instance. var game: Game # Target player. var player: Player redef fun render_title do add "" add " \"{player.name}\"" add "  {player.link}" end redef fun render_body do var ranking = game.player_ranking # TODO player.rank add "

ranked " add " # {ranking[player.name]}

" add "{player.nitcoins} nitcoins

" add "{player.stats["achievements"]} achievements

" add "{player.stats["pulls"]} pull requests
" add "{player.stats["issues"]} issues
" add "{player.stats["commits"]} commits" end end # A panel that display a list of player in a repo. class ShortListPlayersPanel super Panel # Game instance. var game: Game redef fun render_title do add "  " add "Players" end redef fun render_body do var players = game.load_players.values.to_a if players.is_empty then add "No player yet..." return end (new PlayerCoinComparator).sort(players) for player in players do add "{player.nitcoins} - {player.link}
" end end end # A panel that display a list of player in a repo. class ListPlayersPanel super TablePanel # Game instance. var game: Game redef fun render_title do add "  " add "Players" end redef fun render_body do var players = game.load_players.values.to_a (new PlayerCoinComparator).sort(players) if players.is_empty then add "
" add "No player yet..." add "
" return end add """""" var rank = 1 for player in players do add "" add " " add " " add " " add "" rank += 1 end add "
# Player Nitcoins
{rank}{player.link}{player.nitcoins}
" end end # A panel that display the podium. class PodiumPanel super Panel # Game instance. var game: Game redef fun render_title do add "  Hall of fame" end redef fun render_body do var players = game.load_players.values.to_a (new PlayerCoinComparator).sort(players) if players.is_empty then add "No players yet..." return end add """
""" var max = players.first.nitcoins var orders = [3, 1, 0, 2, 4] for order in orders do if order >= players.length then continue var player = players[order] var size = 0 if max > 0 then size = player.nitcoins * 300 / max add """

{{{player.name}}}

{{{player.link}}}

{{{player.nitcoins}}}

""" end add """
""" end end # A `Panel` that displays the list of PR to review for a `Player`. class PlayerReviewsPanel super Panel # Repo to display. var game: Game # Player to display customized list for. var player: Player redef fun render_title do add "  " add "Review pull requests and comment issues to gain nitcoins!" end redef fun render_body do var q = "is:open label:need_review sort:updated-asc " + "-involves:{player.name}" var q2 = "is:open label:request_for_comments sort:updated-asc " + "-involves:{player.name}" var issues = new ArraySet[Issue] issues.add_all game.repo.search_issues(q).as(not null) issues.add_all game.repo.search_issues(q2).as(not null) if issues.is_empty then add "No pull request or issue to review yet..." return end for issue in issues do var user = issue.user var uplay = user.player(game) add """
{{{uplay.name}}}

{{{issue.link}}} {{{issue.title}}}

opened by {{{uplay.link}}}
""" end end end # A `Panel` that displays a pagined list of events stored in the `entity`. # # This way the panel can be used to view events stored under `Game`, `Player`... class EventListPanel super Panel # Entity to load the events from. var entity: GameEntity # Number of events to display. var limit: Int # From where to start? var from: Int redef fun render_title do add "  " add "Last events" end redef fun render_body do var events = entity.load_events if events.is_empty then add "No event yet..." return end # check input if limit < 0 then limit = 10 if from < 0 then from = 0 # display events for i in [from .. from + limit] do if i >= events.length then break add events[i].tpl_event.media_item end # pagination if limit > events.length then return add "
" add """
""" if from > 0 then add """ """ end if from + limit < events.length then add """ """ end add "
" end end # Achievement unlocked list panel. class AchievementsListPanel super Panel # Entity to load the events from. var entity: GameEntity redef fun render_title do add "  " add "Achievements unlocked" end redef fun render_body do var achs = entity.load_achievements.values.to_a if achs.is_empty then add "No achievement yet..." return end for ach in achs do add ach.list_item end end # Achievement detail panel. class AchievementPanel super Panel # Achievement to display. var achievement: Achievement redef fun render_title do add "  " add "Achievement details" end redef fun render_body do add """

+{{{achievement.reward}}} {{{achievement.name}}}

{{{achievement.desc}}}

""" var events = achievement.load_events if events.is_empty then add "Never unlocked..." return end var event = events.last var tpl = event.tpl_event var player = tpl.player add "
" add """
#1 {{{player.name}}}

Unlocked first by {{{player.link}}}

at {{{event.time}}}
""" if events.length > 1 then add """


Also unlocked by {{{events.length}}} players.

""" end end end