Permalink
Browse files

pagenation

  • Loading branch information...
1 parent f9b6736 commit 56109a8d20a65afb0de9d55ba6c296b9035edce7 @nobuo-danjou nobuo-danjou committed Aug 3, 2009
@@ -5,6 +5,7 @@ use warnings;
use utf8;
use parent 'GourmetSpot::ControllerBase::Resource';
use DateTime;
+use Data::Page::Navigation;
=head1 NAME
@@ -21,6 +22,7 @@ Catalyst Controller.
__PACKAGE__->config(
{
model => 'DBIC::Review',
+ rows => 40,
like_field => ['budget', 'comment'],
form => {
budget => [
@@ -62,8 +64,6 @@ sub setup_item_params :Private {
my $now = DateTime->now;
$c->stash->{search_params}->{created_by} = $c->user->id;
- $c->stash->{item_params}->{modified_at} = $now;
- $c->stash->{item_params}->{created_at} = $now;
$c->stash->{item_params}->{created_by} = $c->user->id;
}
@@ -74,52 +74,6 @@ sub setup_item :Private {
$self->next::method($c, $id);
}
-#sub create_item :Private {
-# my ( $self, $c ) = @_;
-#
-# $self->next::method($c);
-# $c->forward('update_tag');
-#}
-#
-#sub update_item :Private {
-# my ( $self, $c ) = @_;
-#
-# $self->next::method($c);
-# $c->forward('update_tag');
-#}
-#
-#sub update_tag :Private {
-# my ( $self, $c ) = @_;
-# my @values = grep {length($_)} split(/\s/, $c->stash->{outer_params}->{tags}->{value});
-# my @tags = $c->stash->{item}->tags;
-# for my $tag ($c->stash->{item}->tags) {
-# if (grep {$_ eq $tag->value } @values) {
-# @values = grep {$_ ne $tag->value} @values;
-# } else {
-# $tag->map_tag_review({review_id => $c->stash->{item}->id})->delete;
-# }
-# }
-# for my $value (@values) {
-# my $tag = $c->model('DBIC::Tag')->find_or_create(
-# {
-# value => $value,
-# created_by => $c->stash->{item}->created_by,
-# created_at => $c->stash->{item}->created_at,
-# },
-# {
-# key => 'value',
-# }
-# );
-# $c->model('DBIC::TagReview')->find_or_create(
-# {
-# tag_id => $tag->id,
-# review_id => $c->stash->{item}->id,
-# restrant_id => $c->stash->{item}->restrant_id,
-# }
-# );
-# }
-#}
-
=head2 index
=cut
@@ -6,7 +6,7 @@ use parent 'GourmetSpot::ControllerBase::Resource';
__PACKAGE__->config(
{
model => 'DBIC::Tag',
- rows => 0,
+ rows => 'all',
}
);
@@ -119,7 +119,7 @@ sub index :Chained('noitem_load') :PathPart('') :Args(0) {
$c->stash(
list => [ $rs->all ],
- pager => $rs->pager,
+ pager => $c->stash->{search_attr}->{rows} ? $rs->pager : undef,
);
$c->forward($c->view);
$c->fillform;
@@ -132,11 +132,11 @@ sub setup_search_attr :Private {
$order .= " desc" if $c->req->param('_desc');
}
my $attr = {
- order_by => $order || 'id desc',
+ order_by => $order || $self->{order} || 'id desc',
rows => $c->req->param('_rows') ||$self->{rows},
page => $c->req->param('_page') || 1,
};
- if ($c->req->param('_rows') && $c->req->param('_rows') eq 'all') {
+ if ($attr->{rows} eq 'all') {
delete $attr->{rows};
delete $attr->{page};
}
@@ -5,62 +5,63 @@ use warnings;
use base 'DBIx::Class';
-__PACKAGE__->load_components("Core");
+__PACKAGE__->load_components(qw(InflateColumn::DateTime TimeStamp Core));
__PACKAGE__->table("review");
__PACKAGE__->add_columns(
- "id",
- { data_type => "INT", default_value => undef, is_nullable => 0, size => 11 },
- "restrant_id",
- { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
- "budget",
- { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
- "comment",
- {
- data_type => "TEXT",
- default_value => undef,
- is_nullable => 1,
- size => 65535,
- },
- "created_by",
- { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
- "created_at",
- {
- data_type => "DATETIME",
- default_value => undef,
- is_nullable => 1,
- size => 19,
- },
- "modified_at",
- {
- data_type => "DATETIME",
- default_value => undef,
- is_nullable => 1,
- size => 19,
- },
-);
-__PACKAGE__->set_primary_key("id");
-
-
-# Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-11 10:30:58
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9lI25MVDd6MRDkhBkfrr0A
-
-__PACKAGE__->load_components(qw(InflateColumn::DateTime));
-
-__PACKAGE__->add_columns(
- created_at => {
- data_type => 'datetime',
+ "id" => {
+ data_type => "INT",
+ default_value => undef,
+ is_nullable => 0,
+ size => 11
+ },
+ "restrant_id" => {
+ data_type => "INT",
+ default_value => 0,
+ is_nullable => 0,
+ size => 11
+ },
+ "budget" => {
+ data_type => "INT",
+ default_value => 0,
+ is_nullable => 0,
+ size => 11
+ },
+ "comment" => {
+ data_type => "TEXT",
+ default_value => undef,
+ is_nullable => 1,
+ size => 65535,
+ },
+ "created_by" => {
+ data_type => "INT",
+ default_value => 0,
+ is_nullable => 0,
+ size => 11
+ },
+ "created_at" => {
+ data_type => "DATETIME",
timezone => 'Asia/Tokyo',
+ set_on_create => 1,
+ default_value => undef,
+ is_nullable => 1,
+ size => 19,
},
- modified_at => {
- data_type => 'datetime',
+ "modified_at" => {
+ data_type => "DATETIME",
timezone => 'Asia/Tokyo',
+ set_on_create => 1,
+ set_on_update => 1,
+ default_value => undef,
+ is_nullable => 1,
+ size => 19,
},
);
+__PACKAGE__->set_primary_key("id");
+
__PACKAGE__->belongs_to('restrant' => 'GourmetSpot::Schema::Restrant' => 'restrant_id');
__PACKAGE__->belongs_to('member' => 'GourmetSpot::Schema::Member' => 'created_by');
__PACKAGE__->has_many('map_review_tag' => 'GourmetSpot::Schema::TagReview' => 'review_id');
__PACKAGE__->many_to_many(tags => 'map_review_tag' => 'tag');
-# You can replace this text with custom content, and it will be preserved on regeneration
1;
@@ -10,13 +10,17 @@
[% END %]
</ul>
[% IF pager.previous_page %]
-<a href="[% c.uri_for('', {name => c.req.param('name') or '', _page => pager.previous_page}) %]">&lt; 前</a>
+<a href="[% c.req.uri_with({ _page => pager.previous_page }) %]">&lt; 前</a>
[% ELSE %]
&lt; 前
[% END %]
-|
+[% FOR p IN pager.pages_in_navigation %]
+[% IF p == pager.current_page %][% p %][% ELSE %]
+<a href="[% c.req.uri_with({_page => p}) %]">[% p %]</a>
+[% END %]
+[% END %]
[% IF pager.next_page %]
-<a href="[% c.uri_for('', {name => c.req.param('name') or '', _page => pager.next_page}) %]">次 &gt;</a>
+<a href="[% c.req.uri_with({_page => pager.next_page}) %]">次 &gt;</a>
[% ELSE %]
次 &gt;
[% END %]

0 comments on commit 56109a8

Please sign in to comment.