aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-07-10 20:42:51 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-07-10 20:42:51 +0000
commit99535516a8275b3c98a90cb037d2c88219c2b756 (patch)
tree66dadc45c8914b3d3d0d2949c277c5514bcf3c46
parentad0b52c377cccb45543fbd76d2e85288dfe4045e (diff)
downloadreaction-99535516a8275b3c98a90cb037d2c88219c2b756.tar.gz
reaction-99535516a8275b3c98a90cb037d2c88219c2b756.zip
String fragment viewport
-rw-r--r--lib/ComponentUI/Controller/TestModel/Baz.pm12
-rw-r--r--lib/ComponentUI/UI/ViewPort/Baz/ListView/Member.pm23
-rw-r--r--lib/Reaction/UI/ViewPort/Field/String/Fragment.pm44
-rw-r--r--t/lib/RTest/InterfaceModel/Reflector/DBIC.pm4
-rw-r--r--t/lib/RTest/TestDB.pm4
-rw-r--r--t/lib/RTest/TestDB/Baz.pm4
6 files changed, 85 insertions, 6 deletions
diff --git a/lib/ComponentUI/Controller/TestModel/Baz.pm b/lib/ComponentUI/Controller/TestModel/Baz.pm
index 2fece5a..6c88792 100644
--- a/lib/ComponentUI/Controller/TestModel/Baz.pm
+++ b/lib/ComponentUI/Controller/TestModel/Baz.pm
@@ -2,6 +2,7 @@ package ComponentUI::Controller::TestModel::Baz;
use base 'Reaction::UI::Controller::Collection::CRUD';
use Reaction::Class;
+use ComponentUI::UI::ViewPort::Baz::ListView::Member;
__PACKAGE__->config(
model_name => 'TestModel',
@@ -10,7 +11,16 @@ __PACKAGE__->config(
base => { Chained => '/base', PathPart => 'testmodel/baz' },
list => {
ViewPort => {
- enable_order_by => [qw/id name/],
+ enable_order_by => [qw/id name bool_field description/],
+ member_class => 'ComponentUI::UI::ViewPort::Baz::ListView::Member',
+ Member => {
+ Field => {
+ description => {
+ max_length => 40,
+ layout => 'value/string',
+ },
+ },
+ },
},
},
},
diff --git a/lib/ComponentUI/UI/ViewPort/Baz/ListView/Member.pm b/lib/ComponentUI/UI/ViewPort/Baz/ListView/Member.pm
new file mode 100644
index 0000000..26740ce
--- /dev/null
+++ b/lib/ComponentUI/UI/ViewPort/Baz/ListView/Member.pm
@@ -0,0 +1,23 @@
+package ComponentUI::UI::ViewPort::Baz::ListView::Member;
+
+use Reaction::Class;
+use namespace::clean -except => [ qw(meta) ];
+use aliased 'Reaction::UI::ViewPort::Field::String::Fragment';
+
+extends 'Reaction::UI::ViewPort::Collection::Grid::Member::WithActions';
+
+sub _build_layout {
+ 'collection/grid/member/with_actions';
+}
+
+sub _build_fields_for_name_description {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => Fragment, %$args);
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__;
+
diff --git a/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm b/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm
new file mode 100644
index 0000000..4205769
--- /dev/null
+++ b/lib/Reaction/UI/ViewPort/Field/String/Fragment.pm
@@ -0,0 +1,44 @@
+package Reaction::UI::ViewPort::Field::String::Fragment;
+
+use Reaction::Class;
+use MooseX::Types::Moose qw/Int/;
+extends 'Reaction::UI::ViewPort::Field::String';
+
+has max_length => (
+ is => 'rw',
+ isa => Int,
+ required => 1,
+ default => sub { 80 }
+);
+
+sub _build_layout { 'field/string' };
+
+around _build_value_string => sub {
+ my $super = shift;
+ my $self = $_[0];
+ my $string = $super->(@_);
+ my $max_len = $self->max_length;
+ if(length($string) > $max_len){
+ $string = join('', substr( $string, 0, $max_len - 3 ), '...');
+ }
+ return $string;
+};
+
+1;
+
+__END__;
+
+=head1 DESCRIPTION
+
+If it was possible to address the widgets in any way this wouldn't be necessary.
+
+Ideally this would be a widget instead of a viewport. But there is currently no
+way to implement this in a widget, because it is impossible to pass any
+arguments to widgets.
+
+Using this module will require subclassing the Object or Member Viewport to
+override the builder classes for the field you desire to render as a string
+fragment. If we ever get a way to pass arguments to layouts or widgets, this
+will be greatly simplified. Don't hold your breath.
+
+=cut
diff --git a/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm b/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm
index fe1cee6..73effd4 100644
--- a/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm
+++ b/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm
@@ -195,7 +195,7 @@ sub test_reflect_submodel :Tests{
my %attrs = map { $_->name => $_ } $member->parameter_attributes;
my $target;
if( $sm eq "Bar"){$target = 4; }
- elsif($sm eq "Baz"){$target = 4; }
+ elsif($sm eq "Baz"){$target = 5; }
elsif($sm eq "Foo"){$target = 5; }
Test::More::is( scalar keys %attrs, $target, "Correct # of attributes for $sm");
@@ -292,7 +292,7 @@ sub test_reflect_submodel_action :Tests{
my $attr_num;
if($action_name =~ /Delete/){next; }
elsif($sm eq "Bar"){$attr_num = 4; }
- elsif($sm eq "Baz"){$attr_num = 3; }
+ elsif($sm eq "Baz"){$attr_num = 4; }
elsif($sm eq "Foo"){$attr_num = 3; }
Test::More::is( scalar keys %attrs, $attr_num, "Correct # of attributes for $sm");
if($attr_num != keys %attrs ){
diff --git a/t/lib/RTest/TestDB.pm b/t/lib/RTest/TestDB.pm
index 25012d2..e7b5459 100644
--- a/t/lib/RTest/TestDB.pm
+++ b/t/lib/RTest/TestDB.pm
@@ -17,8 +17,8 @@ sub setup_test_data {
) } (1 .. 50)
]);
$self->populate('Baz' => [
- [ qw/ name / ],
- map { [ "Baz $_" ] } (1 .. 4)
+ [ qw/ name description/ ],
+ map { [ "Baz $_", ("lorem ipsum dolor sit amet," x $_) ] } (1 .. 4)
]);
$self->populate('Bar' => [
[ qw/ name foo_id / ],
diff --git a/t/lib/RTest/TestDB/Baz.pm b/t/lib/RTest/TestDB/Baz.pm
index 14bbfaa..8ea0c51 100644
--- a/t/lib/RTest/TestDB/Baz.pm
+++ b/t/lib/RTest/TestDB/Baz.pm
@@ -4,11 +4,12 @@ package # hide from PAUSE
use Moose;
extends 'DBIx::Class::Core';
-use MooseX::Types::Moose qw/ArrayRef Int Bool/;
+use MooseX::Types::Moose qw/ArrayRef Int Bool Str/;
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
has 'id' => (isa => Int, is => 'ro', required => 1);
has 'name' => (isa => NonEmptySimpleStr, is => 'rw', required => 1);
+has 'description' => (isa => Str, is => 'rw',);
has 'bool_field' => (isa => Bool, is => 'rw', required => 0);
has 'foo_list' => (
isa => ArrayRef,
@@ -27,6 +28,7 @@ __PACKAGE__->table('baz');
__PACKAGE__->add_columns(
id => { data_type => 'integer', size => 16, is_auto_increment => 1 },
name => { data_type => 'varchar', size => 255 },
+ description => { data_type => 'text', is_nullable => 1 },
bool_field => {
data_type => 'char',
size => '1',