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, timestamps: false,
tableName: 'contest', tableName: 'contest',
@ -84,7 +85,8 @@ class Contest extends Model {
end_time: 0, end_time: 0,
holder: 0, holder: 0,
ranklist_id: 0, ranklist_id: 0,
is_public: false is_public: false,
hide_statistics: false
}, val))); }, 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.start_time = syzoj.utils.parseDate(req.body.start_time);
contest.end_time = syzoj.utils.parseDate(req.body.end_time); contest.end_time = syzoj.utils.parseDate(req.body.end_time);
contest.is_public = req.body.is_public === 'on'; contest.is_public = req.body.is_public === 'on';
contest.hide_statistics = req.body.hide_statistics === 'on';
await contest.save(); await contest.save();
@ -131,6 +132,7 @@ app.get('/contest/:id', async (req, res) => {
if (!contest) throw new ErrorMessage('无此比赛。'); if (!contest) throw new ErrorMessage('无此比赛。');
if (!contest.is_public && (!res.locals.user || !res.locals.user.is_admin)) 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.running = contest.isRunning();
contest.ended = contest.isEnded(); contest.ended = contest.isEnded();
contest.subtitle = await syzoj.utils.markdown(contest.subtitle); contest.subtitle = await syzoj.utils.markdown(contest.subtitle);
@ -181,7 +183,7 @@ app.get('/contest/:id', async (req, res) => {
} }
let hasStatistics = false; 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; hasStatistics = true;
await contest.loadRelationships(); await contest.loadRelationships();
@ -212,7 +214,7 @@ app.get('/contest/:id', async (req, res) => {
contest: contest, contest: contest,
problems: problems, problems: problems,
hasStatistics: hasStatistics, hasStatistics: hasStatistics,
isSupervisior: await contest.isSupervisior(curUser) isSupervisior: isSupervisior
}); });
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);

7
views/contest_edit.ejs

@ -66,6 +66,13 @@
<label><span style="visibility: hidden; "> </span></label> <label><span style="visibility: hidden; "> </span></label>
</div> </div>
</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> <button type="submit" class="ui button">提交</button>
</form> </form>
<script> <script>

Loading…
Cancel
Save