Browse Source

Add contest is_public

master
Menci 8 years ago
parent
commit
1e17e77ab6
  1. 7
      models/contest.js
  2. 9
      modules/contest.js
  3. 5
      modules/index.js
  4. 7
      views/contest_edit.ejs

7
models/contest.js

@ -53,7 +53,9 @@ let model = db.define('contest', {
model: 'contest_ranklist',
key: 'id'
}
}
},
is_public: { type: Sequelize.BOOLEAN }
}, {
timestamps: false,
tableName: 'contest',
@ -79,7 +81,8 @@ class Contest extends Model {
start_time: 0,
end_time: 0,
holder: 0,
ranklist_id: 0
ranklist_id: 0,
is_public: false
}, val)));
}

9
modules/contest.js

@ -28,8 +28,12 @@ let User = syzoj.model('user');
app.get('/contests', async (req, res) => {
try {
let paginate = syzoj.utils.paginate(await Contest.count(), req.query.page, syzoj.config.page.contest);
let contests = await Contest.query(paginate, null, [['start_time', 'desc']]);
let where;
if (res.locals.user && await res.locals.user.is_admin) where = {}
else where = { is_public: true };
let paginate = syzoj.utils.paginate(await Contest.count(where), req.query.page, syzoj.config.page.contest);
let contests = await Contest.query(paginate, where, [['start_time', 'desc']]);
await contests.forEachAsync(async x => x.subtitle = await syzoj.utils.markdown(x.subtitle));
@ -97,6 +101,7 @@ app.post('/contest/:id/edit', async (req, res) => {
contest.information = req.body.information;
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';
await contest.save();

5
modules/index.js

@ -47,7 +47,10 @@ 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']]);
let where;
if (res.locals.user && await res.locals.user.is_admin) where = {}
else where = { is_public: true };
let contests = await Contest.query([1, 5], where, [['start_time', 'desc']]);
let hitokoto;
try {

7
views/contest_edit.ejs

@ -51,6 +51,13 @@
<label>结束时间</label>
<input type="text" name="end_time" value="<%= syzoj.utils.formatDate(contest.end_time || syzoj.utils.getCurrentDate()) %>">
</div>
<div class="inline field">
<label class="ui header">公开</label>
<div class="ui toggle checkbox">
<input type="checkbox"<% if (contest.is_public) { %> checked<% } %> name="is_public">
<label><span style="visibility: hidden; "> </span></label>
</div>
</div>
<button type="submit" class="ui button">提交</button>
</form>
<script>

Loading…
Cancel
Save