diff --git a/csp/contests/unpriv_main_page.csp b/csp/contests/unpriv_main_page.csp index c09850233..39428a417 100644 --- a/csp/contests/unpriv_main_page.csp +++ b/csp/contests/unpriv_main_page.csp @@ -16,6 +16,18 @@ ns_unparse_statement( const unsigned char *bb, int is_submittable); +int +compare_prob_with_start_date_name(const int * l, const int * r, const struct section_problem_data **probs) { + if (probs[*l]->start_date > probs[*r]->start_date) { + return -1; + } + if (probs[*l]->start_date < probs[*r]->start_date) { + return 1; + } + // qsort is unstable that why use id as stabilization + return *l - *r; +} + void ns_unparse_answers( FILE *fout, @@ -278,11 +290,22 @@ ns_unparse_answers( // vertical navigation bar %><% prev_group_name[0] = 0; - - for (i = 1, j = 0; i <= cs->max_prob; i++) { + int probs = 0; + int indexes[cs->max_prob]; + for (i = 1; i <= cs->max_prob; i++) { if (!(prob = cs->probs[i])) continue; if (!(pinfo[i].status & PROB_STATUS_TABABLE)) continue; + indexes[probs] = i; + ++probs; + } + if (global->vertical_navigation_sdate_sort > 0) { + qsort_r(indexes, probs, sizeof(indexes[0]), compare_prob_with_start_date_name, cs->probs); + } + for (j = 0; j < probs; ++j) { + i = indexes[j]; + if (!(prob = cs->probs[i])) continue; + if (!(pinfo[i].status & PROB_STATUS_TABABLE)) continue; if (prob->group_name && strcmp(prob->group_name, prev_group_name)) { %>
<% snprintf(prev_group_name, sizeof(prev_group_name), "%s", prob->group_name); @@ -303,7 +326,6 @@ ns_unparse_answers( } %><% %><% - j++; } %> <% diff --git a/csp/super-server/cnts_edit_cur_global_page.csp b/csp/super-server/cnts_edit_cur_global_page.csp index 1dbe0f7a3..6c789189b 100644 --- a/csp/super-server/cnts_edit_cur_global_page.csp +++ b/csp/super-server/cnts_edit_cur_global_page.csp @@ -44,6 +44,7 @@ static const unsigned char MSG_disable_user_standings[] = "Disable build-in stan static const unsigned char MSG_disable_language[] = "Disable language column in new-client"; static const unsigned char MSG_problem_navigation[] = "Advanced problem navigation"; static const unsigned char MSG_vertical_navigation[] = "Place problem navigation vertically"; +static const unsigned char MSG_vertical_navigation_sdate_sort[] = "Sort problem navigation vertically with problem start_date descending"; static const unsigned char MSG_disable_virtual_start[] = "Disable user Virtual start button"; static const unsigned char MSG_disable_virtual_auto_judge[] = "Disable auto-judging after virtual olympiad"; static const unsigned char MSG_enable_auto_print_protocol[] = "Enable automatic protocol printing"; @@ -328,6 +329,7 @@ static const unsigned char * const form_row_attrs[]= <%@expand EDIT_BOOL_ROW "disable_language" "caps" "400px" %> <%@expand EDIT_BOOL_ROW "problem_navigation" "caps" "400px" %> <%@expand EDIT_BOOL_ROW "vertical_navigation" "caps" "400px" %> + <%@expand EDIT_BOOL_ROW "vertical_navigation_sdate_sort" "caps" "400px" %> <%@expand EDIT_BOOL_ROW "disable_virtual_start" "caps" "400px" %> <%@expand EDIT_BOOL_ROW "disable_virtual_auto_judge" "caps" "400px" %> <%@expand EDIT_BOOL_ROW "enable_auto_print_protocol" "caps" "400px" %> @@ -896,6 +898,7 @@ function popupCapsDialog(e, skipField) "disable_language", "problem_navigation", "vertical_navigation", + "vertical_navigation_sdate_sort", "disable_virtual_start", "disable_virtual_auto_judge", "enable_auto_print_protocol", @@ -926,6 +929,7 @@ function capsDialogOnChange() $("#caps-disable_banner_page-div").toggle($("#caps-enable_printing").is(':checked')); $("#caps-printout_uses_login-div").toggle($("#caps-enable_printing").is(':checked') && $("#caps-disable_banner_page").is(':checked')); $("#caps-vertical_navigation-div").toggle($("#caps-problem_navigation").is(':checked')); + $("#caps-vertical_navigation_sdate_sort-div").toggle($("#caps-problem_navigation").is(':checked')); $("#caps-disable_virtual_start-div").toggle(); $("#caps-disable_virtual_auto_judge-div").toggle(); $("#caps-enable_auto_print_protocol-div").toggle(); @@ -1438,6 +1442,7 @@ function advancedDialogOnChange() <%@expand ORIG_BOOL_ROW "disable_language" %> <%@expand ORIG_BOOL_ROW "problem_navigation" %> <%@expand ORIG_BOOL_ROW "vertical_navigation" %> + <%@expand ORIG_BOOL_ROW "vertical_navigation_sdate_sort" %> <%@expand ORIG_BOOL_ROW "disable_virtual_start" %> <%@expand ORIG_BOOL_ROW "disable_virtual_auto_judge" %> <%@expand ORIG_BOOL_ROW "enable_auto_print_protocol" %> diff --git a/csp/super-server/glob_save_capabilities_form.csp b/csp/super-server/glob_save_capabilities_form.csp index 336f46f59..29775546f 100644 --- a/csp/super-server/glob_save_capabilities_form.csp +++ b/csp/super-server/glob_save_capabilities_form.csp @@ -35,6 +35,7 @@ ejintbool_t disable_language = 0; ejintbool_t problem_navigation = 0; ejintbool_t vertical_navigation = 0; + ejintbool_t vertical_navigation_sdate_sort = 0; ejintbool_t disable_virtual_start = 0; ejintbool_t disable_virtual_auto_judge = 0; ejintbool_t enable_auto_print_protocol = 0; @@ -72,6 +73,7 @@ %><% %><% %><% +%><% %><% %><% %><% @@ -109,6 +111,7 @@ global->disable_language = disable_language; global->problem_navigation = problem_navigation; global->vertical_navigation = vertical_navigation; + global->vertical_navigation_sdate_sort = vertical_navigation_sdate_sort; global->disable_virtual_start = disable_virtual_start; global->disable_virtual_auto_judge = disable_virtual_auto_judge; global->enable_auto_print_protocol = enable_auto_print_protocol; diff --git a/gen/prepare_meta.c b/gen/prepare_meta.c index 954ca8291..8ef08d479 100644 --- a/gen/prepare_meta.c +++ b/gen/prepare_meta.c @@ -66,6 +66,7 @@ static struct meta_info_item meta_info_section_global_data_data[] = [CNTSGLOB_problem_navigation] = { CNTSGLOB_problem_navigation, 'B', XSIZE(struct section_global_data, problem_navigation), "problem_navigation", XOFFSET(struct section_global_data, problem_navigation) }, [CNTSGLOB_problem_tab_size] = { CNTSGLOB_problem_tab_size, 'i', XSIZE(struct section_global_data, problem_tab_size), "problem_tab_size", XOFFSET(struct section_global_data, problem_tab_size) }, [CNTSGLOB_vertical_navigation] = { CNTSGLOB_vertical_navigation, 'B', XSIZE(struct section_global_data, vertical_navigation), "vertical_navigation", XOFFSET(struct section_global_data, vertical_navigation) }, + [CNTSGLOB_vertical_navigation_sdate_sort] = { CNTSGLOB_vertical_navigation_sdate_sort, 'B', XSIZE(struct section_global_data, vertical_navigation_sdate_sort), "vertical_navigation_sdate_sort", XOFFSET(struct section_global_data, vertical_navigation_sdate_sort) }, [CNTSGLOB_disable_virtual_start] = { CNTSGLOB_disable_virtual_start, 'B', XSIZE(struct section_global_data, disable_virtual_start), "disable_virtual_start", XOFFSET(struct section_global_data, disable_virtual_start) }, [CNTSGLOB_disable_virtual_auto_judge] = { CNTSGLOB_disable_virtual_auto_judge, 'B', XSIZE(struct section_global_data, disable_virtual_auto_judge), "disable_virtual_auto_judge", XOFFSET(struct section_global_data, disable_virtual_auto_judge) }, [CNTSGLOB_enable_auto_print_protocol] = { CNTSGLOB_enable_auto_print_protocol, 'B', XSIZE(struct section_global_data, enable_auto_print_protocol), "enable_auto_print_protocol", XOFFSET(struct section_global_data, enable_auto_print_protocol) }, diff --git a/include/ejudge/meta/prepare_meta.h b/include/ejudge/meta/prepare_meta.h index f754cd600..01da39845 100644 --- a/include/ejudge/meta/prepare_meta.h +++ b/include/ejudge/meta/prepare_meta.h @@ -61,6 +61,7 @@ enum CNTSGLOB_problem_navigation, CNTSGLOB_problem_tab_size, CNTSGLOB_vertical_navigation, + CNTSGLOB_vertical_navigation_sdate_sort, CNTSGLOB_disable_virtual_start, CNTSGLOB_disable_virtual_auto_judge, CNTSGLOB_enable_auto_print_protocol, diff --git a/include/ejudge/prepare.h b/include/ejudge/prepare.h index 9cd1376ea..8250fcd38 100644 --- a/include/ejudge/prepare.h +++ b/include/ejudge/prepare.h @@ -264,6 +264,8 @@ struct section_global_data int problem_tab_size; /** display problem tabs vertically */ ejintbool_t vertical_navigation; + /** use start_date sort order instead of problem id */ + ejintbool_t vertical_navigation_sdate_sort; /** disable "virtual start" command for contestants */ ejintbool_t disable_virtual_start; /** disable auto-judging after virtual olympiad is finished for a user */ diff --git a/include/ejudge/prepare_dflt.h b/include/ejudge/prepare_dflt.h index b73fda953..2569ae26d 100644 --- a/include/ejudge/prepare_dflt.h +++ b/include/ejudge/prepare_dflt.h @@ -114,6 +114,7 @@ #define DFLT_G_DISABLE_LANGUAGE 0 #define DFLT_G_PROBLEM_NAVIGATION 0 #define DFLT_G_VERTICAL_NAVIGATION 0 +#define DFLT_G_VERTICAL_NAVIGATION_SDATE_SORT 0 #define DFLT_G_DISABLE_VIRTUAL_START 0 #define DFLT_G_DISABLE_VIRTUAL_AUTO_JUDGE 0 #define DFLT_G_ENABLE_AUTO_PRINT_PROTOCOL 0 diff --git a/lib/prepare.c b/lib/prepare.c index 6fa009631..c299dfacc 100644 --- a/lib/prepare.c +++ b/lib/prepare.c @@ -108,6 +108,7 @@ static const struct config_parse_info section_global_params[] = GLOBAL_PARAM(problem_navigation, "d"), GLOBAL_PARAM(problem_tab_size, "d"), GLOBAL_PARAM(vertical_navigation, "d"), + GLOBAL_PARAM(vertical_navigation_sdate_sort, "d"), GLOBAL_PARAM(disable_virtual_start, "d"), GLOBAL_PARAM(disable_virtual_auto_judge, "d"), GLOBAL_PARAM(enable_auto_print_protocol, "d"), @@ -884,6 +885,7 @@ global_init_func(struct generic_section_config *gp) p->disable_language = -1; p->problem_navigation = -1; p->vertical_navigation = -1; + p->vertical_navigation_sdate_sort = -1; p->disable_virtual_start = -1; p->disable_virtual_auto_judge = -1; p->enable_auto_print_protocol = -1; @@ -2826,6 +2828,8 @@ set_defaults( g->problem_navigation = DFLT_G_PROBLEM_NAVIGATION; if (g->vertical_navigation == -1) g->vertical_navigation = DFLT_G_VERTICAL_NAVIGATION; + if (g->vertical_navigation_sdate_sort == -1) + g->vertical_navigation_sdate_sort = DFLT_G_VERTICAL_NAVIGATION_SDATE_SORT; if (g->disable_virtual_start == -1) g->disable_virtual_start = DFLT_G_DISABLE_VIRTUAL_START; if (g->disable_virtual_auto_judge == -1) @@ -5474,6 +5478,7 @@ prepare_set_global_defaults( if (g->disable_language < 0) g->disable_language = DFLT_G_DISABLE_LANGUAGE; if (g->problem_navigation < 0) g->problem_navigation = DFLT_G_PROBLEM_NAVIGATION; if (g->vertical_navigation < 0) g->vertical_navigation = DFLT_G_VERTICAL_NAVIGATION; + if (g->vertical_navigation_sdate_sort < 0) g->vertical_navigation_sdate_sort = DFLT_G_VERTICAL_NAVIGATION_SDATE_SORT; if (g->disable_virtual_start < 0) g->disable_virtual_start = DFLT_G_DISABLE_VIRTUAL_START; if (g->disable_virtual_auto_judge < 0) g->disable_virtual_auto_judge = DFLT_G_DISABLE_VIRTUAL_AUTO_JUDGE; if (g->enable_auto_print_protocol < 0) g->enable_auto_print_protocol = DFLT_G_ENABLE_AUTO_PRINT_PROTOCOL; @@ -5758,6 +5763,7 @@ prepare_new_global_section(int contest_id, const unsigned char *root_dir, global->disable_language = DFLT_G_DISABLE_LANGUAGE; global->problem_navigation = 1; global->vertical_navigation = DFLT_G_VERTICAL_NAVIGATION; + global->vertical_navigation_sdate_sort = DFLT_G_VERTICAL_NAVIGATION_SDATE_SORT; global->disable_virtual_start = DFLT_G_DISABLE_VIRTUAL_START; global->disable_virtual_auto_judge = DFLT_G_DISABLE_VIRTUAL_AUTO_JUDGE; global->enable_auto_print_protocol = DFLT_G_ENABLE_AUTO_PRINT_PROTOCOL; diff --git a/lib/prepare_out.c b/lib/prepare_out.c index eb7513cc4..f05377991 100644 --- a/lib/prepare_out.c +++ b/lib/prepare_out.c @@ -266,6 +266,8 @@ prepare_unparse_global( unparse_bool(f, "problem_navigation", global->problem_navigation); if (global->vertical_navigation != DFLT_G_VERTICAL_NAVIGATION) unparse_bool(f, "vertical_navigation", global->vertical_navigation); + if (global->vertical_navigation_sdate_sort != DFLT_G_VERTICAL_NAVIGATION_SDATE_SORT) + unparse_bool(f, "vertical_navigation_sdate_sort", global->vertical_navigation_sdate_sort); if (global->disable_virtual_start != DFLT_G_DISABLE_VIRTUAL_START) unparse_bool(f, "disable_virtual_start", global->disable_virtual_start); if (global->disable_virtual_auto_judge != DFLT_G_DISABLE_VIRTUAL_AUTO_JUDGE)