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 extends 'Reaction::UI::ViewPort::Collection';
11 has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
12 has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
13 has included_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
14 has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
16 has _raw_field_labels => (
19 init_arg => 'field_labels',
20 default => sub { {} },
30 has member_action_count => (
37 for (@{ $self->members }) {
38 my $protos = $_->action_prototypes;
39 return scalar(keys(%$protos));
45 ####################################
46 sub _build_member_class { WithActions };
48 sub _build_field_labels {
50 my %labels = %{$self->_raw_field_labels};
51 for my $field ( @{$self->computed_field_order}) {
52 next if $labels{$field};
53 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
58 sub _build_field_order { []; }
60 sub _build_excluded_fields { []; }
62 sub _build_included_fields { [] }
64 #this is a total clusterfuck and it sucks we should just eliminate it and have
65 # the grid members not render ArrayRef or Collection fields
66 sub _build_computed_field_order {
68 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
69 my %included = map { $_ => undef } @{ $self->included_fields };
70 #treat _$field_name as private and exclude fields with no reader
71 my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) )
72 && !exists($excluded{$_})} map { $_->name }
74 !($_->has_type_constraint &&
75 ($_->type_constraint->is_a_type_of('ArrayRef') ||
76 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
77 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
80 grep { defined $_->get_read_method }
81 $self->current_collection->member_type->parameter_attributes;
83 return $self->sort_by_spec($self->field_order, \@names);
86 around _build_members => sub {
89 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
90 $self->member_args->{computed_action_order} ||= [];
91 my $members = $self->$orig(@_);
94 for my $member (@$members){
95 $member->clear_computed_action_order;
96 my $order = $member->computed_action_order;
97 @{ $self->member_args->{computed_action_order} } = @$order;
104 __PACKAGE__->meta->make_immutable;
113 Reaction::UI::ViewPort::Collection
117 This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
118 homogenous collection of Reaction::InterfaceModel::Objects as a grid.
124 =head2 excluded_fields
126 List of field names to exclude.
128 =head2 included_fields
130 List of field names to include. If both C<included_fields> and
131 C<excluded_fields> are specified the result is those fields which
132 are in C<included_fields> and not in C<excluded_fields>.
134 =head2 included_fields
136 List of field names to include. If both C<included_fields> and
137 C<excluded_fields> are specified the result is those fields which
138 are in C<included_fields> and not in C<excluded_fields>.
143 =head2 _raw_field_labels
145 =head2 computed_field_order
147 =head2 member_action_count
149 =head1 INTERNAL METHODS
151 These methods, although stable, are subject to change without notice. These are meant
152 to be used only by developers. End users should refrain from using these methods to
153 avoid potential breakages.
157 L<Reaction::UI::ViewPort::Collection>
161 See L<Reaction::Class> for authors.
165 See L<Reaction::Class> for the license.