summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-02-14 10:58:05 +0100
committerYorhel <git@yorhel.nl>2011-02-14 10:58:05 +0100
commit23c6f7c1dc584fab42d87f060a9faa033e04c8e2 (patch)
tree355c31e13d4b67afe9cce6ef8b2f7a07689fe172 /lib
parentf4b31e6d934bc93d678804ae7e4039031ff87760 (diff)
chardb: Added trait index and search
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Traits.pm8
-rw-r--r--lib/VNDB/Handler/Tags.pm2
-rw-r--r--lib/VNDB/Handler/Traits.pm146
-rw-r--r--lib/VNDB/Util/CommonHTML.pm1
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm1
5 files changed, 153 insertions, 5 deletions
diff --git a/lib/VNDB/DB/Traits.pm b/lib/VNDB/DB/Traits.pm
index 8b9849ed..d30477c6 100644
--- a/lib/VNDB/DB/Traits.pm
+++ b/lib/VNDB/DB/Traits.pm
@@ -25,11 +25,19 @@ sub dbTraitGet {
@_,
);
+ $o{search} =~ s/%//g if $o{search};
+
my %where = (
$o{id} ? ('t.id = ?' => $o{id}) : (),
$o{noid} ? ('t.id <> ?' => $o{noid}) : (),
$o{name} ? (
't.id = (SELECT id FROM traits LEFT JOIN traits_aliases ON id = trait WHERE lower(name) = ? OR lower(alias) = ? LIMIT 1)' => [ lc $o{name}, lc $o{name} ]) : (),
+ defined $o{state} && $o{state} != -1 ? (
+ 't.state = ?' => $o{state} ) : (),
+ !defined $o{state} && !$o{id} && !$o{name} ? (
+ 't.state = 2' => 1 ) : (),
+ $o{search} ? (
+ 't.id IN (SELECT id FROM traits LEFT JOIN traits_aliases ON id = trait WHERE name ILIKE ? OR alias ILIKE ?)' => [ "%$o{search}%", "%$o{search}%" ] ) : (),
);
my @select = (
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 6e48cc26..6ddac04d 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -625,7 +625,7 @@ sub tagindex {
end;
my $t = $self->dbTagTree(0, 2);
- childtags($self, mt('_tagp_tree'), 'g', {childs => $t});
+ childtags($self, mt('_tagidx_tree'), 'g', {childs => $t});
table class => 'mainbox threelayout';
Tr;
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index d505b6c7..7f79aa27 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -8,10 +8,12 @@ use VNDB::Func;
TUWF::register(
- qr{i([1-9]\d*)}, \&traitpage,
- qr{i([1-9]\d*)/(edit)}, \&traitedit,
- qr{i([1-9]\d*)/(add)}, \&traitedit,
- qr{i/new}, \&traitedit,
+ qr{i([1-9]\d*)}, \&traitpage,
+ qr{i([1-9]\d*)/(edit)}, \&traitedit,
+ qr{i([1-9]\d*)/(add)}, \&traitedit,
+ qr{i/new}, \&traitedit,
+ qr{i/list}, \&traitlist,
+ qr{i}, \&traitindex,
);
@@ -175,5 +177,141 @@ sub traitedit {
}
+sub traitlist {
+ my $self = shift;
+
+ my $f = $self->formValidate(
+ { get => 's', required => 0, default => 'name', enum => ['added', 'name'] },
+ { get => 'o', required => 0, default => 'a', enum => ['a', 'd'] },
+ { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 't', required => 0, default => -1, enum => [ -1..2 ] },
+ { get => 'q', required => 0, default => '' },
+ );
+ return $self->resNotFound if $f->{_err};
+
+ my($t, $np) = $self->dbTraitGet(
+ sort => $f->{s}, reverse => $f->{o} eq 'd',
+ page => $f->{p},
+ results => 50,
+ state => $f->{t},
+ search => $f->{q}
+ );
+
+ $self->htmlHeader(title => mt '_traitb_title');
+ div class => 'mainbox';
+ h1 mt '_traitb_title';
+ form action => '/i/list', 'accept-charset' => 'UTF-8', method => 'get';
+ input type => 'hidden', name => 't', value => $f->{t};
+ $self->htmlSearchBox('i', $f->{q});
+ end;
+ p class => 'browseopts';
+ a href => "/i/list?q=$f->{q};t=-1", $f->{t} == -1 ? (class => 'optselected') : (), mt '_traitb_state-1';
+ a href => "/i/list?q=$f->{q};t=0", $f->{t} == 0 ? (class => 'optselected') : (), mt '_traitb_state0';
+ a href => "/i/list?q=$f->{q};t=1", $f->{t} == 1 ? (class => 'optselected') : (), mt '_traitb_state1';
+ a href => "/i/list?q=$f->{q};t=2", $f->{t} == 2 ? (class => 'optselected') : (), mt '_traitb_state2';
+ end;
+ if(!@$t) {
+ p mt '_traitb_noresults';
+ }
+ end 'div';
+ if(@$t) {
+ $self->htmlBrowse(
+ class => 'taglist',
+ options => $f,
+ nextpage => $np,
+ items => $t,
+ pageurl => "/i/list?t=$f->{t};q=$f->{q};s=$f->{s};o=$f->{o}",
+ sorturl => "/i/list?t=$f->{t};q=$f->{q}",
+ header => [
+ [ mt('_traitb_col_added'), 'added' ],
+ [ mt('_traitb_col_name'), 'name' ],
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ td class => 'tc1', $self->{l10n}->age($l->{added});
+ td class => 'tc3';
+ a href => "/i$l->{id}", $l->{name};
+ if($f->{t} == -1) {
+ b class => 'grayedout', ' '.mt '_traitb_note_awaiting' if $l->{state} == 0;
+ b class => 'grayedout', ' '.mt '_traitb_note_del' if $l->{state} == 1;
+ }
+ end;
+ end 'tr';
+ }
+ );
+ }
+ $self->htmlFooter;
+}
+
+
+sub traitindex {
+ my $self = shift;
+
+ $self->htmlHeader(title => mt '_traiti_title');
+ div class => 'mainbox';
+ a class => 'addnew', href => "/i/new", mt '_traiti_create' if $self->authCan('charedit');
+ h1 mt '_traiti_search';
+ form action => '/i/list', 'accept-charset' => 'UTF-8', method => 'get';
+ $self->htmlSearchBox('i', '');
+ end;
+ end;
+
+ my $t = $self->dbTraitTree(0, 2);
+ childtags($self, mt('_traiti_tree'), 'i', {childs => $t});
+
+ table class => 'mainbox threelayout';
+ Tr;
+
+ # Recently added
+ td;
+ a class => 'right', href => '/i/list', mt '_traiti_browseall';
+ my $r = $self->dbTraitGet(sort => 'added', reverse => 1, results => 10);
+ h1 mt '_traiti_recent';
+ ul;
+ for (@$r) {
+ li;
+ txt $self->{l10n}->age($_->{added});
+ txt ' ';
+ a href => "/i$_->{id}", $_->{name};
+ end;
+ }
+ end;
+ end;
+
+ # Popular
+ td;
+ h1 mt '_traiti_popular';
+ p 'TODO';
+ end;
+
+ # Moderation queue
+ td;
+ h1 mt '_traiti_queue';
+ $r = $self->dbTraitGet(state => 0, sort => 'added', reverse => 1, results => 10);
+ ul;
+ li mt '_traiti_queue_empty' if !@$r;
+ for (@$r) {
+ li;
+ txt $self->{l10n}->age($_->{added});
+ txt ' ';
+ a href => "/i$_->{id}", $_->{name};
+ end;
+ }
+ li;
+ br;
+ a href => '/i/list?t=0;o=d;s=added', mt '_traiti_queue_link';
+ txt ' - ';
+ a href => '/i/list?t=1;o=d;s=added', mt '_traiti_denied';
+ end;
+ end;
+ end;
+
+ end 'tr';
+ end 'table';
+ $self->htmlFooter;
+}
+
+
1;
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index ce086e55..ba03aeac 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -405,6 +405,7 @@ sub htmlSearchBox {
a href => '/r', $sel eq 'r' ? (class => 'sel') : (), mt '_searchbox_releases';
a href => '/p/all', $sel eq 'p' ? (class => 'sel') : (), mt '_searchbox_producers';
a href => '/g', $sel eq 'g' ? (class => 'sel') : (), mt '_searchbox_tags';
+ a href => '/i', $sel eq 'i' ? (class => 'sel') : (), mt '_searchbox_traits';
a href => '/u/all', $sel eq 'u' ? (class => 'sel') : (), mt '_searchbox_users';
end;
input type => 'text', name => 'q', id => 'q', class => 'text', value => $v;
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 7c03b6a3..ada9e17b 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -66,6 +66,7 @@ sub _menu {
a href => '/r', mt '_menu_releases'; br;
a href => '/p/all', mt '_menu_producers'; br;
a href => '/g', mt '_menu_tags'; br;
+ a href => '/i', mt '_menu_traits'; br;
a href => '/u/all', mt '_menu_users'; br;
a href => '/hist', mt '_menu_recent_changes'; br;
a href => '/t', mt '_menu_discussion_board'; br;