Browse Source

Add page to reset submission count.

master
t123yh 7 years ago
parent
commit
dc323c25ed
  1. 15
      models/problem.js
  2. 35
      modules/admin.js
  3. 3
      views/admin_header.ejs
  4. 7
      views/admin_other.ejs
  5. 1
      views/admin_rejudge.ejs
  6. 1
      views/problem_manage.ejs

15
models/problem.js

@ -201,6 +201,7 @@ let Sequelize = require('sequelize');
let db = syzoj.db;
let User = syzoj.model('user');
let JudgeState = syzoj.model('judge_state');
let File = syzoj.model('file');
const fs = require('fs-extra');
const path = require('path');
@ -472,8 +473,6 @@ class Problem extends Model {
async getJudgeState(user, acFirst) {
if (!user) return null;
let JudgeState = syzoj.model('judge_state');
let where = {
user_id: user.id,
problem_id: this.id
@ -498,6 +497,12 @@ class Problem extends Model {
});
}
async resetSubmissionCount() {
this.submit_num = await JudgeState.count({ score: { $not: null }, problem_id: this.id });
this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id });
await this.save();
}
// type: fastest / slowest / shortest / longest / earliest
async countStatistics(type) {
let statement = statisticsStatements[type];
@ -585,10 +590,12 @@ class Problem extends Model {
let addTagIDs = newTagIDs.filter(x => !oldTagIDs.includes(x));
for (let tagID of delTagIDs) {
let map = await ProblemTagMap.findOne({ where: {
let map = await ProblemTagMap.findOne({
where: {
problem_id: this.id,
tag_id: tagID
} });
}
});
await map.destroy();
}

35
modules/admin.js

@ -198,6 +198,19 @@ app.post('/admin/privilege', async (req, res) => {
}
});
app.get('/admin/other', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
res.render('admin_other');
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
})
}
});
app.get('/admin/rejudge', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
@ -214,6 +227,28 @@ app.get('/admin/rejudge', async (req, res) => {
}
});
app.post('/admin/other', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
if (req.body.type === 'reset_count') {
const problems = await Problem.query();
for(const p of problems) {
await p.resetSubmissionCount();
}
} else {
throw new ErrorMessage("操作类型不正确");
}
res.redirect(syzoj.utils.makeUrl(['admin', 'other']));
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
})
}
});
app.post('/admin/rejudge', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');

3
views/admin_header.ejs

@ -5,7 +5,8 @@ let items = {
privilege: '权限管理',
rejudge: '一键重测',
links: '友链管理',
raw: '配置文件'
raw: '配置文件',
other: '其他操作'
};
%>
<% this.title = items[this.adminPage] + ' - 后台管理'; %>

7
views/admin_other.ejs

@ -0,0 +1,7 @@
<% this.adminPage = 'rejudge'; %>
<% include admin_header %>
<form method="post" class="ui form">
<button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button>
<!-- <button name="type" value="reset_size" type="submit">重新计算代码大小</button> -->
</form>
<% include admin_footer %>

1
views/admin_rejudge.ejs

@ -1,7 +1,6 @@
<% this.adminPage = 'rejudge'; %>
<% include admin_header %>
<form method="post" class="ui form">
<div class="four fields">
<div class="field">
<label>题目 ID</label>

1
views/problem_manage.ejs

@ -4,6 +4,7 @@
<div class="ui grid">
<div class="row">
<div class="seven wide column">
<form class="ui form" method="post" action=""></form>
<% include problem_testcases %>
</div>
<div class="nine wide column">

Loading…
Cancel
Save