user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [REJECT] view: use <ul>/<li> for threading instead of tables
@ 2015-12-30  1:42 Eric Wong
  2015-12-30 21:44 ` [PATCH] view: thread using <ul> instead of <table> Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2015-12-30  1:42 UTC (permalink / raw)
  To: meta

Rejecting this for now since it eats precious horizontal
whitespace on browsers that can render indentation properly;
and this still doesn't render thread levels properly on lynx.
---
 lib/PublicInbox/View.pm | 53 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index ad90eb3..be92e9f 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -103,11 +103,7 @@ sub index_entry {
 	}
 
 	my $ts = _msg_date($mime);
-	my $rv = "<table\nsummary=l$level><tr>";
-	if ($level) {
-		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
-	}
-	$rv .= "<td\nid=s$midx><pre>";
+	my $rv = "<pre\nid=s$midx>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	$rv .= "- $from @ $ts UTC - ";
 	$rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -155,8 +151,7 @@ sub index_entry {
 				"<a\nhref=\"${path}$href/T/#u\">flat</a>]";
 		}
 	}
-
-	$fh->write($rv .= '</pre></td></tr></table>');
+	$fh->write($rv .= '</pre>');
 }
 
 sub thread_html {
@@ -181,16 +176,20 @@ sub emit_thread_html {
 		seen => $seen,
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
+		max_level => 0,
 	};
 
 	require PublicInbox::Git;
 	my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
 	if ($flat) {
 		pre_anchor_entry($seen, $_) for (@$msgs);
-		__thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs);
+		__thread_entry(\$cb, $git, $state, $_, -1) for (@$msgs);
 	} else {
 		my $th = thread_results($msgs);
 		thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+		my $max = $state->{max_level};
+		$cb->write('</ul></li>' x $max) if $max;
+		$cb->write('</ul>');
 	}
 	$git = undef;
 	Email::Address->purge_cache;
@@ -608,7 +607,7 @@ sub anchor_for {
 }
 
 sub thread_html_head {
-	my ($cb, $header, $state) = @_;
+	my ($cb, $header, $state, $level) = @_;
 	$$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
 
 	my $s = PublicInbox::Hval->new_oneline($header->header('Subject'));
@@ -617,7 +616,7 @@ sub thread_html_head {
 		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
 		qq!href="../t.atom"\ntype="application/atom+xml"/>! .
 		PublicInbox::Hval::STYLE .
-		"</head><body>");
+		'</head><body>' . ($level >= 0 ? '<ul>' : ''));
 }
 
 sub pre_anchor_entry {
@@ -637,12 +636,26 @@ sub ghost_parent {
 	qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub ghost_table {
-	my ($upfx, $mid, $level) = @_;
-	"<table\nsummary=ghost><tr><td>" .
-		(INDENT x $level) . '</td><td><pre>' .
-		ghost_parent($upfx, $mid) .
-		'</pre></td></table>';
+sub __thread_adj_level {
+	my ($cb, $state, $level) = @_;
+
+	return if $level < 0; # flat output
+
+	if ($level > $state->{max_level}) {
+		$state->{max_level} = $level;
+		$$cb->write('<li><ul><li>');
+	} else {
+		$$cb->write('<li>');
+	}
+}
+
+sub __thread_ghost {
+	my ($cb, $state, $upfx, $mid, $level) = @_;
+
+	__thread_adj_level($cb, $state, $level);
+
+	$$cb->write('<pre>' .  ghost_parent($upfx, $mid) . '</pre>' .
+			($level >= 0 ? '' : '</li>'));
 }
 
 sub __thread_entry {
@@ -655,16 +668,20 @@ sub __thread_entry {
 	} or return;
 
 	if ($state->{anchor_idx} == 0) {
-		thread_html_head($cb, $mime, $state);
+		thread_html_head($cb, $mime, $state, $level);
 	}
 
 	if (my $ghost = delete $state->{ghost}) {
 		# n.b. ghost messages may only be parents, not children
 		foreach my $g (@$ghost) {
-			$$cb->write(ghost_table('../../', @$g));
+			__thread_ghost($cb, $state, '../../', @$g);
 		}
 	}
+	__thread_adj_level($cb, $state, $level);
+
 	index_entry($$cb, $mime, $level, $state);
+	$$cb->write('</li>');
+
 	1;
 }
 
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] view: thread using <ul> instead of <table>
  2015-12-30  1:42 [REJECT] view: use <ul>/<li> for threading instead of tables Eric Wong
@ 2015-12-30 21:44 ` Eric Wong
  2015-12-31  8:22   ` [PATCH] view: fixup indentation nesting in search Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2015-12-30 21:44 UTC (permalink / raw)
  To: meta

On second viewing, this does render small cues which makes the
output more pleasant for lynx users.  We avoid injecting the
root (level=0) message into a list since it still wastes
precious horizontal whitespace on small displays.

This also results in small reductions in bandwidth usage as
it takes fewer tags/whitespace to render unordered lists.
---
 lib/PublicInbox/View.pm | 52 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index ad90eb3..bcd2ebc 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -103,11 +103,7 @@ sub index_entry {
 	}
 
 	my $ts = _msg_date($mime);
-	my $rv = "<table\nsummary=l$level><tr>";
-	if ($level) {
-		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
-	}
-	$rv .= "<td\nid=s$midx><pre>";
+	my $rv = "<pre\nid=s$midx>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	$rv .= "- $from @ $ts UTC - ";
 	$rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -155,8 +151,7 @@ sub index_entry {
 				"<a\nhref=\"${path}$href/T/#u\">flat</a>]";
 		}
 	}
-
-	$fh->write($rv .= '</pre></td></tr></table>');
+	$fh->write($rv .= '</pre>');
 }
 
 sub thread_html {
@@ -181,6 +176,7 @@ sub emit_thread_html {
 		seen => $seen,
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
+		max_level => 0,
 	};
 
 	require PublicInbox::Git;
@@ -191,6 +187,10 @@ sub emit_thread_html {
 	} else {
 		my $th = thread_results($msgs);
 		thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+		if (my $max = $state->{max_level}) {
+			my $x = $max > 1 ? ('</ul></li>' x ($max-1)) : '';
+			$cb->write($x . '</ul>');
+		}
 	}
 	$git = undef;
 	Email::Address->purge_cache;
@@ -637,12 +637,25 @@ sub ghost_parent {
 	qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub ghost_table {
-	my ($upfx, $mid, $level) = @_;
-	"<table\nsummary=ghost><tr><td>" .
-		(INDENT x $level) . '</td><td><pre>' .
-		ghost_parent($upfx, $mid) .
-		'</pre></td></table>';
+sub __thread_adj_level {
+	my ($cb, $state, $level) = @_;
+
+	return if $level <= 0; # flat output
+	my $max = $state->{max_level};
+	if ($level > $max) {
+		$state->{max_level} = $level;
+		$$cb->write(($max ? '<li>' : ''). '<ul><li>');
+	} else {
+		$$cb->write('<li>');
+	}
+}
+
+sub __ghost_flush {
+	my ($cb, $state, $upfx, $mid, $level) = @_;
+
+	__thread_adj_level($cb, $state, $level);
+	$$cb->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' .
+			($level > 0 ? '</li>' : ''));
 }
 
 sub __thread_entry {
@@ -655,20 +668,23 @@ sub __thread_entry {
 	} or return;
 
 	if ($state->{anchor_idx} == 0) {
-		thread_html_head($cb, $mime, $state);
+		thread_html_head($cb, $mime, $state, $level);
 	}
 
 	if (my $ghost = delete $state->{ghost}) {
 		# n.b. ghost messages may only be parents, not children
 		foreach my $g (@$ghost) {
-			$$cb->write(ghost_table('../../', @$g));
+			__ghost_flush($cb, $state, '../../', @$g);
 		}
 	}
+	__thread_adj_level($cb, $state, $level);
 	index_entry($$cb, $mime, $level, $state);
+	$$cb->write('</li>') if $level > 0;
+
 	1;
 }
 
-sub __ghost_entry {
+sub __ghost_prepare {
 	my ($state, $node, $level) = @_;
 	my $ghost = $state->{ghost} ||= [];
 	push @$ghost, [ $node->messageid, $level ];
@@ -679,10 +695,10 @@ sub thread_entry {
 	return unless $node;
 	if (my $mime = $node->message) {
 		unless (__thread_entry($cb, $git, $state, $mime, $level)) {
-			__ghost_entry($state, $node, $level);
+			__ghost_prepare($state, $node, $level);
 		}
 	} else {
-		__ghost_entry($state, $node, $level);
+		__ghost_prepare($state, $node, $level);
 	}
 
 	thread_entry($cb, $git, $state, $node->child, $level + 1);
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] view: fixup indentation nesting in search
  2015-12-30 21:44 ` [PATCH] view: thread using <ul> instead of <table> Eric Wong
