From 344b9ecbc46796ca51028ad817a6184323c3346a Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 5 Dec 2016 19:20:33 +0800 Subject: [PATCH] Add recent contests --- modules/index.js | 6 +++++- views/index.ejs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/modules/index.js b/modules/index.js index ad53efc..7900e2f 100644 --- a/modules/index.js +++ b/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); diff --git a/views/index.ejs b/views/index.ejs index e286d9f..7c15e23 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -103,9 +103,47 @@ <% } %> +

近期比赛

+
+ <% if (!contests || !contests.length) { %> + 还没有举行过任何比赛 + <% } else { %> + + + + + + + + + <% + for (let contest of contests) { + let now = syzoj.utils.getCurrentDate(); + let tag = ''; + %> + + <% if (now < contest.start_time) { %> + <% tag = '
未开始
' %> + <% } else if (now >= contest.start_time && now < contest.end_time) { %> + <% tag = '
进行中
' %> + <% } else { %> + <% tag = '
已结束
' %> + <% } %> + + + + <% } %> + +
比赛名称开始时间
<%= contest.title %> <%- tag %><%= syzoj.utils.formatDate(contest.start_time) %>
+ <% } %> +

信息栏

-
+
+ <% if (!syzoj.config.announcement) { %> + 无任何信息 + <% } else { %>

<%- syzoj.config.announcement %>

+ <% } %>