small changes and code cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 Sep 2019 00:48:39 +0000 (19:48 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 Sep 2019 00:48:39 +0000 (19:48 -0500)
codebox/app/app.moon
codebox/controllers/account/register.moon
codebox/controllers/admin/competition/activate.moon [new file with mode: 0644]
codebox/controllers/admin/problem/new.moon
codebox/controllers/admin/submission/edit.moon
codebox/views/admin/competition.moon
codebox/views/admin/problem.moon
codebox/views/admin/submission.moon
codebox/views/admin/user.moon
executer/app/routes.coffee

index cd18b101faeaebc5a2a8124fe4648684f3a0e303..04c437920dfc68c0028e0e64812cc80bcdfe8129 100644 (file)
@@ -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
index c16d4b4a0e86d9ed22c13053b8f8bfda8d5de51a..0f3bc6b0490f3c1350d0200f16ee54ae73ebdff5 100644 (file)
@@ -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 (file)
index 0000000..4fec66e
--- /dev/null
@@ -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
index 7079233f03b2b788ef25539277c2fd9dc19ac6e8..45c119da4df7f58f5f3657929c08f2a359f9e172 100644 (file)
@@ -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'
index 8981baf7dcce76d27c62e2fa21175fc23f6cf465..6ba85b5821d64994c5edc6a28078c97738feecd5 100644 (file)
@@ -21,6 +21,3 @@ make_controller
                        yield_error "Job not found"
 
                render: "admin.submission.edit"
-
-       post: capture_errors_json =>
-               json: { 'success': true }
index 8c07245ae48996abb4747981ce4ddcedb9906206..501936772671bd69bedc9a25388d7391e968169e 100644 (file)
@@ -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
index a7872b1742b0c6304afe32ec98ff4c0584a1c8ee..c507119415b4eb5d5503575a2f598114bff967ef 100644 (file)
@@ -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}"
index d45e58580823bbb9a7a6e03ab4cb0c8753afe89e..9380719664e117061f60fc2329d1178b87ea5baf 100644 (file)
@@ -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
index ae68b2f2953eaf4f3cd4e70a1142c7ae085d8582..4f7619d9bfcd8b4c9038261a9cbe11c970e3acb0 100644 (file)
@@ -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}"
index c2eb91f5b3cb321e67b2449802da5e79785e45f4..c7f97a35c25bd8d226b59dfc97f80f4800d8116f 100644 (file)
@@ -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()