Browse Source

Add recent contests

pull/6/head
Menci 8 years ago
parent
commit
344b9ecbc4
  1. 6
      modules/index.js
  2. 40
      views/index.ejs

6
modules/index.js

@ -21,6 +21,7 @@
let User = syzoj.model('user');
let Article = syzoj.model('article');
let Contest = syzoj.model('contest');
let Divine = require('syzoj-divine');
app.get('/', async (req, res) => {
@ -46,10 +47,13 @@ app.get('/', async (req, res) => {
fortune = Divine(res.locals.user.username, res.locals.user.sex);
}
let contests = await Contest.query([1, 5], null, [['start_time', 'desc']]);
res.render('index', {
ranklist: ranklist,
notices: notices,
fortune: fortune
fortune: fortune,
contests: contests
});
} catch (e) {
syzoj.log(e);

40
views/index.ejs

@ -103,9 +103,47 @@
</div>
</div>
<% } %>
<h4 class="ui top attached block header">近期比赛</h4>
<div class="ui bottom attached <% if (!contests || !contests.length) { %>center aligned <% } %>segment">
<% if (!contests || !contests.length) { %>
还没有举行过任何比赛
<% } else { %>
<table class="ui very basic center aligned table">
<thead>
<tr>
<th>比赛名称</th>
<th>开始时间</th>
</tr>
</thead>
<tbody>
<%
for (let contest of contests) {
let now = syzoj.utils.getCurrentDate();
let tag = '';
%>
<tr>
<% if (now < contest.start_time) { %>
<% tag = '<span class="ui header"><div class="ui mini grey label">未开始</div></span>' %>
<% } else if (now >= contest.start_time && now < contest.end_time) { %>
<% tag = '<span class="ui header"><div class="ui mini green label">进行中</div></span>' %>
<% } else { %>
<% tag = '<span class="ui header"><div class="ui mini red label">已结束</div></span>' %>
<% } %>
<td><a href="<%= syzoj.utils.makeUrl(['contest', contest.id]) %>"><%= contest.title %> <%- tag %></a></td>
<td><%= syzoj.utils.formatDate(contest.start_time) %></td>
</tr>
<% } %>
</tbody>
</table>
<% } %>
</div>
<h4 class="ui top attached block header">信息栏</h4>
<div class="ui bottom attached segment">
<div class="ui bottom attached <% if (!syzoj.config.announcement) { %>center aligned <% } %>segment">
<% if (!syzoj.config.announcement) { %>
无任何信息
<% } else { %>
<p><%- syzoj.config.announcement %></p>
<% } %>
</div>
</div>
</div>

Loading…
Cancel
Save