From: Brendan Hansen Date: Fri, 6 Sep 2019 00:48:39 +0000 (-0500) Subject: small changes and code cleanup X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b39945e2a8d6d413eeadd16d85c9e8e16f6913ab;p=codebox.git small changes and code cleanup --- diff --git a/codebox/app/app.moon b/codebox/app/app.moon index cd18b10..04c4379 100644 --- a/codebox/app/app.moon +++ b/codebox/app/app.moon @@ -68,6 +68,7 @@ class extends lapis.Application ['admin.competition.delete': "/admin/competition/delete/:competition_id"]: controller "admin.competition.delete" ['admin.competition.add_problem': "/admin/competition/add_problem"]: controller "admin.competition.add_problem" ['admin.competition.delete_problem': "/admin/competition/delete_problem"]: controller "admin.competition.delete_problem" + ['admin.competition.activate': "/admin/competition/activate/:competition_id"]: controller "admin.competition.activate" [test: '/test']: => user = Users\find 5 diff --git a/codebox/controllers/account/register.moon b/codebox/controllers/account/register.moon index c16d4b4..0f3bc6b 100644 --- a/codebox/controllers/account/register.moon +++ b/codebox/controllers/account/register.moon @@ -17,7 +17,7 @@ make_controller @flow 'csrf_validate' assert_valid @params, { - { "username", exists: true, min_length: 2 } + { "username", exists: true, min_length: 2, matches_pattern: "%S+" } { "nickname", exists: true, min_length: 2 } { "email", exists: true, min_length: 4, matches_pattern: "%S+@%S+%.%S+" } { "password", exists: true, min_length: 2 } diff --git a/codebox/controllers/admin/competition/activate.moon b/codebox/controllers/admin/competition/activate.moon new file mode 100644 index 0000000..4fec66e --- /dev/null +++ b/codebox/controllers/admin/competition/activate.moon @@ -0,0 +1,25 @@ +import make_controller from require "controllers.controller" +import assert_valid from require "lapis.validate" +import capture_errors, capture_errors_json, yield_error from require 'lapis.application' +import Competitions, Problems, CompetitionProblems from require 'models' +db = require 'lapis.db' + +make_controller + middleware: { 'logged_in', 'admin_required' } + + get: capture_errors_json => + assert_valid @params, { + { "competition_id", exists: true } + } + + comp = Competitions\find @params.competition_id + unless comp + yield_error "Competition not found" + + db.query 'UPDATE competitions SET active=FALSE WHERE 1=1;' + + comp\update { + active: true + } + + redirect_to: @url_for "admin.competition" \ No newline at end of file diff --git a/codebox/controllers/admin/problem/new.moon b/codebox/controllers/admin/problem/new.moon index 7079233..45c119d 100644 --- a/codebox/controllers/admin/problem/new.moon +++ b/codebox/controllers/admin/problem/new.moon @@ -15,10 +15,7 @@ make_controller @problems = Problems\select! - return { - layout: require 'views.partials.admin_layout' - render: 'admin.problem.new' - } + render: 'admin.problem.new' post: capture_errors => @flow 'csrf_validate' diff --git a/codebox/controllers/admin/submission/edit.moon b/codebox/controllers/admin/submission/edit.moon index 8981baf..6ba85b5 100644 --- a/codebox/controllers/admin/submission/edit.moon +++ b/codebox/controllers/admin/submission/edit.moon @@ -21,6 +21,3 @@ make_controller yield_error "Job not found" render: "admin.submission.edit" - - post: capture_errors_json => - json: { 'success': true } diff --git a/codebox/views/admin/competition.moon b/codebox/views/admin/competition.moon index 8c07245..5019367 100644 --- a/codebox/views/admin/competition.moon +++ b/codebox/views/admin/competition.moon @@ -12,10 +12,15 @@ class AdminCompetition extends html.Widget div class: 'option-line', -> span comp.name div class: 'button-list', -> + a href: (@url_for "admin.competition.activate", { competition_id: comp.id }), "Make active" a href: (@url_for "admin.competition.edit", { competition_id: comp.id }), "Edit" a href: (@url_for "admin.competition.delete", { competition_id: comp.id}), 'Delete' div class: 'box', -> + if comp.active + div class: 'highlight pad-12', -> + span 'Active' + div class: 'highlight pad-12 split-lr', -> span 'Start time' span comp.start diff --git a/codebox/views/admin/problem.moon b/codebox/views/admin/problem.moon index a7872b1..c507119 100644 --- a/codebox/views/admin/problem.moon +++ b/codebox/views/admin/problem.moon @@ -18,6 +18,9 @@ class AdminProblems extends html.Widget a { 'data-problem-delete': problem.short_name }, 'Delete' div class: 'box', -> + div class: 'highlight pad-12 split-lr', -> + span "Id:" + span "#{problem.id}" div class: 'highlight pad-12 split-lr', -> span "Short name:" span "#{problem.short_name}" diff --git a/codebox/views/admin/submission.moon b/codebox/views/admin/submission.moon index d45e585..9380719 100644 --- a/codebox/views/admin/submission.moon +++ b/codebox/views/admin/submission.moon @@ -18,11 +18,11 @@ class AdminSubmission extends html.Widget span 'Status:' span Jobs.statuses\to_name job.status div class: 'highlight pad-12 split-lr', -> - span 'Username:' - span job\get_user!.username + span 'User id:' + span job.user_id div class: 'highlight pad-12 split-lr', -> - span 'Problem:' - span job\get_problem!.short_name + span 'Problem id:' + span job.problem_id div class: 'highlight pad-12 split-lr', -> span 'Language:' span job.lang diff --git a/codebox/views/admin/user.moon b/codebox/views/admin/user.moon index ae68b2f..4f7619d 100644 --- a/codebox/views/admin/user.moon +++ b/codebox/views/admin/user.moon @@ -13,6 +13,9 @@ class AdminUsers extends html.Widget button { 'data-user-reset-password': user.username }, 'Reset password' button { 'data-user-delete': user.username }, 'Delete' div class: 'box', -> + div class: 'highlight pad-12 split-lr', -> + span "Id:" + span "#{user.id}" div class: 'highlight pad-12 split-lr', -> span "Nickname:" span "#{user.nickname}" diff --git a/executer/app/routes.coffee b/executer/app/routes.coffee index c2eb91f..c7f97a3 100644 --- a/executer/app/routes.coffee +++ b/executer/app/routes.coffee @@ -34,11 +34,6 @@ async function handle_job(job_id, lang, code, cases, time_limit) { ``` module.exports = (app) -> - app.get '/', (req, res) -> - res.json { - test: 'This is test data' - } - app.post '/request', (req, res) -> cases = JSON.parse req.body.test_cases job_id = uuid()