CatalystX::Resource::TraitFor::Controller::Resource::Sortable - makes your resource sortable
version 0.001_005
# TestApp.pm 'Controller::Resource::Artist' => { resultset_key => 'artists_rs', resources_key => 'artists', resource_key => 'artist', form_class => 'TestApp::Form::Resource::Artist', model => 'DB::Resource::Artist', redirect_mode => 'list', traits => ['Sortable'], actions => { base => { PathPart => 'artists', }, }, }, # TestApp/Schema/Result/Resource/Artist.pm __PACKAGE__->load_components(qw/ Ordered Core /); __PACKAGE__->table('artist'); __PACKAGE__->add_columns( ..., 'position', { data_type => 'integer', is_numeric => 1, is_nullable => 0, }, ); __PACKAGE__->resultset_attributes({ order_by => 'position' }); __PACKAGE__->position_column('position');
adds these paths to your Controller which call move_previous/move_next on your resource item as provided by DBIx::Class::Ordered
Make sure the schema for your sortable resource has a 'position' column.
/resource/*/move_previous /resource/*/move_next
For nested resources you need to set a grouping_column Example: Artist has_many Albums has_many Songs
# TestApp/Schema/Result/Resource/Song.pm __PACKAGE__->grouping_column('album_id');
will switch the resource with the next one
will switch the resource with the previous one
David Schmidt <davewood@cpan.org>
This software is copyright (c) 2011 by David Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install CatalystX::Resource, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::Resource
CPAN shell
perl -MCPAN -e shell install CatalystX::Resource
For more information on module installation, please visit the detailed CPAN module installation guide.