From e902a38c575f2f924bf8aea050c846ab9a9bce8d Mon Sep 17 00:00:00 2001 From: t123yh Date: Thu, 24 Aug 2017 19:41:19 +0800 Subject: [PATCH] Add hide statistics support. --- models/contest.js | 6 ++++-- modules/contest.js | 6 ++++-- views/contest_edit.ejs | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/models/contest.js b/models/contest.js index 47e5b92..32076c6 100644 --- a/models/contest.js +++ b/models/contest.js @@ -56,7 +56,8 @@ let model = db.define('contest', { } }, - is_public: { type: Sequelize.BOOLEAN } + is_public: { type: Sequelize.BOOLEAN }, + hide_statistics: { type: Sequelize.BOOLEAN } }, { timestamps: false, tableName: 'contest', @@ -84,7 +85,8 @@ class Contest extends Model { end_time: 0, holder: 0, ranklist_id: 0, - is_public: false + is_public: false, + hide_statistics: false }, val))); } diff --git a/modules/contest.js b/modules/contest.js index 3951b43..f9d7e57 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -110,6 +110,7 @@ app.post('/contest/:id/edit', async (req, res) => { contest.start_time = syzoj.utils.parseDate(req.body.start_time); contest.end_time = syzoj.utils.parseDate(req.body.end_time); contest.is_public = req.body.is_public === 'on'; + contest.hide_statistics = req.body.hide_statistics === 'on'; await contest.save(); @@ -131,6 +132,7 @@ app.get('/contest/:id', async (req, res) => { if (!contest) throw new ErrorMessage('无此比赛。'); if (!contest.is_public && (!res.locals.user || !res.locals.user.is_admin)) throw new ErrorMessage('无此比赛。'); + const isSupervisior = await contest.isSupervisior(curUser); contest.running = contest.isRunning(); contest.ended = contest.isEnded(); contest.subtitle = await syzoj.utils.markdown(contest.subtitle); @@ -181,7 +183,7 @@ app.get('/contest/:id', async (req, res) => { } let hasStatistics = false; - if (contest.type === 'ioi' || contest.type === 'acm' || (contest.type === 'noi' && (contest.ended || (res.locals.user && res.locals.user.is_admin)))) { + if ((!contest.hide_statistics) || (contest.ended) || (isSupervisior)) { hasStatistics = true; await contest.loadRelationships(); @@ -212,7 +214,7 @@ app.get('/contest/:id', async (req, res) => { contest: contest, problems: problems, hasStatistics: hasStatistics, - isSupervisior: await contest.isSupervisior(curUser) + isSupervisior: isSupervisior }); } catch (e) { syzoj.log(e); diff --git a/views/contest_edit.ejs b/views/contest_edit.ejs index 31b4ed9..d82fda3 100644 --- a/views/contest_edit.ejs +++ b/views/contest_edit.ejs @@ -66,6 +66,13 @@ +
+ +
+ checked<% } %> name="hide_statistics"> + +
+