diff options
author | Yorhel <git@yorhel.nl> | 2011-04-29 12:11:28 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-04-29 12:11:28 +0200 |
commit | 67afab5bfa32662f53699eb2fe37a9adec86a1ab (patch) | |
tree | f683ad9819a7249aed7b715cb22b6c79eb18b39c /lib | |
parent | d1937fbfbc4996a524fe1649c081d9a486a34ab7 (diff) |
affiliates: +data column, hide hidden links, better browser, Multi fixes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Multi/Core.pm | 2 | ||||
-rw-r--r-- | lib/Multi/Maintenance.pm | 1 | ||||
-rw-r--r-- | lib/VNDB/DB/Affiliates.pm | 23 | ||||
-rw-r--r-- | lib/VNDB/Handler/Affiliates.pm | 41 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 2 |
5 files changed, 54 insertions, 15 deletions
diff --git a/lib/Multi/Core.pm b/lib/Multi/Core.pm index 9eaa6269..3c9d8bae 100644 --- a/lib/Multi/Core.pm +++ b/lib/Multi/Core.pm @@ -98,7 +98,7 @@ sub log_msg { # msg sub log { # level, msg (my $p = eval { $_[SENDER][2]{$_[CALLER_STATE]}[0] } || '') =~ s/^Multi:://; log_msg sprintf '%s::%s: %s', $p, $_[CALLER_STATE], - $_[ARG1] ? sprintf($_[ARG0], @_[ARG1..$#_]) : $_[ARG0]; + $#_>ARG0 ? sprintf($_[ARG0], @_[ARG1..$#_]) : $_[ARG0]; } diff --git a/lib/Multi/Maintenance.pm b/lib/Multi/Maintenance.pm index fb0c336f..33154f9b 100644 --- a/lib/Multi/Maintenance.pm +++ b/lib/Multi/Maintenance.pm @@ -46,6 +46,7 @@ sub _start { sub shutdown { $_[KERNEL]->delay('daily'); $_[KERNEL]->delay('monthly'); + $_[KERNEL]->delay('vnsearch_check'); $_[KERNEL]->alias_remove('maintenance'); } diff --git a/lib/VNDB/DB/Affiliates.pm b/lib/VNDB/DB/Affiliates.pm index 2aa891ce..51320b47 100644 --- a/lib/VNDB/DB/Affiliates.pm +++ b/lib/VNDB/DB/Affiliates.pm @@ -9,23 +9,38 @@ use Exporter 'import'; our @EXPORT = qw|dbAffiliateGet dbAffiliateEdit dbAffiliateDel dbAffiliateAdd|; -# options: id rids affiliate hide_hidden +# options: id rids affiliate hidden sort reverse # what: release sub dbAffiliateGet { my($self, %o) = @_; + $o{sort} ||= 'id'; + $o{reverse} //= 0; my %where = ( $o{id} ? ('id = ?' => $o{id}) : (), $o{rids} ? ('rid IN(!l)' => [$o{rids}]) : (), defined($o{affiliate}) ? ('affiliate = ?' => $o{affiliate}) : (), - $o{hide_hidden} ? ('NOT hidden' => 1) : (), + defined($o{hidden}) ? ('!s af.hidden' => $o{hidden} ? '' : 'NOT') : (), ); my $join = $o{what} ? 'JOIN releases r ON r.id = af.rid JOIN releases_rev rr ON rr.id = r.latest' : ''; my $select = $o{what} ? ', rr.title' : ''; - return $self->dbAll("SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version, extract('epoch' from af.lastfetch) as lastfetch, af.price$select - FROM affiliate_links af $join !W", \%where); + my $order = sprintf { + id => 'af.id %s', + rel => 'rr.title %s', + prio => 'af.priority %s', + url => 'af.url %s', + lastfetch => 'af.lastfetch %s', + }->{$o{sort}}, $o{reverse} ? 'DESC' : 'ASC'; + + return $self->dbAll(qq| + SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version, + extract('epoch' from af.lastfetch) as lastfetch, af.price$select + FROM affiliate_links af + $join + !W + ORDER BY !s|, \%where, $order); } diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm index 36435ade..e5e05d0f 100644 --- a/lib/VNDB/Handler/Affiliates.pm +++ b/lib/VNDB/Handler/Affiliates.pm @@ -20,7 +20,10 @@ sub list { return $self->htmlDenied if !$self->authCan('affiliate'); my $f = $self->formValidate( - { get => 'a', required => 0, enum => [ 0..$#{$self->{affiliates}} ] } + { get => 'a', required => 0, enum => [ 0..$#{$self->{affiliates}} ] }, + { get => 'h', required => 0, default => 0, enum => [ -1..1 ] }, + { get => 'o', required => 0, default => 'a', enum => ['a', 'd'] }, + { get => 's', required => 0, default => 'rel', enum => [qw|rel prio url lastfetch|] }, ); return $self->resNotFound if $f->{_err}; @@ -29,18 +32,37 @@ sub list { h1 'Affiliate administration interface'; p class => 'browseopts'; a defined($f->{a}) && $f->{a} == $_ ? (class => 'optselected') : (), href => "/affiliates?a=$_", $self->{affiliates}[$_]{name} - for (0..$#{$self->{affiliates}}); + for (grep $self->{affiliates}[$_], 0..$#{$self->{affiliates}}); end; + if(defined $f->{a}) { + p class => 'browseopts'; + a $f->{h} == -1 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=-1",'all'; + a $f->{h} == 1 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=1", 'hidden'; + a $f->{h} == 0 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=0", 'non-hidden'; + end; + } end; if(defined $f->{a}) { - my $list = $self->dbAffiliateGet(affiliate => $f->{a}, what => 'release'); + my $list = $self->dbAffiliateGet( + affiliate => $f->{a}, hidden => $f->{h}==-1?undef:$f->{h}, + what => 'release', + sort => $f->{s}, reverse => $f->{o} eq 'd' + ); $self->htmlBrowse( items => $list, nextpage => 0, - options => {p=>0}, + options => {p=>0, %$f}, pageurl => '', - header => [ ['Release'], ['Version'], ['Hid'], ['Prio'], ['URL'], ['Price'], [''] ], + sorturl => "/affiliates?a=$f->{a}", + header => [ + ['Release', 'rel'], + ['Version'], + ['Hid'], + ['Prio', 'prio'], + ['Price / Lastfetch', 'lastfetch'], + ['', 'url' ] + ], row => sub { my($s, $n, $l) = @_; Tr $n % 2 ? (class => 'odd') : (); @@ -48,9 +70,10 @@ sub list { td class => 'tc2', $l->{version} || '<default>'; td class => 'tc3', $l->{hidden} ? 'YES' : 'no'; td class => 'tc4', $l->{priority}; - td class => 'tc5'; a href => $l->{url}, $l->{url}; end; - td class => 'tc6', sprintf '%s / %s', $l->{price}, $l->{lastfetch} ? $self->{l10n}->age($l->{lastfetch}) : '-'; - td class => 'tc7'; + td class => 'tc5', sprintf '%s / %s', $l->{price}, $l->{lastfetch} ? $self->{l10n}->age($l->{lastfetch}) : '-'; + td class => 'tc6'; + a href => $l->{url}, 'link'; + txt ' | '; a href => "/affiliates/edit/$l->{id}", 'edit'; txt ' | '; a href => "/affiliates/del/$l->{id}?formcode=".$self->authGetCode("/affiliates/del/$l->{id}"), 'del'; @@ -111,7 +134,7 @@ sub edit { [ input => short => 'priority', name => 'Priority', width => 50 ], [ check => short => 'hidden', name => 'Hidden' ], [ select => short => 'affiliate', name => 'Affiliate', options => [ map - [ $_, $self->{affiliates}[$_]{name} ], 0..$#{$self->{affiliates}} ] ], + [ $_, $self->{affiliates}[$_]{name} ], grep $self->{affiliates}[$_], 0..$#{$self->{affiliates}} ] ], [ input => short => 'url', name => 'URL', width => 400 ], [ input => short => 'version', name => 'Version', width => 400 ], ]); diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 0fe71297..cd012aa2 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -409,7 +409,7 @@ sub _affiliate_links { my($self, $r) = @_; return if !keys @$r; my %r = map +($_->{id}, $_), @$r; - my $links = $self->dbAffiliateGet(rids => [ keys %r ]); + my $links = $self->dbAffiliateGet(rids => [ keys %r ], hidden => 0); return if !@$links; $links = [ sort { $b->{priority}||$self->{affiliates}[$b->{affiliate}]{default_prio} <=> $a->{priority}||$self->{affiliates}[$a->{affiliate}]{default_prio} } @$links ]; |