work in progress, listview still broken
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection / Grid.pm
1 package Reaction::UI::ViewPort::Collection::Grid;
2
3 use Reaction::Class;
4
5 use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6 use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member';
7
8 class Grid is 'Reaction::UI::ViewPort::Collection', which {
9
10   has field_order    => ( isa => 'ArrayRef', is => 'ro', lazy_build => 1);
11   has field_labels   => ( isa => 'HashRef',  is => 'ro', lazy_build => 1);
12
13   has ordered_fields  => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
14   has excluded_fields => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
15
16   ####################################
17   implements _build_member_class => as { };
18
19   implements _build_field_labels => as {
20     my $self = shift;
21     my %labels;
22     for my $field ( @{$self->field_order}){
23       $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
24     }
25     return \%labels;
26   };
27
28   implements _build_field_order     => as { []; };
29   implements _build_excluded_fields => as { []; };
30
31   implements _build_ordered_fields => as {
32     my ($self) = @_;
33     confess("current_collection lacks a value for 'member_type' attribute")
34       unless $self->current_collection->has_member_type;
35     my %excluded = map { $_ => undef } @{ $self->excluded_fields };
36     #treat _$field_name as private and exclude fields with no reader
37     my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name }
38       grep { defined $_->get_read_method }
39         $self->current_collection->member_type->meta->parameter_attributes;
40     return $self->sort_by_spec($self->field_order, \@names);
41   };
42
43   before _build_members => sub {
44     my ($self) = @_;
45     $self->member_args->{ordered_fields} ||= $self->ordered_fields;
46   };
47
48 };
49
50
51
52 1;