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