@ 2015-12-31  8:22   ` Eric Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-12-31  8:22 UTC (permalink / raw)
  To: meta

Oops, the rarely-accessed threaded search view was completely
broken.  Additionally, the normal threading depths were broken
when we attempted to go up-thread and replies got nested
improperly

Followup to commit be984ce279776d4513b4ca1bff05ebecafdd1bad
("view: thread using <ul> instead of <table>")
---
 lib/PublicInbox/SearchView.pm | 18 +++++++++++---
 lib/PublicInbox/View.pm       | 57 ++++++++++++++++++++++++++-----------------
 2 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index ab3dddb..5d4f4fe 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -138,7 +138,7 @@ sub search_nav_bot {
 sub tdump {
 	my ($cb, $res, $mset, $q, $ctx) = @_;
 	my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
-	$fh->write($res);
+	$fh->write($res .= '</pre>');
 	my %pct;
 	my @m = map {
 		my $i = $_;
@@ -168,9 +168,15 @@ sub tdump {
 	}
 
 	my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
-	my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
+	my $state = {
+		ctx => $ctx,
+		anchor_idx => 0,
+		pct => \%pct,
+		cur_level => 0
+	};
 	$ctx->{searchview} = 1;
 	tdump_ent($fh, $git, $state, $_, 0) for $th->rootset;
+	PublicInbox::View::thread_adj_level($fh, $state, 0);
 	Email::Address->purge_cache;
 
 	$fh->write(search_nav_bot($mset, $q). "\n\n" .
@@ -193,10 +199,13 @@ sub tdump_ent {
 		};
 	}
 	if ($mime) {
+		my $end =
+		  PublicInbox::View::thread_adj_level($fh, $state, $level);
 		PublicInbox::View::index_entry($fh, $mime, $level, $state);
+		$fh->write($end) if $end;
 	} else {
 		my $mid = $node->messageid;
-		$fh->write(PublicInbox::View::ghost_table('', $mid, $level));
+		PublicInbox::View::ghost_flush($fh, $state, '', $mid, $level);
 	}
 	tdump_ent($fh, $git, $state, $node->child, $level + 1);
 	tdump_ent($fh, $git, $state, $node->next, $level);
@@ -214,7 +223,8 @@ sub html_start {
 
 	my $qh = $query->as_html;
 	my $A = $q->qs_html(x => 'A', r => undef);
-	my $res = "<html><head><title>$qh - search results</title>" .
+	my $res = '<html><head>' . PublicInbox::Hval::STYLE .
+		"<title>$qh - search results</title>" .
 		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
 		qq!href="?$A"\ntype="application/atom+xml"/></head>! .
 		qq{<body><form\naction="">} .
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 2040047..fac0fcb 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -176,7 +176,7 @@ sub emit_thread_html {
 		seen => $seen,
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
-		max_level => 0,
+		cur_level => 0,
 	};
 
 	require PublicInbox::Git;
@@ -187,9 +187,8 @@ sub emit_thread_html {
 	} else {
 		my $th = thread_results($msgs);
 		thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
-		if (my $max = $state->{max_level}) {
-			my $x = $max > 1 ? ('</ul></li>' x ($max-1)) : '';
-			$cb->write($x . '</ul>');
+		if (my $max = $state->{cur_level}) {
+			$cb->write(('</ul></li>' x ($max - 1)) . '</ul>');
 		}
 	}
 	$git = undef;
@@ -638,25 +637,37 @@ sub ghost_parent {
 	qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub __thread_adj_level {
-	my ($cb, $state, $level) = @_;
+sub thread_adj_level {
+	my ($fh, $state, $level) = @_;
 
-	return if $level <= 0; # flat output
-	my $max = $state->{max_level};
-	if ($level > $max) {
-		$state->{max_level} = $level;
-		$$cb->write(($max ? '<li>' : ''). '<ul><li>');
-	} else {
-		$$cb->write('<li>');
+	my $max = $state->{cur_level};
+	if ($level <= 0) {
+		return '' if $max == 0; # flat output
+
+		# reset existing lists
+		my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
+		$fh->write($x . '</ul>');
+		$state->{cur_level} = 0;
+		return '';
 	}
+	if ($level == $max) { # continue existing list
+		$fh->write('<li>');
+	} elsif ($level < $max) {
+		my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
+		$fh->write($x .= '<li>');
+		$state->{cur_level} = $level;
+	} else { # ($level > $max) # start a new level
+		$state->{cur_level} = $level;
+		$fh->write(($max ? '<li>' : '') . '<ul><li>');
+	}
+	'</li>';
 }
 
-sub __ghost_flush {
-	my ($cb, $state, $upfx, $mid, $level) = @_;
+sub ghost_flush {
+	my ($fh, $state, $upfx, $mid, $level) = @_;
 
-	__thread_adj_level($cb, $state, $level);
-	$$cb->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' .
-			($level > 0 ? '</li>' : ''));
+	my $end = thread_adj_level($fh, $state, $level);
+	$fh->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' . $end);
 }
 
 sub __thread_entry {
@@ -671,16 +682,16 @@ sub __thread_entry {
 	if ($state->{anchor_idx} == 0) {
 		thread_html_head($cb, $mime, $state, $level);
 	}
-
+	my $fh = $$cb;
 	if (my $ghost = delete $state->{ghost}) {
 		# n.b. ghost messages may only be parents, not children
 		foreach my $g (@$ghost) {
-			__ghost_flush($cb, $state, '../../', @$g);
+			ghost_flush($fh, $state, '../../', @$g);
 		}
 	}
-	__thread_adj_level($cb, $state, $level);
-	index_entry($$cb, $mime, $level, $state);
-	$$cb->write('</li>') if $level > 0;
+	my $end = thread_adj_level($fh, $state, $level);
+	index_entry($fh, $mime, $level, $state);
+	$fh->write($end) if $end;
 
 	1;
 }
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-31  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-30  1:42 [REJECT] view: use <ul>/<li> for threading instead of tables Eric Wong
2015-12-30 21:44 ` [PATCH] view: thread using <ul> instead of <table> Eric Wong
2015-12-31  8:22   ` [PATCH] view: fixup indentation nesting in search Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).