summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/Traits.pm80
-rw-r--r--lib/VNWeb/Tags/Index.pm70
-rw-r--r--lib/VNWeb/Tags/Lib.pm9
-rw-r--r--lib/VNWeb/Tags/List.pm3
4 files changed, 53 insertions, 109 deletions
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index ec7fc7c6..d3c717e1 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -9,7 +9,6 @@ use VNDB::Func;
TUWF::register(
qr{i([1-9]\d*)}, \&traitpage,
- qr{i}, \&traitindex,
qr{xml/traits\.xml}, \&traitxml,
);
@@ -130,85 +129,6 @@ sub traitpage {
}
-sub traitindex {
- my $self = shift;
-
- $self->htmlHeader(title => 'Trait index');
- div class => 'mainbox';
- a class => 'addnew', href => "/i/new", 'Create new trait' if $self->authCan('edit');
- h1 'Search traits';
- form action => '/i/list', 'accept-charset' => 'UTF-8', method => 'get';
- $self->htmlSearchBox('i', '');
- end;
- end;
-
- my $t = $self->dbTTTree(trait => 0, 2);
- childtags($self, 'Trait tree', 'i', {childs => $t}, 'order');
-
- table class => 'mainbox threelayout';
- Tr;
-
- # Recently added
- td;
- a class => 'right', href => '/i/list', 'Browse all traits';
- my $r = $self->dbTraitGet(sort => 'added', reverse => 1, results => 10);
- h1 'Recently added';
- ul;
- for (@$r) {
- li;
- txt fmtage $_->{added};
- txt ' ';
- b class => 'grayedout', $_->{groupname}.' / ' if $_->{group};
- a href => "/i$_->{id}", $_->{name};
- end;
- }
- end;
- end;
-
- # Popular
- td;
- h1 'Popular traits';
- ul;
- $r = $self->dbTraitGet(sort => 'items', reverse => 1, results => 10);
- for (@$r) {
- li;
- b class => 'grayedout', $_->{groupname}.' / ' if $_->{group};
- a href => "/i$_->{id}", $_->{name};
- txt " ($_->{c_items})";
- end;
- }
- end;
- end;
-
- # Moderation queue
- td;
- h1 'Awaiting moderation';
- $r = $self->dbTraitGet(state => 0, sort => 'added', reverse => 1, results => 10);
- ul;
- li 'Moderation queue empty! yay!' if !@$r;
- for (@$r) {
- li;
- txt fmtage $_->{added};
- txt ' ';
- b class => 'grayedout', $_->{groupname}.' / ' if $_->{group};
- a href => "/i$_->{id}", $_->{name};
- end;
- }
- li;
- br;
- a href => '/i/list?t=0;o=d;s=added', 'Moderation queue';
- txt ' - ';
- a href => '/i/list?t=1;o=d;s=added', 'Denied traits';
- end;
- end;
- end;
-
- end 'tr';
- end 'table';
- $self->htmlFooter;
-}
-
-
sub traitxml {
my $self = shift;
diff --git a/lib/VNWeb/Tags/Index.pm b/lib/VNWeb/Tags/Index.pm
index 6650705f..b883aae2 100644
--- a/lib/VNWeb/Tags/Index.pm
+++ b/lib/VNWeb/Tags/Index.pm
@@ -1,22 +1,28 @@
package VNWeb::Tags::Index;
use VNWeb::Prelude;
+use VNWeb::Tags::Lib 'enrich_group';
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');
+ my($type) = @_;
+ my $table = $type eq 'g' ? 'tag' : 'trait';
+ my $top = tuwf->dbAlli(
+ "SELECT id, name, c_items FROM ${table}s WHERE state = 1+1 AND NOT EXISTS(SELECT 1 FROM ${table}s_parents WHERE $table = id)
+ ORDER BY ", $type eq 'g' ? 'name' : '"order"'
+ );
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'
+ "SELECT tp.parent, t.id, t.name, t.c_items FROM ${table}s t JOIN ${table}s_parents tp ON tp.$table = t.id WHERE state = 1+1 AND tp.parent IN", $_, 'ORDER BY name'
}, $top;
- $top = [ sort { $b->{childs}->@* <=> $a->{childs}->@* } @$top ];
+ $top = [ sort { $b->{childs}->@* <=> $a->{childs}->@* } @$top ] if $type eq 'g';
my sub lnk_ {
- a_ href => "/g$_[0]{id}", $_[0]{name};
+ a_ href => "/$type$_[0]{id}", $_[0]{name};
b_ class => 'grayedout', " ($_[0]{c_items})" if $_[0]{c_items};
}
div_ class => 'mainbox', sub {
- h1_ 'Tag tree';
+ h1_ $type eq 'g' ? 'Tag tree' : 'Trait tree';
ul_ class => 'tagtree', sub {
li_ sub {
lnk_ $_;
@@ -25,11 +31,11 @@ sub tree_ {
li_ sub {
txt_ '> ';
lnk_ $_;
- } for grep $_, $sub->@[0..4];
+ } for grep $_, $sub->@[0 .. (@$sub > 6 ? 4 : 5)];
li_ sub {
my $num = @$sub-5;
txt_ '> ';
- a_ href => "/g$_->{id}", style => 'font-style: italic', sprintf '%d more tag%s', $num, $num == 1 ? '' : 's';
+ a_ href => "/$type$_->{id}", style => 'font-style: italic', sprintf '%d more %s%s', $num, $table, $num == 1 ? '' : 's';
} if @$sub > 6;
} if @$sub;
} for @$top;
@@ -41,30 +47,36 @@ sub tree_ {
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');
+ my($type) = @_;
+ my $lst = tuwf->dbAlli('SELECT id, name, ', sql_totime('added'), 'AS added FROM', $type eq 'g' ? 'tags' : 'traits', 'WHERE state = 1+1 ORDER BY added DESC LIMIT 10');
+ enrich_group $type, $lst;
p_ class => 'mainopts', sub {
- a_ href => '/g/list', 'Browse all tags';
+ a_ href => "/$type/list", 'Browse all '.($type eq 'g' ? 'tags' : 'traits');
};
h1_ 'Recently added';
ul_ sub {
li_ sub {
txt_ fmtage $_->{added};
txt_ ' ';
- a_ href => "/g$_->{id}", $_->{name};
+ b_ class => 'grayedout', "$_->{group} / " if $_->{group};
+ a_ href => "/$type$_->{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');
+ my($type) = @_;
+ my $lst = tuwf->dbAlli('SELECT id, name, c_items FROM', $type eq 'g' ? 'tags' : 'traits', 'WHERE state = 1+1 AND c_items > 0 AND applicable ORDER BY c_items DESC LIMIT 10');
+ enrich_group $type, $lst;
p_ class => 'mainopts', sub {
a_ href => '/g/links', 'Recently tagged';
- };
+ } if $type eq 'g';
h1_ 'Popular';
ul_ sub {
li_ sub {
- a_ href => "/g$_->{id}", $_->{name};
+ b_ class => 'grayedout', "$_->{group} / " if $_->{group};
+ a_ href => "/$type$_->{id}", $_->{name};
txt_ " ($_->{c_items})";
} for @$lst;
};
@@ -72,42 +84,46 @@ sub popular_ {
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');
+ my($type) = @_;
+ my $lst = tuwf->dbAlli('SELECT id, name, ', sql_totime('added'), 'AS added FROM', $type eq 'g' ? 'tags' : 'traits', 'WHERE state = 0 ORDER BY added DESC LIMIT 10');
+ enrich_group $type, $lst;
h1_ 'Awaiting moderation';
ul_ sub {
li_ 'The moderation queue is empty!' if !@$lst;
li_ sub {
txt_ fmtage $_->{added};
txt_ ' ';
- a_ href => "/g$_->{id}", $_->{name};
+ b_ class => 'grayedout', "$_->{group} / " if $_->{group};
+ a_ href => "/$type$_->{id}", $_->{name};
} for @$lst;
li_ sub {
br_;
- a_ href => '/g/list?t=0;o=d;s=added', 'Moderation queue';
+ a_ href => "/$type/list?t=0;o=d;s=added", 'Moderation queue';
txt_ ' - ';
- a_ href => '/g/list?t=1;o=d;s=added', 'Denied tags';
+ a_ href => "/$type/list?t=1;o=d;s=added", $type eq 'g' ? 'Denied tags' : 'Denied traits';
};
};
}
-TUWF::get qr{/g}, sub {
- framework_ title => 'Tag index', index => 1, sub {
+TUWF::get qr{/(?<type>[gi])}, sub {
+ my $type = tuwf->capture('type');
+ framework_ title => $type eq 'g' ? 'Tag index' : 'Trait index', index => 1, sub {
div_ class => 'mainbox', sub {
p_ class => 'mainopts', sub {
- a_ href => '/g/new', 'Create a new tag' if can_edit g => {};
+ a_ href => "/$type/new", 'Create a new'.($type eq 'g' ? 'tag' : 'trait') if can_edit $type => {};
};
- h1_ 'Search tags';
- form_ action => '/g/list', sub {
- searchbox_ g => '';
+ h1_ $type eq 'g' ? 'Search tags' : 'Search traits';
+ form_ action => "/$type/list", sub {
+ searchbox_ $type => '';
};
};
- tree_;
+ tree_ $type;
table_ class => 'mainbox threelayout', sub {
tr_ sub {
- td_ \&recent_;
- td_ \&popular_;
- td_ \&moderation_;
+ td_ sub { recent_ $type };
+ td_ sub { popular_ $type };
+ td_ sub { moderation_ $type };
};
};
diff --git a/lib/VNWeb/Tags/Lib.pm b/lib/VNWeb/Tags/Lib.pm
index 61220186..e9935629 100644
--- a/lib/VNWeb/Tags/Lib.pm
+++ b/lib/VNWeb/Tags/Lib.pm
@@ -3,7 +3,7 @@ package VNWeb::Tags::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/ tagscore_ /;
+our @EXPORT = qw/ tagscore_ enrich_group /;
sub tagscore_ {
my($s, $ign) = @_;
@@ -13,4 +13,11 @@ sub tagscore_ {
};
}
+
+# Add a 'group' name for traits
+sub enrich_group {
+ my($type, @lst) = @_;
+ enrich_merge id => 'SELECT t.id, g.name AS "group" FROM traits t JOIN traits g ON g.id = t."group" WHERE t.id IN', @lst if $type eq 'i';
+}
+
1;
diff --git a/lib/VNWeb/Tags/List.pm b/lib/VNWeb/Tags/List.pm
index 77d1c6ec..54da1f86 100644
--- a/lib/VNWeb/Tags/List.pm
+++ b/lib/VNWeb/Tags/List.pm
@@ -3,6 +3,7 @@
package VNWeb::Tags::List;
use VNWeb::Prelude;
+use VNWeb::Tags::Lib 'enrich_group';
sub listing_ {
@@ -70,7 +71,7 @@ TUWF::get qr{/(?<type>[gi])/list}, sub {
ORDER BY', {qw|added id name name items c_items|}->{$opt->{s}}, {qw|a ASC d DESC|}->{$opt->{o}}, ', id'
);
- enrich_merge id => 'SELECT t.id, g.name AS "group" FROM traits t JOIN traits g ON g.id = t."group" WHERE t.id IN', $list if $type eq 'i';
+ enrich_group $type, $list;
framework_ title => "Browse $table", index => 1, sub {
div_ class => 'mainbox', sub {