Commit | Line | Data |
ddccc6a2 |
1 | package Reaction::UI::ViewPort::Collection::Grid; |
2 | |
3 | use Reaction::Class; |
4 | |
5 | use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection'; |
6 | use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member'; |
7 | |
81393881 |
8 | use namespace::clean -except => [ qw(meta) ]; |
9 | extends 'Reaction::UI::ViewPort::Collection'; |
ddccc6a2 |
10 | |
81393881 |
11 | |
12 | |
13 | has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); |
14 | has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); |
15 | has field_labels => ( is => 'ro', isa => 'HashRef', lazy_build => 1); |
16 | |
17 | has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1); |
18 | |
19 | #################################### |
20 | sub _build_member_class { Member }; |
21 | sub _build_field_labels { |
22 | my $self = shift; |
23 | my %labels; |
24 | for my $field ( @{$self->computed_field_order}){ |
25 | $labels{$field} = join(' ', map{ ucfirst } split('_', $field)); |
26 | } |
27 | return \%labels; |
28 | }; |
29 | sub _build_field_order { []; }; |
30 | sub _build_excluded_fields { []; }; |
31 | sub _build_computed_field_order { |
32 | my ($self) = @_; |
33 | my %excluded = map { $_ => undef } @{ $self->excluded_fields }; |
34 | #treat _$field_name as private and exclude fields with no reader |
35 | my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name } |
36 | grep { |
37 | !($_->has_type_constraint && |
38 | ($_->type_constraint->is_a_type_of('ArrayRef') || |
39 | eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} || |
40 | eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') } |
41 | ) |
42 | ) } |
43 | grep { defined $_->get_read_method } |
44 | $self->current_collection->member_type->parameter_attributes; |
45 | |
46 | return $self->sort_by_spec($self->field_order, \@names); |
ddccc6a2 |
47 | }; |
48 | |
81393881 |
49 | before _build_members => sub { |
50 | my ($self) = @_; |
51 | $self->member_args->{computed_field_order} ||= $self->computed_field_order; |
52 | }; |
53 | |
54 | __PACKAGE__->meta->make_immutable; |
55 | |
56 | |
2dba7201 |
57 | 1; |
ddccc6a2 |
58 | |
2dba7201 |
59 | __END__; |
ddccc6a2 |
60 | |
2dba7201 |
61 | =head1 NAME |
62 | |
63 | Reaction::UI::ViewPort::Collection |
64 | |
65 | =head1 DESCRIPTION |
66 | |
67 | This subclass of L<Reaction::UI::ViewPort::Collection> allows you to display a |
68 | homogenous collection of Reaction::InterfaceModel::Objects as a grid. |
69 | |
70 | =head1 ATTRIBUTES |
71 | |
72 | =head2 field_order |
73 | |
74 | =head2 excluded_fields |
75 | |
76 | =head2 field_labels |
77 | |
78 | =head2 computed_field_order |
79 | |
2dba7201 |
80 | =head1 INTERNAL METHODS |
81 | |
82 | These methods, although stable, are subject to change without notice. These are meant |
83 | to be used only by developers. End users should refrain from using these methods to |
84 | avoid potential breakages. |
85 | |
86 | =head1 SEE ALSO |
87 | |
88 | L<Reaction::UI::ViewPort::Collection> |
89 | |
90 | =head1 AUTHORS |
91 | |
92 | See L<Reaction::Class> for authors. |
93 | |
94 | =head1 LICENSE |
95 | |
96 | See L<Reaction::Class> for the license. |
97 | |
98 | =cut |