summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/Tags.pm79
-rw-r--r--lib/VNWeb/Tags/Index.pm117
2 files changed, 117 insertions, 79 deletions
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index d80059c4..bced924f 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -11,8 +11,6 @@ use VNDB::Types;
TUWF::register(
qr{g([1-9]\d*)}, \&tagpage,
- qr{u([1-9]\d*)/tags}, \&usertags,
- qr{g}, \&tagindex,
qr{g/debug}, \&fulltree,
qr{xml/tags\.xml}, \&tagxml,
);
@@ -142,83 +140,6 @@ sub tagpage {
}
-sub tagindex {
- my $self = shift;
-
- $self->htmlHeader(title => 'Tag index');
- div class => 'mainbox';
- a class => 'addnew', href => "/g/new", 'Create new tag' if $self->authCan('tag');
- h1 'Search tags';
- form action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get';
- $self->htmlSearchBox('g', '');
- end;
- end;
-
- my $t = $self->dbTTTree(tag => 0, 2);
- childtags($self, 'Tag tree', 'g', {childs => $t});
-
- table class => 'mainbox threelayout';
- Tr;
-
- # Recently added
- td;
- a class => 'right', href => '/g/list', 'Browse all tags';
- my $r = $self->dbTagGet(sort => 'added', reverse => 1, results => 10, state => 2);
- h1 'Recently added';
- ul;
- for (@$r) {
- li;
- txt fmtage $_->{added};
- txt ' ';
- a href => "/g$_->{id}", $_->{name};
- end;
- }
- end;
- end;
-
- # Popular
- td;
- a class => 'addnew', href => "/g/links", 'Recently tagged';
- $r = $self->dbTagGet(sort => 'items', reverse => 1, searchable => 1, applicable => 1, results => 10);
- h1 'Popular tags';
- ul;
- for (@$r) {
- li;
- a href => "/g$_->{id}", $_->{name};
- txt " ($_->{c_items})";
- end;
- }
- end;
- end;
-
- # Moderation queue
- td;
- h1 'Awaiting moderation';
- $r = $self->dbTagGet(state => 0, sort => 'added', reverse => 1, results => 10);
- ul;
- li 'Moderation queue empty! yay!' if !@$r;
- for (@$r) {
- li;
- txt fmtage $_->{added};
- txt ' ';
- a href => "/g$_->{id}", $_->{name};
- end;
- }
- li;
- br;
- a href => '/g/list?t=0;o=d;s=added', 'Moderation queue';
- txt ' - ';
- a href => '/g/list?t=1;o=d;s=added', 'Denied tags';
- end;
- end;
- end;
-
- end 'tr';
- end 'table';
- $self->htmlFooter;
-}
-
-
# non-translatable debug page
sub fulltree {
my $self = shift;
diff --git a/lib/VNWeb/Tags/Index.pm b/lib/VNWeb/Tags/Index.pm
new file mode 100644
index 00000000..6650705f
--- /dev/null
+++ b/lib/VNWeb/Tags/Index.pm
@@ -0,0 +1,117 @@
+package VNWeb::Tags::Index;
+
+use VNWeb::Prelude;
+
+
+sub tree_ {
+ my $top = tuwf->dbAlli('SELECT id, name, c_items FROM tags WHERE state = 1+1 AND NOT EXISTS(SELECT 1 FROM tags_parents WHERE tag = id) ORDER BY name');
+
+ enrich childs => id => parent => sub { sql
+ 'SELECT tp.parent, t.id, t.name, t.c_items FROM tags t JOIN tags_parents tp ON tp.tag = t.id WHERE state = 1+1 AND tp.parent IN', $_, 'ORDER BY name'
+ }, $top;
+ $top = [ sort { $b->{childs}->@* <=> $a->{childs}->@* } @$top ];
+
+ my sub lnk_ {
+ a_ href => "/g$_[0]{id}", $_[0]{name};
+ b_ class => 'grayedout', " ($_[0]{c_items})" if $_[0]{c_items};
+ }
+ div_ class => 'mainbox', sub {
+ h1_ 'Tag tree';
+ ul_ class => 'tagtree', sub {
+ li_ sub {
+ lnk_ $_;
+ my $sub = $_->{childs};
+ ul_ sub {
+ li_ sub {
+ txt_ '> ';
+ lnk_ $_;
+ } for grep $_, $sub->@[0..4];
+ li_ sub {
+ my $num = @$sub-5;
+ txt_ '> ';
+ a_ href => "/g$_->{id}", style => 'font-style: italic', sprintf '%d more tag%s', $num, $num == 1 ? '' : 's';
+ } if @$sub > 6;
+ } if @$sub;
+ } for @$top;
+ };
+ clearfloat_;
+ br_;
+ };
+}
+
+
+sub recent_ {
+ my $lst = tuwf->dbAlli('SELECT id, name, ', sql_totime('added'), 'AS added FROM tags WHERE state = 1+1 ORDER BY added DESC LIMIT 10');
+ p_ class => 'mainopts', sub {
+ a_ href => '/g/list', 'Browse all tags';
+ };
+ h1_ 'Recently added';
+ ul_ sub {
+ li_ sub {
+ txt_ fmtage $_->{added};
+ txt_ ' ';
+ a_ href => "/g$_->{id}", $_->{name};
+ } for @$lst;
+ };
+}
+
+
+sub popular_ {
+ my $lst = tuwf->dbAlli('SELECT id, name, c_items FROM tags WHERE state = 1+1 AND c_items > 0 AND applicable ORDER BY c_items DESC LIMIT 10');
+ p_ class => 'mainopts', sub {
+ a_ href => '/g/links', 'Recently tagged';
+ };
+ h1_ 'Popular';
+ ul_ sub {
+ li_ sub {
+ a_ href => "/g$_->{id}", $_->{name};
+ txt_ " ($_->{c_items})";
+ } for @$lst;
+ };
+}
+
+
+sub moderation_ {
+ my $lst = tuwf->dbAlli('SELECT id, name, ', sql_totime('added'), 'AS added FROM tags WHERE state = 0 ORDER BY added DESC LIMIT 10');
+ h1_ 'Awaiting moderation';
+ ul_ sub {
+ li_ 'The moderation queue is empty!' if !@$lst;
+ li_ sub {
+ txt_ fmtage $_->{added};
+ txt_ ' ';
+ a_ href => "/g$_->{id}", $_->{name};
+ } for @$lst;
+ li_ sub {
+ br_;
+ a_ href => '/g/list?t=0;o=d;s=added', 'Moderation queue';
+ txt_ ' - ';
+ a_ href => '/g/list?t=1;o=d;s=added', 'Denied tags';
+ };
+ };
+}
+
+
+TUWF::get qr{/g}, sub {
+ framework_ title => 'Tag index', index => 1, sub {
+ div_ class => 'mainbox', sub {
+ p_ class => 'mainopts', sub {
+ a_ href => '/g/new', 'Create a new tag' if can_edit g => {};
+ };
+ h1_ 'Search tags';
+ form_ action => '/g/list', sub {
+ searchbox_ g => '';
+ };
+ };
+ tree_;
+ table_ class => 'mainbox threelayout', sub {
+ tr_ sub {
+ td_ \&recent_;
+ td_ \&popular_;
+ td_ \&moderation_;
+ };
+ };
+
+ };
+};
+
+1;