Browse Source

Remember last submit language

master
Menci 7 years ago
parent
commit
a1655640e9
  1. 9
      models/user.js
  2. 3
      modules/contest.js
  3. 3
      modules/problem.js
  4. 2
      views/problem.ejs

9
models/user.js

@ -227,6 +227,15 @@ class User extends Model {
return !(!x);
}
async getLastSubmitLanguage() {
let JudgeState = syzoj.model('judge_state');
let a = await JudgeState.query([1, 1], { user_id: this.id }, [['submit_time', 'desc']]);
if (a[0]) return a[0].language;
return null;
}
getModel() { return model; }
}

3
modules/contest.js

@ -338,7 +338,8 @@ app.get('/contest/:id/:pid', async (req, res) => {
pid: pid,
contest: contest,
problem: problem,
state: state
state: state,
lastLanguage: res.locals.user ? await res.locals.user.getLastSubmitLanguage() : null
});
} catch (e) {
syzoj.log(e);

3
modules/problem.js

@ -203,7 +203,8 @@ app.get('/problem/:id', async (req, res) => {
res.render('problem', {
problem: problem,
state: state
state: state,
lastLanguage: res.locals.user ? await res.locals.user.getLastSubmitLanguage() : null
});
} catch (e) {
syzoj.log(e);

2
views/problem.ejs

@ -166,7 +166,7 @@ if (contest) {
let language = Object.getOwnPropertyNames(syzoj.config.languages).shift();
if (state) {
language = state.language;
}
} else if (lastLanguage) language = lastLanguage;
%>
<% for (lang in syzoj.config.languages) { %>
<a class="item<%= lang === language ? ' active' : '' %>" data-value="<%= lang %>" data-mode="<%= syzoj.config.languages[lang].editor %>">

Loading…
Cancel
Save