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 computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
15 has _raw_field_labels => (
18 init_arg => 'field_labels',
19 default => sub { {} },
29 has member_action_count => (
36 for (@{ $self->members }) {
37 my $protos = $_->action_prototypes;
38 return scalar(keys(%$protos));
44 ####################################
45 sub _build_member_class { WithActions };
47 sub _build_field_labels {
49 my %labels = %{$self->_raw_field_labels};
50 for my $field ( @{$self->computed_field_order}) {
51 next if $labels{$field};
52 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
57 sub _build_field_order { []; }
59 sub _build_excluded_fields { []; }
61 #this is a total clusterfuck and it sucks we should just eliminate it and have
62 # the grid members not render ArrayRef or Collection fields
63 sub _build_computed_field_order {
65 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
66 #treat _$field_name as private and exclude fields with no reader
67 my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name }
69 !($_->has_type_constraint &&
70 ($_->type_constraint->is_a_type_of('ArrayRef') ||
71 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
72 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
75 grep { defined $_->get_read_method }
76 $self->current_collection->member_type->parameter_attributes;
78 return $self->sort_by_spec($self->field_order, \@names);
81 around _build_members => sub {
84 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
85 $self->member_args->{computed_action_order} ||= [];
86 my $members = $self->$orig(@_);
89 for my $member (@$members){
90 $member->clear_computed_action_order;
91 my $order = $member->computed_action_order;
92 @{ $self->member_args->{computed_action_order} } = @$order;
99 __PACKAGE__->meta->make_immutable;
108 Reaction::UI::ViewPort::Collection
112 This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
113 homogenous collection of Reaction::InterfaceModel::Objects as a grid.
119 =head2 excluded_fields
123 =head2 computed_field_order
125 =head1 INTERNAL METHODS
127 These methods, although stable, are subject to change without notice. These are meant
128 to be used only by developers. End users should refrain from using these methods to
129 avoid potential breakages.
133 L<Reaction::UI::ViewPort::Collection>
137 See L<Reaction::Class> for authors.
141 See L<Reaction::Class> for the license.