summaryrefslogtreecommitdiff
path: root/lib/VNWeb
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-11-19 11:28:00 +0100
committerYorhel <git@yorhel.nl>2019-11-19 11:28:25 +0100
commitbd2ff24a35ec70aad52ae5352ce349da53ee5248 (patch)
tree227250da094256c5e18345cd0ed2a449d17136d3 /lib/VNWeb
parent3328d1e39868e14bd42cc341c05fdd8bd2868288 (diff)
v2rw: Convert discussion board listings + change link structure a bit
A board-wide "tab"-like structure rather than breadcrumbs, has a more consistent feeling.
Diffstat (limited to 'lib/VNWeb')
-rw-r--r--lib/VNWeb/Discussions/Board.pm52
-rw-r--r--lib/VNWeb/Discussions/Index.pm10
-rw-r--r--lib/VNWeb/Discussions/Lib.pm32
-rw-r--r--lib/VNWeb/Discussions/Search.pm1
4 files changed, 84 insertions, 11 deletions
diff --git a/lib/VNWeb/Discussions/Board.pm b/lib/VNWeb/Discussions/Board.pm
new file mode 100644
index 00000000..80207ed7
--- /dev/null
+++ b/lib/VNWeb/Discussions/Board.pm
@@ -0,0 +1,52 @@
+package VNWeb::Discussions::Board;
+
+use VNWeb::Prelude;
+use VNWeb::Discussions::Lib;
+
+my $board_regex = join '|', map $_.($BOARD_TYPE{$_}{dbitem}?'(?:[1-9][0-9]{0,5})?':''), keys %BOARD_TYPE;
+
+TUWF::get qr{/t/(all|$board_regex)}, sub {
+ my($type, $id) = tuwf->capture(1) =~ /^([^0-9]+)([0-9]*)$/;
+
+ my $page = eval { tuwf->validate(get => p => { upage => 1 })->data } || 1;
+
+ my $obj = !$id ? undef :
+ $type eq 'v' ? tuwf->dbRowi('SELECT id, title, original, hidden AS entry_hidden, locked AS entry_locked FROM vn WHERE id =', \$id) :
+ $type eq 'p' ? tuwf->dbRowi('SELECT id, name, original, hidden AS entry_hidden, locked AS entry_locked FROM producers WHERE id =', \$id) :
+ $type eq 'u' ? tuwf->dbRowi('SELECT id,', sql_user(), 'FROM users u WHERE id =', \$id) : undef;
+ return tuwf->resNotFound if $id && !$obj->{id};
+
+ my $ititle = $obj && ($obj->{title} || $obj->{name} || user_displayname $obj);
+ my $title = $obj ? "Related discussions for $ititle" : $type eq 'all' ? 'All boards' : $BOARD_TYPE{$type}{txt};
+ my $createurl = '/t/'.($id ? $type.$id : $type eq 'db' ? 'db' : 'ge').'/new';
+
+ framework_ title => $title, type => $type, dbobj => $obj, tab => 'disc',
+ sub {
+ div_ class => 'mainbox', sub {
+ h1_ $title;
+ boardtypes_ $type;
+ boardsearch_ $type if !$id;
+ p_ class => 'center', sub {
+ a_ href => $createurl, 'Start a new thread';
+ } if auth->permBoard;
+ };
+
+ threadlist_
+ where => $type ne 'all' && sql('t.id IN(SELECT tid FROM threads_boards WHERE type =', \$type, $id ? ('AND iid =', \$id) : (), ')'),
+ boards => $type ne 'all' && sql('NOT (tb.type =', \$type, 'AND tb.iid =', \($id||0), ')'),
+ results => 50,
+ sort => $type eq 'an' ? 't.id DESC' : undef,
+ page => $page,
+ paginate => sub { "?p=$_" }
+ or div_ class => 'mainbox', sub {
+ h1_ 'An empty board';
+ p_ class => 'center', sub {
+ txt_ "Nobody's started a discussion on this board yet. Why not ";
+ a_ href => $createurl, 'create a new thread';
+ txt_ ' yourself?';
+ }
+ }
+ };
+};
+
+1;
diff --git a/lib/VNWeb/Discussions/Index.pm b/lib/VNWeb/Discussions/Index.pm
index d178c579..565cbc49 100644
--- a/lib/VNWeb/Discussions/Index.pm
+++ b/lib/VNWeb/Discussions/Index.pm
@@ -9,14 +9,8 @@ TUWF::get qr{/t}, sub {
form_ method => 'get', action => '/t/search', sub {
div_ class => 'mainbox', sub {
h1_ 'Discussion board index';
- fieldset_ class => 'search', sub {
- input_ type => 'text', name => 'bq', id => 'bq', class => 'text';
- input_ type => 'submit', class => 'submit', value => 'Search!';
- };
- p_ class => 'browseopts', sub {
- a_ href => '/t/all', 'All boards';
- a_ href => '/t/'.$_, $BOARD_TYPE{$_}{txt} for (keys %BOARD_TYPE);
- };
+ boardtypes_ 'index';
+ boardsearch_;
}
};
diff --git a/lib/VNWeb/Discussions/Lib.pm b/lib/VNWeb/Discussions/Lib.pm
index 63fb80d8..f2439f97 100644
--- a/lib/VNWeb/Discussions/Lib.pm
+++ b/lib/VNWeb/Discussions/Lib.pm
@@ -3,7 +3,7 @@ package VNWeb::Discussions::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/threadlist_/;
+our @EXPORT = qw/threadlist_ boardsearch_ boardtypes_/;
# Generate a thread list table, options:
@@ -12,6 +12,7 @@ our @EXPORT = qw/threadlist_/;
# results => Number of threads to display.
# page => Current page number.
# paginate => sub {} reference that generates a url for paginate_(); pagination is disabled when not set.
+# sort => SQL (default: tl.date DESC)
#
# Returns 1 if something was displayed, 0 if no threads matched the where clause.
sub threadlist_ {
@@ -36,8 +37,8 @@ sub threadlist_ {
JOIN users tfu ON tfu.id = tf.uid
JOIN users tlu ON tlu.id = tl.uid
WHERE }, $where, q{
- ORDER BY tl.date DESC
- });
+ ORDER BY}, $opt{sort}||'tl.date DESC'
+ );
return 0 if !@$lst;
enrich boards => id => tid => sub { sql q{
@@ -92,4 +93,29 @@ sub threadlist_ {
1;
}
+
+sub boardsearch_ {
+ my($type) = @_;
+ form_ action => '/t/search', sub {
+ fieldset_ class => 'search', sub {
+ input_ type => 'text', name => 'bq', id => 'bq', class => 'text';
+ input_ type => 'hidden', name => 'b', value => $type if $type && $type ne 'all';
+ input_ type => 'submit', class => 'submit', value => 'Search!';
+ }
+ }
+}
+
+
+sub boardtypes_ {
+ my($type) = @_;
+ p_ class => 'browseopts', sub {
+ a_ href => '/t/'.$_->[0], mkclass(optselected => $type && $type eq $_->[0]), $_->[1] for (
+ [ index => 'Index' ],
+ [ all => 'All boards' ],
+ map [ $_, $BOARD_TYPE{$_}{txt} ], keys %BOARD_TYPE
+ );
+ };
+}
+
+
1;
diff --git a/lib/VNWeb/Discussions/Search.pm b/lib/VNWeb/Discussions/Search.pm
index 6d21380a..511267b0 100644
--- a/lib/VNWeb/Discussions/Search.pm
+++ b/lib/VNWeb/Discussions/Search.pm
@@ -15,6 +15,7 @@ sub filters_ {
my %boards = map +($_,1), $filt->{b}->@*;
form_ method => 'get', action => tuwf->reqPath(), sub {
+ boardtypes_;
table_ style => 'margin: 0 auto', sub { tr_ sub {
td_ style => 'padding: 10px', sub {
p_ class => 'linkradio', sub {