1 package Reaction::UI::ViewPort::Collection::Grid;
5 use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6 use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member';
8 use namespace::clean -except => [ qw(meta) ];
9 extends 'Reaction::UI::ViewPort::Collection';
13 has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
14 has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
15 has _raw_field_labels => (
16 is => 'rw', isa => 'HashRef',
17 init_arg => 'field_labels',
18 default => sub { {} },
21 is => 'ro', isa => 'HashRef',
22 lazy_build => 1, init_arg => undef,
25 has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
27 ####################################
28 sub _build_member_class { Member };
29 sub _build_field_labels {
31 my %labels = %{$self->_raw_field_labels};
32 for my $field ( @{$self->computed_field_order}) {
33 next if $labels{$field};
34 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
38 sub _build_field_order { []; };
39 sub _build_excluded_fields { []; };
40 sub _build_computed_field_order {
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 }
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') }
52 grep { defined $_->get_read_method }
53 $self->current_collection->member_type->parameter_attributes;
55 return $self->sort_by_spec($self->field_order, \@names);
58 before _build_members => sub {
60 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
63 __PACKAGE__->meta->make_immutable;
72 Reaction::UI::ViewPort::Collection
76 This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
77 homogenous collection of Reaction::InterfaceModel::Objects as a grid.
83 =head2 excluded_fields
87 =head2 computed_field_order
89 =head1 INTERNAL METHODS
91 These methods, although stable, are subject to change without notice. These are meant
92 to be used only by developers. End users should refrain from using these methods to
93 avoid potential breakages.
97 L<Reaction::UI::ViewPort::Collection>
101 See L<Reaction::Class> for authors.
105 See L<Reaction::Class> for the license.