From 1a66e7f3c15bf8d0d5d1b198c6674911a213779e Mon Sep 17 00:00:00 2001 From: Andy Doan Date: Mon, 12 Sep 2016 22:54:08 -0500 Subject: ui-repolist: Allow sections to be collapsible The index page can be difficult to navigate for really large git servers. This change allows a configuration like: section-collapse=people section-collapse=tests And an index page would only display the "people" and "tests" section headers entries (not their repos) with a hyperlink that can be used to drill down into each section. Additionally the boolean logic around displaying sections in ui-repolist.c was simplified to eliminate an impossible condition. Signed-off-by: Andy Doan Reviewed-by: John Keeping Signed-off-by: John Keeping --- ui-repolist.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'ui-repolist.c') diff --git a/ui-repolist.c b/ui-repolist.c index 3f967a8..e9676b8 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -188,10 +188,16 @@ static int sort_section(const void *a, const void *b) { const struct cgit_repo *r1 = a; const struct cgit_repo *r2 = b; + const char *s1 = ""; + const char *s2 = ""; int result; time_t t; - result = cmp(r1->section, r2->section); + if (r1->section) + s1 = r1->section->name; + if (r2->section) + s2 = r2->section->name; + result = cmp(s1, s2); if (!result) { if (!strcmp(ctx.cfg.repository_sort, "age")) { // get_repo_modtime caches the value in r->mtime, so we don't @@ -273,8 +279,8 @@ static int sort_repolist(char *field) void cgit_print_repolist(void) { int i, columns = 3, hits = 0, header = 0; - char *last_section = NULL; - char *section; + struct cgit_section *last_section = NULL; + struct cgit_section *section; int sorted = 0; if (!any_repos_visible()) { @@ -294,12 +300,10 @@ void cgit_print_repolist(void) if (ctx.cfg.index_header) html_include(ctx.cfg.index_header); - if (ctx.qry.sort) sorted = sort_repolist(ctx.qry.sort); else if (ctx.cfg.section_sort) sort_repolist("section"); - html(""); for (i = 0; i < cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; @@ -313,23 +317,22 @@ void cgit_print_repolist(void) if (!header++) print_header(); section = ctx.repo->section; - if (section && !strcmp(section, "")) + if (section && !strcmp(section->name, "")) section = NULL; - if (!sorted && - ((last_section == NULL && section != NULL) || - (last_section != NULL && section == NULL) || - (last_section != NULL && section != NULL && - strcmp(section, last_section)))) { + if (!sorted && section && last_section != section ) { htmlf(""); - last_section = section; } + last_section = section; + if (section && section->collapse && !strstr(ctx.qry.url, section->name)) + continue; + htmlf("
", columns); html(""); - html_txt(section); + html_txt(section->name); html(""); html("
", !sorted && section ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); -- cgit v1.2.3-57-g22cb