From 41d6f3b60dcf5434f3659c5fe6246c07e7dd3d0b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Feb 2016 11:41:52 +0800 Subject: [PATCH] test issue #23 --- app.js | 2 +- lib/components/ProblemManager.js | 4 +- public/javascripts/live2d/src/LAppDefine.js | 8 +-- public/javascripts/main.js | 44 +------------ routes/admin/edit.js | 3 +- routes/admin/new.js | 11 ++-- routes/admin/update.js | 16 ++--- routes/admins.js | 5 +- routes/index.js | 31 +++++----- routes/users.js | 6 +- views/_partial/MathJax.ejs | 2 +- views/_partial/_contest/contest.ejs | 8 +-- views/_partial/_contest/contests.ejs | 2 +- views/_partial/_contest/scoreboard.ejs | 6 +- views/_partial/_problem/domain.ejs | 6 +- views/_partial/_problem/problem-domain.ejs | 11 ++-- views/_partial/_problem/problem-grade.ejs | 4 +- .../_partial/_problem/problem-statistics.ejs | 4 +- views/_partial/_problem/problem.ejs | 21 ++++--- views/_partial/_problem/solution.ejs | 12 ++-- views/_partial/_rank/ranklist.ejs | 4 +- views/_partial/_submission/highlight.ejs | 8 +-- views/_partial/_submission/livesubmission.ejs | 19 +++--- views/_partial/_submission/submissions.ejs | 2 +- views/_partial/_user/edit.ejs | 6 +- views/_partial/_user/score.ejs | 1 - views/_partial/_user/user.ejs | 20 +++--- views/_partial/_widget/recent_problem.ejs | 2 +- views/_partial/_widget/submission_table.ejs | 10 +-- views/_partial/head.ejs | 62 +++++++++---------- views/admin/_partial/account.ejs | 4 +- views/admin/_partial/announcement.ejs | 21 +++---- views/admin/_partial/contest.ejs | 10 +-- views/admin/_partial/contests.ejs | 6 +- views/admin/_partial/grade.ejs | 8 +-- views/admin/_partial/gradettl.ejs | 6 +- views/admin/_partial/newaccount.ejs | 2 +- views/admin/_partial/newcontest.ejs | 6 +- views/admin/_partial/newgrade.ejs | 2 +- views/admin/_partial/newproblem.ejs | 2 +- views/admin/_partial/problem.ejs | 14 ++--- views/admin/_partial/problems.ejs | 8 +-- views/admin/_partial/widget/nav.ejs | 10 +-- 43 files changed, 194 insertions(+), 245 deletions(-) diff --git a/app.js b/app.js index 06fbb7fad..bb8b96db5 100644 --- a/app.js +++ b/app.js @@ -70,7 +70,7 @@ app.use(session({ }, secret: 'alskdjasjoimk' })); -app.use(express.static(path.join(__dirname, 'public'))); +app.use(utils.url_for('/'), express.static(path.join(__dirname, 'public'))); app.use(utils.url_for('admin'), admins); app.use(utils.url_for('user'), users); diff --git a/lib/components/ProblemManager.js b/lib/components/ProblemManager.js index 942dc13bf..8e283f916 100644 --- a/lib/components/ProblemManager.js +++ b/lib/components/ProblemManager.js @@ -84,9 +84,7 @@ var dependencyGraph = function(callback) { var problemContent = function(pid, callback) { var prob_path = config.JUDGE.path + 'source/problem/' + pid + '.html'; fs.readFile(prob_path, 'utf8', function(err, buf_data) { - if (err) - return callback('Loading Error 1'); - var data = buf_data.toString(); + var data = err ? 'Loading Error 1' : buf_data.toString(); sourceList(pid, function(source_list) { var cmd = 'SELECT * FROM problems WHERE pid = ?'; connection.query(cmd, [pid], function(err, result) { diff --git a/public/javascripts/live2d/src/LAppDefine.js b/public/javascripts/live2d/src/LAppDefine.js index 0bbfe76ff..941d0514b 100644 --- a/public/javascripts/live2d/src/LAppDefine.js +++ b/public/javascripts/live2d/src/LAppDefine.js @@ -30,10 +30,10 @@ var LAppDefine = { BACK_IMAGE_NAME : "assets/image/back_class_normal.png", // モデル定義 - MODEL_HARU : "/javascripts/live2d/assets/live2d/haru/haru.model.json", - MODEL_HARU_B : "/javascripts/live2d/assets/live2d/haru/haru_02.model.json", - MODEL_SHIZUKU : "/javascripts/live2d/assets/live2d/shizuku/shizuku.model.json", - MODEL_WANKO : "/javascripts/live2d/assets/live2d/wanko/wanko.model.json", + MODEL_HARU : "./../javascripts/live2d/assets/live2d/haru/haru.model.json", + MODEL_HARU_B : "./../javascripts/live2d/assets/live2d/haru/haru_02.model.json", + MODEL_SHIZUKU : "./..javascripts/live2d/assets/live2d/shizuku/shizuku.model.json", + MODEL_WANKO : "./../javascripts/live2d/assets/live2d/wanko/wanko.model.json", // 外部定義ファイル(json)と合わせる MOTION_GROUP_IDLE : "idle", // アイドリング diff --git a/public/javascripts/main.js b/public/javascripts/main.js index 080f5d7dc..7ce2b7acc 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -7,51 +7,11 @@ function zeroFill( number, width ) } return number + ""; // always return a string } - -window.onunload = function(){}; - -window.addEventListener("load", function(){ - return 0; - document.getElementsByClassName("blackscreen")[0].style.opacity = 0; - setTimeout(function(){ document.getElementsByClassName("blackscreen")[0].style.display = "none"; }, 249); - - - var allNav = document.getElementsByTagName("a"); - for( var i = 0 ; i < allNav.length ; ++i ){ - (function(realTarget){ - realTarget.addEventListener("click", function(event){ - if( event.which === 1 && realTarget.getAttribute('target') == undefined){ - event.preventDefault(); - - document.getElementsByClassName("blackscreen")[0].style.display = ""; - setTimeout(function(){ document.getElementsByClassName("blackscreen")[0].style.opacity = 1; - setTimeout(function(){ window.location = realTarget.getAttribute("href"); }, 249); }, 50); - } - }); - })(allNav[i]); - } - - -}); - -function get_clock_offset() { - var offset; - var xmlhttp = new XMLHttpRequest(); - xmlhttp.open("GET", "/time", false); - xmlhttp.send(); - - var dateStr = xmlhttp.getResponseHeader('Date'); - var serverTimeMillisGMT = Date.parse(new Date(Date.parse(dateStr)).toUTCString()); - var localMillisUTC = Date.parse(new Date().toUTCString()); - - offset = serverTimeMillisGMT - localMillisUTC; - return offset; -} -function start_clock() { +function start_clock(timeURL) { var offset = 0; function calcOffset() { var xmlhttp = new XMLHttpRequest(); - xmlhttp.open("GET", "/time", false); + xmlhttp.open("GET", timeURL, false); xmlhttp.send(); var dateStr = xmlhttp.getResponseHeader('Date'); diff --git a/routes/admin/edit.js b/routes/admin/edit.js index 3dca7594b..a94a8db4c 100644 --- a/routes/admin/edit.js +++ b/routes/admin/edit.js @@ -5,7 +5,8 @@ var dblink = require('../../lib/components/dblink'); var multer = require('multer'); var upload = multer({dest: 'files/'}); var fs = require('fs'); -var loginURL = '/login'; +var utils = require('../../lib/components/utils'); +var loginURL = utils.url_for('login'); /* edit page */ router.get('/problem/:pid', function(req, res, next) { diff --git a/routes/admin/new.js b/routes/admin/new.js index 928846154..dea80a58e 100644 --- a/routes/admin/new.js +++ b/routes/admin/new.js @@ -5,7 +5,8 @@ var dblink = require('../../lib/components/dblink'); var multer = require('multer'); var upload = multer({dest: 'files/'}); var fs = require('fs'); -var loginURL = '/login'; +var utils = require('../../lib/components/utils'); +var loginURL = utils.url_for('login'); /* new page */ router.get('/problem', function(req, res, next) { @@ -59,7 +60,7 @@ router.post('/problem', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.create_problem_content(config, function() { - res.redirect('/admin/problems'); + res.redirect(utils.url_for('admin/problems')); }); }); }); @@ -80,7 +81,7 @@ router.post('/contest', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.create_contest_config(config, function() { - res.redirect('/admin/contests'); + res.redirect(utils.url_for('admin/contests')); }); }); }); @@ -97,7 +98,7 @@ router.post('/account', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.create_account(config, function() { - res.redirect('/admin/accounts'); + res.redirect(utils.url_for('admin/accounts')); }); }); }); @@ -108,7 +109,7 @@ router.post('/grade', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.create_exam_scores(ttl, function() { - res.redirect('/admin/grade'); + res.redirect(utils.url_for('admin/grade')); }); }); }); diff --git a/routes/admin/update.js b/routes/admin/update.js index 92a3bb865..fdab61534 100644 --- a/routes/admin/update.js +++ b/routes/admin/update.js @@ -5,8 +5,8 @@ var dblink = require('../../lib/components/dblink'); var multer = require('multer'); var upload = multer({dest: 'files/'}); var fs = require('fs'); -var loginURL = '/login'; - +var utils = require('../../lib/components/utils'); +var loginURL = utils.url_for('login'); /* update */ router.post('/announcement', function(req, res, next) { @@ -16,7 +16,7 @@ router.post('/announcement', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_announcement(md, function() { - res.redirect('/'); + res.redirect(utils.url_for('/')); }); }); }); @@ -38,7 +38,7 @@ router.post('/problem/:pid', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_problem_content(config, function() { - res.redirect('/problem/0/' + config.pid); + res.redirect(utils.url_for('problem/0/' + config.pid)); dblink.admin.update_problem_solution(config, function() { }); @@ -68,7 +68,7 @@ router.post('/contest/:cid', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_contest_config(config, function() { - res.redirect('/contest/' + config.cid); + res.redirect(utils.url_for('contest/' + config.cid)); }); }); }); @@ -84,7 +84,7 @@ router.post('/account/:uid', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_account(config, function() { - res.redirect('/admin/accounts'); + res.redirect(utils.url_for('admin/accounts')); }); }); }); @@ -94,7 +94,7 @@ router.post('/grade/:uid', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_scores(req.params.uid, req.body, function() { - res.redirect('/admin/grade'); + res.redirect(utils.url_for('admin/grade')); }); }); }); @@ -105,7 +105,7 @@ router.post('/gradettl/:eid', function(req, res, next) { if (!isadmin) return res.redirect(loginURL); dblink.admin.update_gradettl(eid, req.body.ttl, function() { - res.redirect('/admin/grade'); + res.redirect(utils.url_for('admin/grade')); }); }); }); diff --git a/routes/admins.js b/routes/admins.js index 51a6353b3..a5b495d2d 100644 --- a/routes/admins.js +++ b/routes/admins.js @@ -5,7 +5,8 @@ var dblink = require('../lib/components/dblink'); var multer = require('multer'); var upload = multer({dest: 'files/'}); var fs = require('fs'); -var loginURL = '/login'; +var utils = require('../lib/components/utils'); +var loginURL = utils.url_for('login'); /* GET admin page dashboard */ router.get('/', function(req, res, next) { @@ -79,7 +80,7 @@ router.get('/api/rejudge?', function(req, res, next) { return res.redirect(loginURL); dblink.api.rejudge(req.query, function(result) { if (req.headers.referer) res.redirect(req.headers.referer); - else res.redirect("/"); + else res.redirect(utils.url_for('/')); }); }); }); diff --git a/routes/index.js b/routes/index.js index f26bef034..d04d660d9 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,6 +4,7 @@ var dblink = require('../lib/components/dblink'); var multer = require('multer'); var _config = require('../lib/config').config; var markdown = require('../lib/components/plugin/markdown'); +var utils = require('../lib/components/utils'); var fs = require('fs'); var upload = multer({ @@ -34,14 +35,14 @@ router.get('/restart', function(req, res, next){ throw new Exception(); } else { - res.redirect('/'); + res.redirect(utils.url_for('/')); } }); }); /* User Information control */ router.get('/login', function(req, res, next) { - req.session.redirect_to = req.header('Referer') || '/'; + req.session.redirect_to = req.header('Referer') || utils.url_for('/'); res.render('layout', { layout: 'login', subtitle: 'Login', user: req.session, sysmsg: '' }); }); router.post('/login', function(req, res, next) { @@ -51,8 +52,7 @@ router.post('/login', function(req, res, next) { }; var iplist = _config.CONTEST.VALID_IP; var ip = req.ip; - console.log(req.session.redirect_to); - var backURL = req.session.redirect_to || '/'; + var backURL = req.session.redirect_to || utils.url_for('/'); dblink.user.login(user, req.session, function(status) { if (status == 1) { var uid = req.session.uid; @@ -75,7 +75,7 @@ router.post('/login', function(req, res, next) { }); router.get('/logout', function(req, res, next) { req.session.regenerate(function(err) { - res.redirect('/'); + res.redirect(utils.url_for('/')); }); }); router.get('/edit', function(req, res, next) { @@ -131,7 +131,7 @@ router.post('/register', function(req, res, next) { */ /* Navigation Bar */ router.get('/archive', function(req, res, next) { - res.redirect('/'); + res.redirect(utils.url_for('/')); }); router.get('/ranklist?', function(req, res, next) { dblink.rank.list(req.query, function(rlist) { @@ -176,6 +176,7 @@ router.get('/problem/:cid/:pid', function(req, res, next) { var cid = req.params.cid, pid = req.params.pid, uid = req.session.uid; + console.log(pid); var loadPage = function() { dblink.problemManager.problemContent(pid, function(pcontent, pinfo, psubmit) { dblink.problemManager.testdataList(pid, function(tconfig) { @@ -194,7 +195,7 @@ router.get('/problem/:cid/:pid', function(req, res, next) { if (uid != undefined && req.session['class'] == null) can = true; if (!can) - return res.redirect('/problems'); + return res.redirect(utils.url_for('problems/domains')); loadPage(); }); }); @@ -206,7 +207,7 @@ router.get('/solution/problem/:pid', function(req, res, next) { if (uid != undefined && req.session['class'] == null) can = true; if (!can) - return res.redirect('/problems'); + return res.redirect(utils.url_for('problems/domains')); dblink.problemManager.problemSolution(pid, function(solution_config) { res.render('layout', { layout: 'solution', subtitle: 'Solution', user: req.session, solution_config: solution_config}); }); @@ -248,7 +249,7 @@ router.get('/statistic/grade/problem/:cid/:pid', function(req, res, next) { }; dblink.helper.isAdmin(uid, function(isadmin) { if (!isadmin) - return res.redirect('/login'); + return res.redirect(utils.url_for('login')); loadPage(); }); }); @@ -284,7 +285,7 @@ router.get('/scoreboard/contest/:cid', function(req, res, next) { uid = req.session.uid; dblink.contest.enable(cid, uid, function(status, contest_config, sysmsg) { if (status == 0) { - res.redirect('/contest/' + cid); + res.redirect(utils.url_for('/contest/' + cid)); } else { dblink.contest.scoreboard(cid, uid, function(table_config) { res.render('layout', { layout: 'scoreboard', subtitle: 'Scoreboard', user: req.session, table_config: table_config}); @@ -300,7 +301,7 @@ router.post('/submit', {name: 'code6', maxCount: 1}, {name: 'code7', maxCount: 1}]), function(req, res, next) { if (req.session.uid === undefined || req.session.uid < 0) - return res.redirect("/login"); + return res.redirect(utils.url_for('/login')); var cid = req.body.cid, pid = req.body.pid, @@ -318,7 +319,7 @@ router.post('/submit', if (req.files['code' + i] == null || req.files['code' + i] == undefined || req.files['code' + i][0] == null || req.files['code' + i][0] == undefined) { console.log('NOT FOUND FILE ' + i); - return res.redirect("/"); + return res.redirect(utils.url_for('/')); } size += req.files['code' + i][0].size; } @@ -340,9 +341,9 @@ router.post('/submit', dblink.judge.update_waiting_submission(sid, function(err) { if (cid === "0") - return res.redirect("/submissions"); + return res.redirect(utils.url_for('submissions')); else - return res.redirect("/submissions?cid=" + cid); + return res.redirect(utils.url_for('submissions?cid=' + cid)); }); }); @@ -353,7 +354,7 @@ router.post('/submit', if (req.session['class'] == null) canSubmit = true; if (!canSubmit) - return res.redirect("/"); + return res.redirect(utils.url_for('/')); submitStep(); }); }); diff --git a/routes/users.js b/routes/users.js index 6c3b53768..849ccc8f2 100644 --- a/routes/users.js +++ b/routes/users.js @@ -5,6 +5,8 @@ var config = require('../lib/config').config; var MAU = require('../lib/components/modify-and-upload'); var multer = require('multer'); var fs = require('fs'); +var utils = require('../lib/components/utils'); + var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, './files/') @@ -40,10 +42,10 @@ router.post('/upload/avatar', upload.fields([{name: 'avatar', maxCount: 1}]), function(req, res, next) { var uid = req.session.uid; if (uid == undefined || uid == null) { - res.redirect('../login'); + res.redirect(utils.url_for('login')); } else { var mau = new MAU(req.files['avatar'][0], uid, function(err, newImagePath){ - res.redirect('/'); + res.redirect(utils.url_for('/')); }); } }); diff --git a/views/_partial/MathJax.ejs b/views/_partial/MathJax.ejs index f768ef7bd..94611fbc0 100644 --- a/views/_partial/MathJax.ejs +++ b/views/_partial/MathJax.ejs @@ -26,5 +26,5 @@ }); - \ No newline at end of file diff --git a/views/_partial/_contest/contest.ejs b/views/_partial/_contest/contest.ejs index 642d90389..24582a9c0 100644 --- a/views/_partial/_contest/contest.ejs +++ b/views/_partial/_contest/contest.ejs @@ -22,9 +22,9 @@
@@ -62,7 +62,7 @@ <% } %> <%- problem_list[row].pid %> - " ><%- problem_list[row].ttl %> + <%- problem_list[row].ttl %> <%- site.CONTEST.SUBMIT_LIMIT - submits %> diff --git a/views/_partial/_contest/contests.ejs b/views/_partial/_contest/contests.ejs index a0e0f05db..55266393b 100644 --- a/views/_partial/_contest/contests.ejs +++ b/views/_partial/_contest/contests.ejs @@ -94,5 +94,5 @@ else page = parseInt(page); %> - <%- include('../pagination', {page: page, url: '/contests?page=', query: arg_query, totpage: totpage})%> + <%- include('../pagination', {page: page, url: site.url_for('contests?page='), query: arg_query, totpage: totpage})%> \ No newline at end of file diff --git a/views/_partial/_contest/scoreboard.ejs b/views/_partial/_contest/scoreboard.ejs index 629ef0e82..656e2eff7 100644 --- a/views/_partial/_contest/scoreboard.ejs +++ b/views/_partial/_contest/scoreboard.ejs @@ -16,7 +16,7 @@ Score <% var width = 85 / Math.max(table_config.header.length, 1); %> <% for (var row = 0; row < table_config.header.length; row++) { %> - <%- table_config.header[row].ttl %> + <%- table_config.header[row].ttl %> <% } %> @@ -119,7 +119,7 @@ %> <% for (var row = 0; row < table_config.user.length; row++) { %> - <%- table_config.user[row].lgn %> + <%- table_config.user[row].lgn %> <% for (var col = 0; col < table_config.header.length; col++) { %> <% if (alluser[table_config.user[row].uid][table_config.header[col].pid] != undefined) { @@ -136,7 +136,7 @@ AC <% } %> <%- score %> - <%- times %> + <%- times %> <% } else { %> NO 0 diff --git a/views/_partial/_problem/domain.ejs b/views/_partial/_problem/domain.ejs index 682ef1255..afc388a7f 100644 --- a/views/_partial/_problem/domain.ejs +++ b/views/_partial/_problem/domain.ejs @@ -21,15 +21,13 @@
diff --git a/views/_partial/_problem/problem-domain.ejs b/views/_partial/_problem/problem-domain.ejs index 15e79a934..7c50e34cc 100644 --- a/views/_partial/_problem/problem-domain.ejs +++ b/views/_partial/_problem/problem-domain.ejs @@ -7,7 +7,7 @@