missed default
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection / Grid.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Collection::Grid;
2
3use Reaction::Class;
4
5use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member';
7
81393881 8use namespace::clean -except => [ qw(meta) ];
9extends 'Reaction::UI::ViewPort::Collection';
ddccc6a2 10
81393881 11
12
13has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
14has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
e113d857 15has _raw_field_labels => (
16 is => 'rw', isa => 'HashRef',
17 init_arg => 'field_labels',
4646dc25 18 default => sub { {} },
e113d857 19);
20has field_labels => (
21 is => 'ro', isa => 'HashRef',
22 lazy_build => 1, init_arg => undef,
23);
81393881 24
25has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
26
27####################################
28sub _build_member_class { Member };
29sub _build_field_labels {
30 my $self = shift;
e113d857 31 my %labels = %{$self->_raw_field_labels};
32 for my $field ( @{$self->computed_field_order}) {
33 next if $labels{$field};
81393881 34 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
35 }
36 return \%labels;
37};
38sub _build_field_order { []; };
39sub _build_excluded_fields { []; };
40sub _build_computed_field_order {
41 my ($self) = @_;
42 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
43 #treat _$field_name as private and exclude fields with no reader
44 my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name }
45 grep {
46 !($_->has_type_constraint &&
47 ($_->type_constraint->is_a_type_of('ArrayRef') ||
48 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
49 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
50 )
51 ) }
52 grep { defined $_->get_read_method }
53 $self->current_collection->member_type->parameter_attributes;
54
55 return $self->sort_by_spec($self->field_order, \@names);
ddccc6a2 56};
57
81393881 58before _build_members => sub {
59 my ($self) = @_;
60 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
61};
62
63__PACKAGE__->meta->make_immutable;
64
65
2dba7201 661;
ddccc6a2 67
2dba7201 68__END__;
ddccc6a2 69
2dba7201 70=head1 NAME
71
72Reaction::UI::ViewPort::Collection
73
74=head1 DESCRIPTION
75
76This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
77homogenous collection of Reaction::InterfaceModel::Objects as a grid.
78
79=head1 ATTRIBUTES
80
81=head2 field_order
82
83=head2 excluded_fields
84
85=head2 field_labels
86
87=head2 computed_field_order
88
2dba7201 89=head1 INTERNAL METHODS
90
91These methods, although stable, are subject to change without notice. These are meant
92to be used only by developers. End users should refrain from using these methods to
93avoid potential breakages.
94
95=head1 SEE ALSO
96
97L<Reaction::UI::ViewPort::Collection>
98
99=head1 AUTHORS
100
101See L<Reaction::Class> for authors.
102
103=head1 LICENSE
104
105See L<Reaction::Class> for the license.
106
107=cut