From: tim.nordell at logicpd.com (Tim Nordell)
Subject: [PATCH 3/3] ui-repolist: Support a trimmed view when several sections are present
Date: Fri, 26 Feb 2016 14:58:59 -0600 [thread overview]
Message-ID: <1456520339-32708-4-git-send-email-tim.nordell@logicpd.com> (raw)
In-Reply-To: <1456520339-32708-1-git-send-email-tim.nordell@logicpd.com>
Trim the view to just a section list if there are multiple
sections present in the output view. This is only really useful
if one also has a script placing links on each section heading to
trim the view by path.
Signed-off-by: Tim Nordell <tim.nordell at logicpd.com>
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 113b7a0..2658e89 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -413,9 +413,14 @@ section-filter::
section-sort::
Flag which, when set to "1", will sort the sections on the repository
- listing by name. Set this flag to "0" if the order in the cgitrc file should
- be preserved. Default value: "1". See also: section,
- case-sensitive-sort, repository-sort.
+ listing by name. When set to "2", this will collapse the listing of
+ repositories (when over the size max-repo-count) into just the list
+ of sections. This is only really useful if section filters are also
+ enabled, if the filter makes links into the URL that the section
+ comprises, and if all section headings are paths. Set this flag to
+ "0" if the order in the cgitrc file should be preserved.
+ Default value: "1". See also: section, case-sensitive-sort,
+ repository-sort, section-filter
section-from-path::
A number which, if defined prior to scan-path, specifies how many
diff --git a/ui-repolist.c b/ui-repolist.c
index 6b06a1a..9045203 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -278,6 +278,8 @@ struct repolist_ctx
/* Used in interior context; should be reset in repolist_walk_visible() */
int hits;
const char *last_section;
+ int section_cnt;
+ int section_nested_cnt;
};
static void html_section(struct cgit_repo *repo, int columns)
@@ -374,6 +376,57 @@ static int generate_repolist(struct cgit_repo *repo, struct repolist_ctx *c)
return 0;
}
+static int generate_sectionlist(struct cgit_repo *repo, struct repolist_ctx *c)
+{
+ bool is_toplevel;
+
+ is_toplevel = (NULL == repo->section || repo->section[0] == '\0');
+
+ if(!should_emit_section(repo, c) && !is_toplevel)
+ return 0;
+
+ c->hits++;
+
+ if (c->hits <= ctx.qry.ofs)
+ return 0;
+ if (c->hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
+ return 0;
+
+ if(is_toplevel)
+ html_repository(repo, c->sorted);
+ else
+ html_section(repo, c->columns);
+
+ return 0;
+}
+
+static int count_sections(struct cgit_repo *repo, struct repolist_ctx *c)
+{
+ const char *last_section;
+
+ last_section = c->last_section;
+ if(should_emit_section(repo, c))
+ {
+ c->section_cnt++;
+
+ /* Determine if one section is nested within the other. This
+ * is only accurate if this is a sorted list.
+ */
+ if(NULL != last_section && NULL != repo->section)
+ {
+ int spn = strspn(last_section, repo->section);
+ if(last_section[spn] == '\0')
+ {
+ c->section_nested_cnt++;
+ }
+ }
+ }
+
+ c->hits++;
+
+ return 0;
+}
+
typedef int (*repolist_walk_callback_t)(struct cgit_repo *repo, struct repolist_ctx *c);
static int repolist_walk_visible(repolist_walk_callback_t callback, struct repolist_ctx *c)
{
@@ -382,6 +435,8 @@ static int repolist_walk_visible(repolist_walk_callback_t callback, struct repol
c->hits = 0;
c->last_section = NULL;
+ c->section_cnt = 0;
+ c->section_nested_cnt = 0;
for (i = 0; i < cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i];
@@ -395,6 +450,7 @@ static int repolist_walk_visible(repolist_walk_callback_t callback, struct repol
void cgit_print_repolist(void)
{
+ bool section_pages = false;
struct repolist_ctx repolist_ctx = {0};
repolist_ctx.columns = 3;
@@ -420,13 +476,24 @@ void cgit_print_repolist(void)
if (ctx.qry.sort)
repolist_ctx.sorted = sort_repolist(ctx.qry.sort);
else if (ctx.cfg.section_sort)
+ {
sort_repolist("section");
+ section_pages = (2 == ctx.cfg.section_sort);
+ }
html("<table summary='repository list' class='list nowrap'>");
print_header();
- /* Count visible repositories */
- repolist_walk_visible(generate_repolist, &repolist_ctx);
+ if(section_pages)
+ repolist_walk_visible(count_sections, &repolist_ctx);
+
+ if(section_pages && repolist_ctx.hits > ctx.cfg.max_repo_count &&
+ repolist_ctx.section_cnt - repolist_ctx.section_nested_cnt > 1)
+ {
+ repolist_walk_visible(generate_sectionlist, &repolist_ctx);
+ } else {
+ repolist_walk_visible(generate_repolist, &repolist_ctx);
+ }
html("</table>");
if (repolist_ctx.hits > ctx.cfg.max_repo_count)
--
2.4.9
next prev parent reply other threads:[~2016-02-26 20:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 20:58 [PATCH 0/3] ui-repolist: Support additional formatting for sections tim.nordell
2016-02-26 20:58 ` [PATCH 1/3] ui-repolist: Add section filter tim.nordell
2016-02-28 12:51 ` john
2016-02-26 20:58 ` [PATCH 2/3] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-02-28 13:02 ` john
2016-02-29 20:51 ` tim.nordell
2016-02-26 20:58 ` tim.nordell [this message]
2016-03-04 23:24 ` [PATCH v2 0/8] ui-repolist: Support additional formatting for sections tim.nordell
2016-03-04 23:24 ` [PATCH v2 1/8] ui-repolist: Add section filter tim.nordell
2016-03-04 23:24 ` [PATCH v2 2/8] ui-repolist: Remove conditional around print_header() tim.nordell
2016-03-04 23:24 ` [PATCH v2 3/8] ui-repolist: Create context structure for cgit_print_repolist() tim.nordell
2016-03-04 23:24 ` [PATCH v2 4/8] ui-repolist: Move HTML generation into helper functions tim.nordell
2016-03-04 23:29 ` [PATCH v2 5/8] ui-repolist: Factor out logic for emitting a new section heading tim.nordell
2016-03-04 23:30 ` [PATCH v2 6/8] ui-repolist: Remove assignment of section to repolist_ctx tim.nordell
2016-03-04 23:30 ` [PATCH v2 7/8] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-03-04 23:30 ` [PATCH v2 8/8] ui-repolist: Support a trimmed view when several sections are present tim.nordell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456520339-32708-4-git-send-email-tim.nordell@logicpd.com \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).