Skip to content

Commit

Permalink
fix ui, add dt_updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaonan song committed Jan 23, 2013
1 parent d3e2810 commit 1eb4c9b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -32,6 +32,7 @@ requires 'DBIx::Class::Schema::Loader';
requires 'Domain::PublicSuffix';
requires 'Image::OCR::Tesseract';
requires 'Business::ISBN';
requires 'Date::Calc';

test_requires 'Test::More' => '0.88';
catalyst;
Expand Down
35 changes: 35 additions & 0 deletions lib/Ptt/Controller/Search.pm
Expand Up @@ -4,9 +4,11 @@ use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

use utf8;
use Data::Page;
use Page;
use Debug;
use Date::Calc;

sub search : Chained("/") : PathPart("search") : Args(0) {
my ( $self, $c ) = @_;
Expand All @@ -29,13 +31,46 @@ sub search : Chained("/") : PathPart("search") : Args(0) {
my $total_results = $data->{response}->{numFound};
my $results = $data->{response}->{docs};

my @now = localtime;
my ( $y2, $m2, $d2, $hh2, $mm2, $ss2 ) = ($now[5]+1900, $now[4]+1, $now[3], $now[2], $now[1], $now[0]);

my %site_seen;
if ( $results ) {
foreach my $item ( @$results ) {
if ( $item->{price} ) {
$item->{price} = sprintf("%.2f", $item->{price});
}
$site_seen{$item->{site_id}}++;
if ( my $dt_created = $item->{dt_created} ) {
my ( $y1, $m1, $d1, $hh1, $mm1, $ss1 ) = ($dt_created =~ m{(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z});
$hh1 =~ s{^0+}{};
my @deltas = Date::Calc::N_Delta_YMDHMS( $y1, $m1, $d1, $hh1, $mm1, $ss1, $y2, $m2, $d2, $hh2, $mm2, $ss2 );
my $i = 0;
foreach ( @deltas ) {
if ( $_ ) {
if ( $i == 0 ) {
$item->{dt_delta} = $_ . "年前";
last;
} elsif ( $i == 1 ) {
$item->{dt_delta} = $_ . "月前";
last;
} elsif ( $i == 2 ) {
$item->{dt_delta} = $_ . "天前";
last;
} elsif ( $i == 3 ) {
$item->{dt_delta} = $_ . "小时前";
last;
} elsif ( $i == 4 ) {
$item->{dt_delta} = $_ . "分钟前";
last;
} elsif ( $i == 5 ) {
$item->{dt_delta} = $_ . "秒前";
last;
}
}
$i++;
}
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions root/tmpl/search.tt
Expand Up @@ -33,7 +33,7 @@
<a href=[% c.req.uri_with({ sort => 'price' }) %]>价格从低到高</a>
[% END %]
</td>
<td>商家</td><td></td>
<td>商家</td><td>更新</td><td></td>
</tr>
[% index = 0 %]
[% FOREACH row IN results; %]
Expand All @@ -53,11 +53,16 @@
</td></tr>
</table>
</td>
<td width=15%>
<td width=7%>
<table>
<tr><td>[% site_seen.$site_id %]</td></tr>
</table>
</td>
<td width=8%>
<table>
<tr><td>[% row.dt_delta %]</td></tr>
</table>
</td>
<td width=15%>
<p class="btn pull-right">
<a href="[% row.url %]" target=_blank>去购物</a>
Expand Down

0 comments on commit 1eb4c9b

Please sign in to comment.