X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FHelper%2FGetModels%2FSorted.pm;h=73144dbc4eeb41863829b1e71a862821a2db3e3b;hb=a9d9ca02abd3a0ff1e43f23888142266174bec55;hp=14e733d452c397a96c8098f8e8d98c867e73c106;hpb=7dfa1a54b755208936400e4dc9a890cadc983c1e;p=kivitendo-erp.git
diff --git a/SL/Controller/Helper/GetModels/Sorted.pm b/SL/Controller/Helper/GetModels/Sorted.pm
index 14e733d45..73144dbc4 100644
--- a/SL/Controller/Helper/GetModels/Sorted.pm
+++ b/SL/Controller/Helper/GetModels/Sorted.pm
@@ -6,6 +6,8 @@ use parent 'SL::Controller::Helper::GetModels::Base';
use Carp;
use List::MoreUtils qw(uniq);
+use Data::Dumper;
+
use Rose::Object::MakeMethods::Generic (
scalar => [ qw(by dir specs form_data) ],
'scalar --get_set_init' => [ qw(form_params) ],
@@ -76,6 +78,12 @@ sub finalize {
my %sort_params = $self->read_params;
my $sort_spec = $self->specs->{ $sort_params{sort_by} };
+ if (!$sort_spec) {
+ no warnings 'once';
+ $::lxdebug->show_backtrace(1);
+ die "Unknown sort spec '$sort_params{sort_by}'";
+ }
+
$params{sort_by} = "SL::DB::Manager::$sort_spec->{model}"->make_sort_string(sort_by => $sort_spec->{model_column}, sort_dir => $sort_params{sort_dir});
%params;
@@ -143,34 +151,26 @@ of sorting lists of database models in a controller
In a controller:
- use SL::Controller::Helper::GetModels;
- use SL::Controller::Helper::Sorted;
-
- __PACKAGE__->make_sorted( # update this
- DEFAULT_BY => 'run_at',
- DEFAULT_DIR => 1,
- MODEL => 'BackgroundJobHistory',
- ONLY => [ qw(list) ],
-
- error => $::locale->text('Error'),
- package_name => $::locale->text('Package name'),
- run_at => $::locale->text('Run at'),
+ SL::Controller::Helper::GetModels->new(
+ ...
+ sorted => {
+ _default => {
+ by => 'run_at',
+ dir => 1,
+ },
+ error => $::locale->text('Error'),
+ package_name => $::locale->text('Package name'),
+ run_at => $::locale->text('Run at'),
+ },
);
- sub action_list {
- my ($self) = @_;
-
- my $sorted_models = $self->get_models;
- $self->render('controller/list', ENTRIES => $sorted_models);
- }
-
-In said template:
+In template:
[% USE L %]
-
[% L.sortable_table_header('package_name') %]
# models
+
[% L.sortable_table_header('package_name') %]
[% L.sortable_table_header('run_at') %]
[% L.sortable_table_header('error') %]
@@ -186,95 +186,44 @@ In said template:
=head1 OVERVIEW
-This specialized helper module enables controllers to display a
+This C plugin enables controllers to display a
sortable list of database models with as few lines as possible.
For this to work the controller has to provide the information which
-indexes are eligible for sorting etc. by a call to L at #not compiletime
-compile time.
-
-The underlying functionality that enables the use of more than just
-the sort helper is provided by the controller helper C. It
-provides mechanisms for helpers like this one to hook into certain
-calls made by the controller (C and C) so
-that the specialized helpers can inject their parameters into the
-calls to e.g. C.
-
-A template on the other hand can use the method
-C from the layout helper module C.
-
-This module requires that the Rose model managers use their C
-helper.
-
-The C helper hooks into the controller call to the action via
-a C hook. This is done so that it can remember the sort
-parameters that were used in the current view.
-
-=head1 PACKAGE FUNCTIONS
+indexes are eligible for sorting etc. through it's configuration of
+C.
-=over 4
-
-=item C # meh complete rewrite
+A template can then use the method C from the layout
+helper module C.
-This function must be called by a controller at compile time. It is
-uesd to set the various parameters required for this helper to do its
-magic.
+This module requires that the Rose model managers use their
+C helper.
-There are two sorts of keys in the hash C<%sort_spec>. The first kind
-is written in all upper-case. Those parameters are control
-parameters. The second kind are all lower-case and represent indexes
-that can be used for sorting (similar to database column names). The
-second kind are also the indexes you use in a template when calling
-C<[% L.sorted_table_header(...) %]>.
-
-Control parameters include the following:
+=head1 OPTIONS
=over 4
-=item * C
-
-Optional. A string: the name of the Rose database model that is used
-as a default in certain cases. If this parameter is missing then it is
-derived from the controller's package (e.g. for the controller
-C the C would default to
-C).
-
-=item * C
-
-Optional. A string: the index to sort by if the user hasn't clicked on
-any column yet (meaning: if the C<$::form> parameters for sorting do
-not contain a valid index).
-
-Defaults to the underlying database model's default sort column name.
+=item * C<_default HASHREF>
-=item * C
+Optional. If it exists, it is expected to contain the keys C and C and
+will be used to set the default sorting if nothing is found in C