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