@ -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; }
@ -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);
@ -203,7 +203,8 @@ app.get('/problem/:id', async (req, res) => {
res.render('problem', {
@ -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 %>">