diff options
author | Yorhel <git@yorhel.nl> | 2021-01-16 10:29:16 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-01-16 10:29:18 +0100 |
commit | cfad152cc6a7338de3b76439ccae6cdeb44cd839 (patch) | |
tree | 7016e3664aacad6fa1922fca0de84f7f86873e19 /lib/VNWeb/TT/Lib.pm | |
parent | 4406605928109f1800582acf886a2b77c46dcea0 (diff) |
TraitPage: Rewrite to use new AdvSearch system
Largely a copy-paste from TagPage.
Diffstat (limited to 'lib/VNWeb/TT/Lib.pm')
-rw-r--r-- | lib/VNWeb/TT/Lib.pm | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/VNWeb/TT/Lib.pm b/lib/VNWeb/TT/Lib.pm index cb8bf64d..bb8c1375 100644 --- a/lib/VNWeb/TT/Lib.pm +++ b/lib/VNWeb/TT/Lib.pm @@ -3,7 +3,7 @@ package VNWeb::TT::Lib; use VNWeb::Prelude; use Exporter 'import'; -our @EXPORT = qw/ tagscore_ enrich_group tree_ /; +our @EXPORT = qw/ tagscore_ enrich_group tree_ parents_ /; sub tagscore_ { my($s, $ign) = @_; @@ -67,5 +67,36 @@ sub tree_ { } +# Breadcrumbs-style listing of parent tags/traits +sub parents_ { + my($type, $t) = @_; + + my %t; + my $name = $type eq 'g' ? 'tag' : 'trait'; + push $t{$_->{child}}->@*, $_ for tuwf->dbAlli(' + WITH RECURSIVE p(id,child,name) AS ( + SELECT ', \$t->{id}, "::int, 0, NULL::text + UNION + SELECT t.id, p.id, t.name FROM p JOIN ${name}s_parents tp ON tp.${name} = p.id JOIN ${name}s t ON t.id = tp.parent + ) SELECT * FROM p WHERE child <> 0 ORDER BY name + ")->@*; + + my sub rec { + $t{$_[0]} ? map { my $e=$_; map [ @$_, $e ], __SUB__->($e->{id}) } $t{$_[0]}->@* : [] + } + + p_ sub { + join_ \&br_, sub { + a_ href => "/$type", $type eq 'g' ? 'Tags' : 'Traits'; + for (@$_) { + txt_ ' > '; + a_ href => "/$type$_->{id}", $_->{name}; + } + txt_ ' > '; + txt_ $t->{name}; + }, rec($t->{id}); + }; +} + 1; |