changes so far for new moose / mop
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / GridView / Role / Order.pm
CommitLineData
e22de101 1package Reaction::UI::ViewPort::GridView::Role::Order;
2
3use Reaction::Role;
4
5role Order, which {
6
7 has order_by => (isa => 'Str', is => 'rw', trigger_adopt('order_by'));
8 has order_by_desc => (isa => 'Int', is => 'rw', trigger_adopt('order_by'), lazy_build => 1);
9
89939ff9 10 implements _build_order_by_desc => as { 0 };
b8faba69 11
12 implements adopt_order_by => as {
13 shift->clear_current_collection;
14 };
15
89939ff9 16 around _build_current_collection => sub {
e22de101 17 my $orig = shift;
18 my ($self) = @_;
19 my $collection = $orig->(@_);
20 my %attrs;
21
22 #XXX DBICism that needs to be fixed
23 if ($self->has_order_by) {
24 $attrs{order_by} = $self->order_by;
25 $attrs{order_by} .= ' DESC' if ($self->order_by_desc);
26 }
27
28 return $collection->where(undef, \%attrs);
29 };
30
31 around accept_events => sub { ('order_by', 'order_by_desc', shift->(@_)); };
32
33};
34
351;