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><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>"
120 add
"<strong class=\"text-success\
">{game.stats["commits"]}</strong> commits"
124 # Player status panel.
125 class PlayerStatusPanel
134 redef fun render_title
do
135 add
"<a href=\"{player.url}\
">"
136 add
" <img class=\"img-circle\
" style=\"width
: 30px\
""
137 add
" src=\"{player.user.avatar_url}\
" alt=\"{player.name}\
">"
138 add
"</a> "
139 add
"<a href=\"{player.url}\
">{player.name}</a>"
142 redef fun render_body
do
143 var ranking
= game
.player_ranking
145 add
"<p class=\"lead\
">ranked "
146 add
" <span class=\"text-success\
"># {ranking[player.name]}</span></p>"
147 add
"<strong class=\"text-success\
">{player.nitcoins}</strong> nitcoins<br><br>"
148 add
"<strong>{player.stats["pulls"]}</strong> pull requests<br>"
149 add
"<strong>{player.stats["issues"]}</strong> issues<br>"
150 add
"<strong>{player.stats["commits"]}</strong> commits"
155 # A panel that display a list of player in a repo.
156 class ShortListPlayersPanel
162 redef fun render_title
do
163 add
"<span class=\"glyphicon glyphicon-user\
"></span> "
164 add
"<a href=\"{game.url}/players\
">Players</a>"
167 redef fun render_body
do
168 var players
= game
.load_players
.values
.to_a
169 if players
.is_empty
then
170 add
"<em>No player yet...</em>"
173 (new PlayerCoinComparator).sort
(players
)
174 for player
in players
do
175 add
"<a href=\"{player.url}\
">"
177 add
"</a> ({player.nitcoins})<br>"
182 # A panel that display a list of player in a repo.
183 class ListPlayersPanel
189 redef fun render_title
do
190 add
"<span class=\"glyphicon glyphicon-user\
"></span> "
191 add
"<a href=\"{game.url}/players\
">Players</a>"
194 redef fun render_body
do
195 var players
= game
.load_players
.values
.to_a
196 (new PlayerCoinComparator).sort
(players
)
197 if players
.is_empty
then
198 add
"<div class=\"panel-body\
">"
199 add
"<em>No player yet...</em>"
203 add
"""<table class="table table-striped table-hover">
210 for player
in players
do
212 add
" <td>{rank}</td>"
213 add
" <td><a href=\"{player.url}\
">{player.name}</a></td>"
214 add
" <td>{player.nitcoins}</td>"
222 # A panel that display the podium.
229 redef fun render_title
do
230 add
"<span class=\"glyphicon glyphicon-stats\
"></span> Hall of fame"
233 redef fun render_body
do
234 var players
= game
.load_players
.values
.to_a
235 (new PlayerCoinComparator).sort
(players
)
236 if players
.is_empty
then
237 add
"<em>No players yet...</em>"
241 <div class="container-fluid">
242 <div id="podium" class="row row-sm-height">"""
243 var max
= players
.first
.nitcoins
244 var orders
= [3, 1, 0, 2, 4]
245 for order
in orders
do
246 if order
>= players
.length
then continue
247 var player
= players
[order
]
249 if max
> 0 then size
= player
.nitcoins
* 300 / max
251 <div class="col-xs-2 col-xs-height col-xs-offset-{{{order}}} col-bottom"
252 style="text-align: center;">
254 <a href="{{{player.url}}}">
255 <img class="img-circle" style="width: 80px"
256 src="{{{player.user.avatar_url}}}" alt="{{{player.name}}}">
259 <p><a href="{{{player.url}}}">{{{player.name}}}</a></p>
260 <p>{{{player.nitcoins}}}</p>
261 <div class=" progress-bar-warning progress-bar-striped"
262 style="height: {{{size}}}px;"></div>
271 # A `Panel` that displays the list of PR to review for a `Player`.
272 class PlayerReviewsPanel
278 # Player to display customized list for.
281 redef fun render_title
do
282 add
"<span class=\"glyphicon glyphicon-check\
"></span> "
283 add
"Review pull requests to gain nitcoins!"
286 redef fun render_body
do
287 var q
= "is:open label:need_review sort:updated-asc " +
288 "-involves:{player.name}"
290 var issues
= game
.repo
.search_issues
(q
)
291 if issues
.is_empty
then
292 add
"<em>No pull request to review yet...</em>"
295 for issue
in issues
do
296 add
"""<div class="media">
297 <a class="media-left" href="{{{player.url}}}">
298 <img class=\"img-circle\" style="width:50px"
299 src="{{{issue.user.avatar_url}}}" alt="{{{issue.user.login}}}">
301 <div class="media-body">
302 <h4 class="media-heading">
303 <a href="{{{issue.html_url}}}">#{{{issue.number}}} {{{issue.title}}}</a></h4>
304 <span class="text-muted">opened by </span>
305 <a href="{{{player.url}}}">{{{issue.user.login}}}</a>