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(@$protos);
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 #this is a total clusterfuck and it sucks we should just eliminate it and have
63 # the grid members not render ArrayRef or Collection fields
64 sub _build_computed_field_order {
66 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
67 #treat _$field_name as private and exclude fields with no reader
68 my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name }
70 !($_->has_type_constraint &&
71 ($_->type_constraint->is_a_type_of('ArrayRef') ||
72 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
73 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
76 grep { defined $_->get_read_method }
77 $self->current_collection->member_type->parameter_attributes;
79 return $self->sort_by_spec($self->field_order, \@names);
82 around _build_members => sub {
85 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
86 # $self->member_args->{computed_action_order} ||= [];
87 my $members = $self->$orig(@_);
90 # for my $member (@$members){
91 # $member->clear_computed_action_order;
92 # my $order = $member->computed_action_order;
93 # @{ $self->member_args->{computed_action_order} } = @$order;
100 __PACKAGE__->meta->make_immutable;
109 Reaction::UI::ViewPort::Collection
113 This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a
114 homogenous collection of Reaction::InterfaceModel::Objects as a grid.
120 =head2 excluded_fields
124 =head2 computed_field_order
126 =head1 INTERNAL METHODS
128 These methods, although stable, are subject to change without notice. These are meant
129 to be used only by developers. End users should refrain from using these methods to
130 avoid potential breakages.
134 L<Reaction::UI::ViewPort::Collection>
138 See L<Reaction::Class> for authors.
142 See L<Reaction::Class> for the license.