List for cgit developers and users
 help / color / mirror / Atom feed
From: tim.nordell at logicpd.com (Tim Nordell)
Subject: [PATCH v2 8/8] ui-repolist: Support a trimmed view when several sections are present
Date: Fri, 4 Mar 2016 17:30:36 -0600	[thread overview]
Message-ID: <1457134236-9758-1-git-send-email-tim.nordell@logicpd.com> (raw)
In-Reply-To: <1457133901-12998-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/ui-repolist.c b/ui-repolist.c
index 93655d4..ff70ddc 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -278,6 +278,8 @@ struct repolist_ctx {
 	 * (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)
@@ -375,6 +377,51 @@ static int generate_repolist(struct repolist_ctx *c, struct cgit_repo *repo)
 	return 0;
 }
 
+static int generate_sectionlist(struct repolist_ctx *c, struct cgit_repo *repo)
+{
+	bool is_toplevel;
+
+	is_toplevel = (NULL == repo->section || repo->section[0] == '\0');
+
+	if (!should_emit_section(c, repo) && !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 repolist_ctx *c, struct cgit_repo *repo)
+{
+	const char *last_section;
+
+	last_section = c->last_section;
+	if (should_emit_section(c, repo)) {
+		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 &&
+		    last_section[strspn(last_section, repo->section)] == '\0')
+			c->section_nested_cnt++;
+	}
+
+	c->hits++;
+
+	return 0;
+}
+
 typedef int (*repolist_walk_callback_t)(struct repolist_ctx *c, struct cgit_repo *repo);
 static int repolist_walk_visible(struct repolist_ctx *c, repolist_walk_callback_t callback)
 {
@@ -383,6 +430,8 @@ static int repolist_walk_visible(struct repolist_ctx *c, repolist_walk_callback_
 
 	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];
@@ -396,6 +445,7 @@ static int repolist_walk_visible(struct repolist_ctx *c, repolist_walk_callback_
 
 void cgit_print_repolist(void)
 {
+	bool section_pages = false;
 	struct repolist_ctx repolist_ctx;
 
 	repolist_ctx.columns      = 3;
@@ -421,12 +471,23 @@ void cgit_print_repolist(void)
 
 	if (ctx.qry.sort)
 		repolist_ctx.sorted = sort_repolist(ctx.qry.sort);
-	else if (ctx.cfg.section_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();
-	repolist_walk_visible(&repolist_ctx, generate_repolist);
+
+	if (section_pages)
+		repolist_walk_visible(&repolist_ctx, count_sections);
+
+	if (section_pages && repolist_ctx.hits > ctx.cfg.max_repo_count &&
+		repolist_ctx.section_cnt - repolist_ctx.section_nested_cnt > 1)
+		repolist_walk_visible(&repolist_ctx, generate_sectionlist);
+	else
+		repolist_walk_visible(&repolist_ctx, generate_repolist);
+
 	html("</table>");
 	if (repolist_ctx.hits > ctx.cfg.max_repo_count)
 		print_pager(repolist_ctx.hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
-- 
2.4.9



      parent reply	other threads:[~2016-03-04 23:30 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 ` [PATCH 3/3] ui-repolist: Support a trimmed view when several sections are present tim.nordell
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   ` tim.nordell [this message]

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=1457134236-9758-1-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).