1 package Reaction::UI::ViewPort::Collection::Grid;
5 use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6 use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member::WithActions';
8 use namespace::clean -except => [ qw(meta) ];
9 use MooseX::Types::Moose qw/ArrayRef HashRef Int/;
10 extends 'Reaction::UI::ViewPort::Collection';
12 has field_order => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
13 has excluded_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
14 has included_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
15 has computed_field_order => (is => 'ro', isa => ArrayRef, lazy_build => 1);
17 has _raw_field_labels => (
20 init_arg => 'field_labels',
21 default => sub { {} },
31 has member_action_count => (
38 for (@{ $self->members }) {
39 my $protos = $_->action_prototypes;
40 return scalar(keys(%$protos));
46 ####################################
47 sub _build_member_class { WithActions };
49 sub _build_field_labels {
51 my %labels = %{$self->_raw_field_labels};
52 for my $field ( @{$self->computed_field_order}) {
53 next if defined $labels{$field};
54 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
59 sub _build_field_order { []; }
61 sub _build_excluded_fields { []; }
63 sub _build_included_fields { [] }
65 #this is a total clusterfuck and it sucks we should just eliminate it and have
66 # the grid members not render ArrayRef or Collection fields
67 sub _build_computed_field_order {
69 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
70 my %included = map { $_ => undef } @{ $self->included_fields };
71 #treat _$field_name as private and exclude fields with no reader
72 my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) )
73 && !exists($excluded{$_})} map { $_->name }
75 !($_->has_type_constraint &&
76 ($_->type_constraint->is_a_type_of('ArrayRef') ||
77 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
78 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
81 grep { defined $_->get_read_method }
82 $self->current_collection->member_type->parameter_attributes;
84 return $self->sort_by_spec($self->field_order, \@names);
87 around _build_members => sub {
90 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
91 my $members = $self->$orig(@_);
96 __PACKAGE__->meta->make_immutable;
105 Reaction::UI::ViewPort::Collection
109 This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
110 homogenous collection of Reaction::InterfaceModel::Objects as a grid.
116 =head2 excluded_fields
118 List of field names to exclude.
120 =head2 included_fields
122 List of field names to include. If both C<included_fields> and
123 C<excluded_fields> are specified the result is those fields which
124 are in C<included_fields> and not in C<excluded_fields>.
126 =head2 included_fields
128 List of field names to include. If both C<included_fields> and
129 C<excluded_fields> are specified the result is those fields which
130 are in C<included_fields> and not in C<excluded_fields>.
135 =head2 _raw_field_labels
137 =head2 computed_field_order
139 =head2 member_action_count
141 =head1 INTERNAL METHODS
143 These methods, although stable, are subject to change without notice. These are meant
144 to be used only by developers. End users should refrain from using these methods to
145 avoid potential breakages.
149 L<Reaction::UI::ViewPort::Collection>
153 See L<Reaction::Class> for authors.
157 See L<Reaction::Class> for the license.