1 package Reaction::UI::ViewPort::Role::FieldArgs;
4 use namespace::clean -except => [ qw(meta) ];
6 has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
7 has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
8 has included_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
9 has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
11 has _raw_field_labels => (
14 init_arg => 'field_labels',
15 default => sub { {} },
25 sub _build_field_labels {
27 my %labels = %{$self->_raw_field_labels};
28 for my $field ( @{$self->computed_field_order}) {
29 next if defined $labels{$field};
30 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
35 sub _build_field_order { [] }
37 sub _build_excluded_fields { [] }
39 sub _build_included_fields { [] }
41 #this is a total clusterfuck and it sucks we should just eliminate it and have
42 # the grid members not render ArrayRef or Collection fields
43 sub _build_computed_field_order {
45 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
46 my %included = map { $_ => undef } @{ $self->included_fields };
47 #treat _$field_name as private and exclude fields with no reader
48 my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) )
49 && !exists($excluded{$_})} map { $_->name }
51 !($_->has_type_constraint &&
52 ($_->type_constraint->is_a_type_of('ArrayRef') ||
53 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
54 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
57 grep { defined $_->get_read_method }
58 $self->current_collection->member_type->parameter_attributes;
60 return $self->sort_by_spec($self->field_order, \@names);
63 around _build_members => sub {
66 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
67 $self->member_args->{computed_action_order} ||= [];
68 my $members = $self->$orig(@_);
71 for my $member (@$members){
72 $member->clear_computed_action_order;
73 my $order = $member->computed_action_order;
74 @{ $self->member_args->{computed_action_order} } = @$order;
87 Reaction::UI::ViewPort::Role::FieldOptions
95 =head2 excluded_fields
97 List of field names to exclude.
99 =head2 included_fields
101 List of field names to include. If both C<included_fields> and
102 C<excluded_fields> are specified the result is those fields which
103 are in C<included_fields> and not in C<excluded_fields>.
105 =head2 included_fields
107 List of field names to include. If both C<included_fields> and
108 C<excluded_fields> are specified the result is those fields which
109 are in C<included_fields> and not in C<excluded_fields>.
113 =head2 computed_field_order
115 =head1 INTERNAL METHODS
117 These methods, although stable, are subject to change without notice. These are meant
118 to be used only by developers. End users should refrain from using these methods to
119 avoid potential breakages.
123 L<Reaction::UI::ViewPort::Collection>
127 See L<Reaction::Class> for authors.
131 See L<Reaction::Class> for the license.