added action_filter
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection / Grid.pm
index 6d8e0a1..1cf3fd9 100644 (file)
@@ -6,29 +6,31 @@ use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
 use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member::WithActions';
 
 use namespace::clean -except => [ qw(meta) ];
+use MooseX::Types::Moose qw/ArrayRef HashRef Int/;
 extends 'Reaction::UI::ViewPort::Collection';
 
-has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
-has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
-has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
+has field_order => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
+has excluded_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
+has included_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1);
+has computed_field_order => (is => 'ro', isa => ArrayRef, lazy_build => 1);
 
 has _raw_field_labels => (
   is => 'rw',
-  isa => 'HashRef',
+  isa => HashRef,
   init_arg => 'field_labels',
   default => sub { {} },
 );
 
 has field_labels => (
   is => 'ro',
-  isa => 'HashRef',
+  isa => HashRef,
   lazy_build => 1,
   init_arg => undef,
 );
 
 has member_action_count => (
   is => 'rw',
-  isa => 'Int',
+  isa => Int,
   required => 1,
   lazy => 1,
   default => sub {
@@ -48,7 +50,7 @@ sub _build_field_labels {
   my $self = shift;
   my %labels = %{$self->_raw_field_labels};
   for my $field ( @{$self->computed_field_order}) {
-    next if $labels{$field};
+    next if defined $labels{$field};
     $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
   }
   return \%labels;
@@ -58,13 +60,17 @@ sub _build_field_order { []; }
 
 sub _build_excluded_fields { []; }
 
+sub _build_included_fields { [] }
+
 #this is a total clusterfuck and it sucks we should just eliminate it and have
 # the grid members not render ArrayRef or Collection fields
 sub _build_computed_field_order {
   my ($self) = @_;
   my %excluded = map { $_ => undef } @{ $self->excluded_fields };
+  my %included = map { $_ => undef } @{ $self->included_fields };
   #treat _$field_name as private and exclude fields with no reader
-  my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name }
+  my @names = grep { $_ !~ /^_/ &&  (!%included || exists( $included{$_}) )
+    && !exists($excluded{$_})} map { $_->name }
     grep {
       !($_->has_type_constraint &&
         ($_->type_constraint->is_a_type_of('ArrayRef') ||
@@ -118,10 +124,29 @@ homogenous collection of Reaction::InterfaceModel::Objects as a grid.
 
 =head2 excluded_fields
 
+List of field names to exclude.
+
+=head2 included_fields
+
+List of field names to include. If both C<included_fields> and
+C<excluded_fields> are specified the result is those fields which
+are in C<included_fields> and not in C<excluded_fields>.
+
+=head2 included_fields
+
+List of field names to include. If both C<included_fields> and
+C<excluded_fields> are specified the result is those fields which
+are in C<included_fields> and not in C<excluded_fields>.
+
+
 =head2 field_labels
 
+=head2 _raw_field_labels
+
 =head2 computed_field_order
 
+=head2 member_action_count
+
 =head1 INTERNAL METHODS
 
 These methods, although stable, are subject to change without notice. These are meant