Browse Source

Add hide statistics support.

pull/6/head
t123yh 7 years ago
parent
commit
e902a38c57
  1. 6
      models/contest.js
  2. 6
      modules/contest.js
  3. 7
      views/contest_edit.ejs

6
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)));
}

6
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);

7
views/contest_edit.ejs

@ -66,6 +66,13 @@
<label><span style="visibility: hidden; "> </span></label>
</div>
</div>
<div class="inline field">
<label class="ui header">隐藏统计信息</label>
<div class="ui toggle checkbox">
<input type="checkbox"<% if (contest.hide_statistics) { %> checked<% } %> name="hide_statistics">
<label><span style="visibility: hidden; "> </span></label>
</div>
</div>
<button type="submit" class="ui button">提交</button>
</form>
<script>

Loading…
Cancel
Save