Skip to content

Commit

Permalink
sim: ui: submissions page: use new API to list submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
varqox committed Nov 3, 2024
1 parent 30c1694 commit fc9a33b
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 242 deletions.
1 change: 1 addition & 0 deletions subprojects/sim/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ sim_server = executable('sim-server',
'src/web_server/server/connection.cc',
'src/web_server/server/server.cc',
'src/web_server/submissions/api.cc',
'src/web_server/submissions/ui.cc',
'src/web_server/ui/ui.cc',
'src/web_server/ui_template.cc',
'src/web_server/users/api.cc',
Expand Down
26 changes: 0 additions & 26 deletions subprojects/sim/src/web_server/old/submissions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,6 @@ void Sim::submissions_handle() {
if (is_digit(next_arg)) { // View submission
page_template(from_unsafe{concat("Submission ", next_arg)});
append("view_submission(false, ", next_arg, ", window.location.hash);");

} else if (next_arg.empty()) { // List submissions
page_template("Submissions");
// clang-format off
append("document.body.appendChild(elem_with_text('h1', 'Submissions'));"
"$(document).ready(function(){"
"var main = $('body');"
"var tabs = [];"
"if (signed_user_is_admin()) {"
"tabs.push('All submissions', function() {"
"main.children('.old_tabmenu + div, .loader,.loader-info').remove();"
"tab_submissions_lister($('<div>').appendTo(main),'', true);"
"});"
"}"
"if (is_signed_in()) {"
"tabs.push('My submissions', function() {"
"main.children('.old_tabmenu + div, .loader,.loader-info').remove();"
"tab_submissions_lister($('<div>').appendTo(main),"
"'/u' + signed_user_id);"
"});"
"}"
"old_tabmenu(function(x) { x.appendTo(main); }, tabs);"
"});"
);
// clang-format on

} else {
return error404();
}
Expand Down
578 changes: 408 additions & 170 deletions subprojects/sim/src/web_server/static/kit/scripts.js

Large diffs are not rendered by default.

88 changes: 42 additions & 46 deletions subprojects/sim/src/web_server/static/kit/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1614,62 +1614,87 @@ table.code-view > tbody > tr:last-child td {

/* Submissions */
table.submissions {
/*display: inline-table;*/
margin: 6px 0;
}
table.submissions th {
padding: 6px;
line-height: 20px;
}
table.submissions th.user {
table.submissions tr.ignored {
background: #e5e5e5;
color: #444;
}
table.submissions td {
padding: 3px 16px 3px 8px;
border-top: 1px solid #bbb;
}
table.submissions td:first-child {
text-align: right;
}
table.submissions td.user {
text-align: center;
}
table.submissions td.status {
padding-left: 20px;
padding-right: 20px;
text-align: center;
}

table.old-submissions {
margin: 6px 0;
}
table.old-submissions th {
padding: 6px;
line-height: 20px;
}
table.old-submissions th.user {
/*min-width: 60px;*/
}
table.submissions th.full-name {
table.old-submissions th.full-name {
/*min-width: 60px;*/
}
table.submissions th.time {
table.old-submissions th.time {
min-width: 100px;
}
table.submissions th.problem {
table.old-submissions th.problem {
/*min-width: 135px;*/
}
table.submissions th.status {
table.old-submissions th.status {
/*min-width: 190px;*/
}
table.submissions th.score {
table.old-submissions th.score {
/*min-width: 60px;*/
}
table.submissions th.type {
table.old-submissions th.type {
/*min-width: 60px;*/
}
table.submissions tr > td:first-child {
table.old-submissions tr > td:first-child {
text-align: right;
}
table.submissions td > a {
table.old-submissions td > a {
/*white-space: nowrap;*/
}
table.submissions tr.ignored,
table.old-submissions tr.ignored,
.submission-info table tr.ignored {
background: #e5e5e5;
color: #444;
}
table.submissions td {
table.old-submissions td {
padding: 4px 16px 4px 8px;
line-height: 20px;
border-top: 1px solid #bbb;
}
table.submissions td.status {
table.old-submissions td.status {
padding-left: 20px;
padding-right: 20px;
text-align: center;
}
table.submissions tr > td:last-child {
table.old-submissions tr > td:last-child {
/*white-space: pre;*/
}

/* Problems */
table.problems {
/*display: inline-table;*/
margin: 6px 0;
}
table.problems th {
Expand All @@ -1692,13 +1717,9 @@ table.problems tr > td:first-child {
text-align: right;
}
table.problems td {
padding: 4px 16px 4px 8px;
line-height: 20px;
padding: 3px 16px 3px 8px;
border-top: 1px solid #bbb;
}
table.problems tr > td:last-child {
/*white-space: pre;*/
}
table.problems .name_and_tags,
.problem-info .tags-row {
display: flex;
Expand All @@ -1716,7 +1737,6 @@ table.problems .tags {

/* Attaching contest problems */
table.attaching-contest-problems {
/*display: inline-table;*/
margin: 6px 0;
}
table.attaching-contest-problems th {
Expand Down Expand Up @@ -1845,44 +1865,20 @@ table.users,
table.contest-users {
margin: 6px 0;
}
table.users th.username,
table.contest-users th.username {
/*min-width: 90px;*/
}
table.users th.first-name,
table.users th.last-name,
table.contest-users th.first-name,
table.contest-users th.last-name {
/*min-width: 100px;*/
}
table.users th.email {
/*min-width: 120px;*/
}
table.users th.type {
/*min-width: 90px;*/
}
table.contest-users th.mode {
/*min-width: 110px;*/
}
table.users th,
table.contest-users th {
padding: 6px;
line-height: 20px;
}
table.users td,
table.contest-users td {
padding: 4px 24px 4px 8px;
line-height: 20px;
padding: 3px 16px 3px 8px;
border-top: 1px solid #bbb;
}
table.users tr > td:first-child,
table.contest-users tr > td:first-child {
text-align: right;
}
table.users tr > td:last-child,
table.contest-users tr > td:last-child {
/*white-space: pre;*/
}

/* User-info, problem-info */
.user-info,
Expand Down
14 changes: 14 additions & 0 deletions subprojects/sim/src/web_server/submissions/ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "../http/response.hh"
#include "../web_worker/context.hh"
#include "ui.hh"

using web_server::http::Response;
using web_server::web_worker::Context;

namespace web_server::submissions::ui {

Response list_submissions(Context& ctx) {
return ctx.response_ui("Submissions", "list_submissions()");
}

} // namespace web_server::submissions::ui
10 changes: 10 additions & 0 deletions subprojects/sim/src/web_server/submissions/ui.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "../http/response.hh"
#include "../web_worker/context.hh"

namespace web_server::submissions::ui {

http::Response list_submissions(web_worker::Context& ctx);

} // namespace web_server::submissions::ui
27 changes: 27 additions & 0 deletions subprojects/sim/src/web_server/ui_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ std::string sim_template_params(const decltype(web_worker::Context::session)& se
caps.add_problem_with_visibility_contest_only
);
obj.prop("add_problem_with_visibility_public", caps.add_problem_with_visibility_public);

auto fill_with_list_caps = [&](auto& obj,
const capabilities::ProblemsListCapabilities caps) {
obj.prop("query_all", caps.query_all);
Expand All @@ -145,6 +146,32 @@ std::string sim_template_params(const decltype(web_worker::Context::session)& se
});
obj.prop_obj("submissions", [&](auto& obj) {
obj.prop("ui_view", capabilities::submissions(session).web_ui_view);
obj.prop_obj("list_all", [&](auto& obj) {
const auto caps = capabilities::list_submissions(session);
obj.prop("query_all", caps.query_all);
obj.prop("query_with_type_final", caps.query_with_type_final);
obj.prop("query_with_type_problem_final", caps.query_with_type_problem_final);
obj.prop(
"query_with_type_contest_problem_final",
caps.query_with_type_contest_problem_final
);
obj.prop("query_with_type_ignored", caps.query_with_type_ignored);
obj.prop("query_with_type_problem_solution", caps.query_with_type_problem_solution);
});
if (session) {
obj.prop_obj("list_my", [&](auto& obj) {
const auto caps =
capabilities::list_user_submissions(session, session->user_id);
obj.prop("query_all", caps.query_all);
obj.prop("query_with_type_final", caps.query_with_type_final);
obj.prop("query_with_type_problem_final", caps.query_with_type_problem_final);
obj.prop(
"query_with_type_contest_problem_final",
caps.query_with_type_contest_problem_final
);
obj.prop("query_with_type_ignored", caps.query_with_type_ignored);
});
}
});
obj.prop_obj("users", [&](auto& obj) {
const auto caps = capabilities::users(session);
Expand Down
2 changes: 2 additions & 0 deletions subprojects/sim/src/web_server/web_worker/web_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../problems/api.hh"
#include "../problems/ui.hh"
#include "../submissions/api.hh"
#include "../submissions/ui.hh"
#include "../ui/ui.hh"
#include "../users/api.hh"
#include "../users/ui.hh"
Expand Down Expand Up @@ -142,6 +143,7 @@ WebWorker::WebWorker(sim::mysql::Connection& mysql) : mysql{mysql} {
GET("/sign_in")(users::ui::sign_in);
GET("/sign_out")(users::ui::sign_out);
GET("/sign_up")(users::ui::sign_up);
GET("/submissions")(submissions::ui::list_submissions);
GET("/ui/{string}/jquery.js")(ui::jquery_js);
GET("/ui/{string}/scripts.js")(ui::scripts_js);
GET("/ui/{string}/styles.css")(ui::styles_css);
Expand Down

0 comments on commit fc9a33b

Please sign in to comment.