1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Panels templates for `nitpg`.
22 # A panel can be displayed in a html page.
24 # This display a Bootstrap panel.
28 redef fun rendering
do
29 add
"""<div class="panel panel-default">
30 <div class="panel-heading">
31 <h3 class="panel-title">"""
35 <div class="panel-body">"""
41 # Render the panel title.
42 # Betweem `<h4>` tags.
43 fun render_title
do end
45 # Render the panel body.
46 fun render_body
do end
49 # A panel that contain only a table as body.
53 redef fun rendering
do
54 add
"""<div class="panel panel-default">
55 <div class="panel-heading">
56 <h3 class="panel-title">"""
66 # Display an error message within a panel.
70 redef fun rendering
do
72 <div class="panel panel-danger">
73 <div class="panel-heading">
74 <h3 class="panel-title">"""
79 <div class="panel-body">"""
87 # The error message to display as panel body.
90 redef fun render_title
do
91 add
"<span class=\"glyphicon glyphicon-warning-sign\
"></span> "
95 redef fun render_body
do
101 # A panel that display repo statistics.
102 class GameStatusPanel
108 redef fun render_title
do
109 add
"<span class=\"glyphicon glyphicon-home\
"></span> "
110 add
"<a href=\"{game.url}\
">{game.name}</a>"
113 redef fun render_body
do
114 add
"<strong class=\"text-success\
">{game.load_players.length}</strong>"
115 add
" <a href=\"{game.url}/players\
">players</a><br>"
116 add
"<strong class=\"text-success\
">{game.stats["pulls"]}</strong> pull requests"
117 add
" (<strong>{game.stats["pulls_open"]}</strong> open)<br>"
118 add
"<strong class=\"text-success\
">{game.stats["issues"]}</strong> issues"
119 add
" (<strong>{game.stats["issues_open"]}</strong> open)<br>"
123 # Player status panel.
124 class PlayerStatusPanel
133 redef fun render_title
do
134 add
"<a href=\"{player.url}\
">"
135 add
" <img class=\"img-circle\
" style=\"width
: 30px\
""
136 add
" src=\"{player.user.avatar_url}\
" alt=\"{player.name}\
">"
137 add
"</a> "
138 add
"<a href=\"{player.url}\
">{player.name}</a>"
141 redef fun render_body
do
142 var ranking
= game
.player_ranking
144 add
"<p class=\"lead\
">ranked "
145 add
" <span class=\"text-success\
"># {ranking[player.name]}</span></p>"
146 add
"<strong class=\"text-success\
">{player.nitcoins}</strong> nitcoins<br>"
150 # A panel that display a list of player in a repo.
151 class ShortListPlayersPanel
157 redef fun render_title
do
158 add
"<span class=\"glyphicon glyphicon-user\
"></span> "
159 add
"<a href=\"{game.url}/players\
">Players</a>"
162 redef fun render_body
do
163 var players
= game
.load_players
.values
.to_a
164 if players
.is_empty
then
165 add
"<em>No player yet...</em>"
168 (new PlayerCoinComparator).sort
(players
)
169 for player
in players
do
170 add
"<a href=\"{player.url}\
">"
172 add
"</a> ({player.nitcoins})<br>"
177 # A panel that display a list of player in a repo.
178 class ListPlayersPanel
184 redef fun render_title
do
185 add
"<span class=\"glyphicon glyphicon-user\
"></span> "
186 add
"<a href=\"{game.url}/players\
">Players</a>"
189 redef fun render_body
do
190 var players
= game
.load_players
.values
.to_a
191 (new PlayerCoinComparator).sort
(players
)
192 if players
.is_empty
then
193 add
"<div class=\"panel-body\
">"
194 add
"<em>No player yet...</em>"
198 add
"""<table class="table table-striped table-hover">
205 for player
in players
do
207 add
" <td>{rank}</td>"
208 add
" <td><a href=\"{player.url}\
">{player.name}</a></td>"
209 add
" <td>{player.nitcoins}</td>"
217 # A panel that display the podium.
224 redef fun render_title
do
225 add
"<span class=\"glyphicon glyphicon-stats\
"></span> Hall of fame"
228 redef fun render_body
do
229 var players
= game
.load_players
.values
.to_a
230 (new PlayerCoinComparator).sort
(players
)
231 if players
.is_empty
then
232 add
"<em>No players yet...</em>"
236 <div class="container-fluid">
237 <div id="podium" class="row row-sm-height">"""
238 var max
= players
.first
.nitcoins
239 var orders
= [3, 1, 0, 2, 4]
240 for order
in orders
do
241 if order
>= players
.length
then continue
242 var player
= players
[order
]
244 if max
> 0 then size
= player
.nitcoins
* 300 / max
246 <div class="col-xs-2 col-xs-height col-xs-offset-{{{order}}} col-bottom"
247 style="text-align: center;">
249 <a href="{{{player.url}}}">
250 <img class="img-circle" style="width: 80px"
251 src="{{{player.user.avatar_url}}}" alt="{{{player.name}}}">
254 <p><a href="{{{player.url}}}">{{{player.name}}}</a></p>
255 <p>{{{player.nitcoins}}}</p>
256 <div class=" progress-bar-warning progress-bar-striped"
257 style="height: {{{size}}}px;"></div>
266 # A `Panel` that displays the list of PR to review for a `Player`.
267 class PlayerReviewsPanel
273 # Player to display customized list for.
276 redef fun render_title
do
277 add
"<span class=\"glyphicon glyphicon-check\
"></span> "
278 add
"Review pull requests to gain nitcoins!"
281 redef fun render_body
do
282 var q
= "is:open label:need_review sort:updated-asc " +
283 "-involves:{player.name}"
285 var issues
= game
.repo
.search_issues
(q
)
286 if issues
.is_empty
then
287 add
"<em>No pull request to review yet...</em>"
290 for issue
in issues
do
291 add
"""<div class="media">
292 <a class="media-left" href="{{{player.url}}}">
293 <img class=\"img-circle\" style="width:50px"
294 src="{{{issue.user.avatar_url}}}" alt="{{{issue.user.login}}}">
296 <div class="media-body">
297 <h4 class="media-heading">
298 <a href="{{{issue.html_url}}}">#{{{issue.number}}} {{{issue.title}}}</a></h4>
299 <span class="text-muted">opened by </span>
300 <a href="{{{player.url}}}">{{{issue.user.login}}}</a>