From 26813507465a6fd209cd902c33a16974627e9670 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 15 Oct 2013 15:33:41 +0200 Subject: [PATCH] Doku cleanup --- SL/Controller/Helper/GetModels/Filtered.pm | 1 - SL/Controller/Helper/GetModels/Paginated.pm | 124 ++++-------------- SL/Controller/Helper/GetModels/Sorted.pm | 133 ++++++-------------- 3 files changed, 65 insertions(+), 193 deletions(-) diff --git a/SL/Controller/Helper/GetModels/Filtered.pm b/SL/Controller/Helper/GetModels/Filtered.pm index 88a298860..6d2be88e9 100644 --- a/SL/Controller/Helper/GetModels/Filtered.pm +++ b/SL/Controller/Helper/GetModels/Filtered.pm @@ -140,7 +140,6 @@ In a controller: filtered => 0, ); - =head1 OVERVIEW This C plugin enables use of the diff --git a/SL/Controller/Helper/GetModels/Paginated.pm b/SL/Controller/Helper/GetModels/Paginated.pm index 871f4b5c1..ad5e10c14 100644 --- a/SL/Controller/Helper/GetModels/Paginated.pm +++ b/SL/Controller/Helper/GetModels/Paginated.pm @@ -122,59 +122,30 @@ of paginating lists of database models in a controller In a controller: - use SL::Controller::Helper::GetModels; - use SL::Controller::Helper::Paginated; - - __PACKAGE__->make_paginated( - MODEL => 'BackgroundJobHistory', - ONLY => [ qw(list) ], - FORM_PARAMS => [ qw(page per_page) ], + SL::Controller::Helper::GetModels->new( + .. + paginated => { + form_params => [ qw(page per_page) ], + per_page => 20, + } ); - sub action_list { - my ($self) = @_; - - my $paginated_models = $self->get_models; - $self->render('controller/list', ENTRIES => $paginated_models); - } - In said template: - [% USE L %] - - - - - ... - - - - - [% FOREACH entry = ENTRIES %] - - ... - - [% END %] - -
- [% L.paginate_controls %] =head1 OVERVIEW -This specialized helper module enables controllers to display a -paginatable list of database models with as few lines as possible. It -can also be combined trivially with the L -helper for sortable lists. +This C plugin enables controllers to display a +paginatable 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 paginateing etc. by a call to -L at compile time. +indexes are eligible for paginateing etc. during C creation. The underlying functionality that enables the use of more than just the paginate helper is provided by the controller helper -C. See the documentation for L for -more information on it. +C. See the documentation for L +for more information on it. A template can use the method C from the layout helper module C which renders the links for navigation between the @@ -183,53 +154,18 @@ pages. 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 paginate -parameters that were used in the current view. - -=head1 PACKAGE FUNCTIONS +=head1 OPTIONS =over 4 -=item 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. - -The hash C<%paginate_spec> can include the following parameters: - -=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. Either a code reference or the name of function to be called -on the controller importing this helper. - -If this funciton is given then the paginate helper calls it whenever -it has to count the total number of models for calculating the number -of pages to display. The function must return a hash reference with -elements suitable for passing to a Rose model manager's C -function. - -This can be used e.g. when filtering is used. - -=item * C +=item * C -Optional. An integer: the number of models to return per page. +Optional. The number of models to return per page. Defaults to the underlying database model's default number of models per page. -=item * C +=item * C Optional. An array reference with exactly two strings that name the indexes in C<$::form> in which the current page's number (the first @@ -238,19 +174,11 @@ element in the array) are stored. Defaults to the values C and C if missing. -=item * C - -Optional. An array reference containing a list of action names for -which the paginate parameters should be saved. If missing or empty then -all actions invoked on the controller are monitored. - -=back - =back =head1 INSTANCE FUNCTIONS -These functions are called on a controller instance. +These functions are called on a C instance and delegated here. =over 4 @@ -285,24 +213,26 @@ displayed). =item C -Returns a hash reference to the paginate spec structure given in the call -to L after normalization (hash reference construction, +Returns a hash reference to the paginate spec structure given in the +configuration after normalization (hash reference construction, applying default parameters etc). -=item C - -Disable pagination for the duration of the current action. Can be used -when using the attribute C to L does not -cover all cases. - =back =head1 BUGS -Nothing here yet. +C generates an array with an entry for every page, which gets +slow if there are a lot of entries. Current observation holds that up to about +1000 pages there is no noticable slowdown, but at about 10000 it gets +noticable. At 100k-500k pages it's takes way too long and should be remodelled. + +This case currently only applies for databases with very large amounts of parts +that get paginated, but BackgroundJobHistory can also accumulate. =head1 AUTHOR Moritz Bunkus Em.bunkus@linet-services.deE +Sven Schöling Es.schoeling@linet-services.deE + =cut diff --git a/SL/Controller/Helper/GetModels/Sorted.pm b/SL/Controller/Helper/GetModels/Sorted.pm index 14e733d45..c20dc3f07 100644 --- a/SL/Controller/Helper/GetModels/Sorted.pm +++ b/SL/Controller/Helper/GetModels/Sorted.pm @@ -143,34 +143,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 %] - # models + @@ -186,95 +178,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. +indexes are eligible for sorting etc. through it's configuration of +C. -This module requires that the Rose model managers use their C -helper. +A template can then use the method C from the layout +helper module C. -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. +This module requires that the Rose model managers use their +C helper. -=head1 PACKAGE FUNCTIONS +=head1 OPTIONS =over 4 -=item C # meh complete rewrite - -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. - -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: - -=over 4 +=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. -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). +Defaults to the underlying database model's default. -=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 - -Optional. Default sort direction (ascending for trueish values, -descrending for falsish values). - -Defaults to the underlying database model's default sort direction. - -=item * C +=item * C Optional. An array reference with exactly two strings that name the -indexes in C<$::form> in which the sort index (the first element in +indexes in C in which the sort index (the first element in the array) and sort direction (the second element in the array) are stored. Defaults to the values C and C if missing. -=item * C - -Optional. An array reference containing a list of action names for -which the sort parameters should be saved. If missing or empty then -all actions invoked on the controller are monitored. - =back -All keys that are written in all lower-case name indexes that can be -used for sorting. Each value to such a key can be either a string or a -hash reference containing certain elements. If the value is only a -string then such a hash reference is constructed, and the string is +All other keys can be used for sorting. Each value to such a key can be either +a string or a hash reference containing certain elements. If the value is only +a string then such a hash reference is constructed, and the string is used as the value for the C key. These possible elements are: @@ -311,7 +252,7 @@ reference is the value. =head1 INSTANCE FUNCTIONS -These functions are called on a controller instance. +These functions are called on a C<GetModels> instance and delegating to this plugin. =over 4 @@ -320,15 +261,15 @@ These functions are called on a controller instance. Returns a hash containing the currently active sort parameters. The key C<by> contains the active sort index referring to the -C<%sort_spec> given to L<make_sorted>. +C<%sort_spec> given by the configuration. The key C<dir> is either C<1> or C<0>. =item C<get_current_sort_params> -Returns a hash reference to the sort spec structure given in the call -to L<make_sorted> after normalization (hash reference construction, -applying default parameters etc). +Returns a hash reference to the sort spec structure given in the configuration +after normalization (hash reference construction, applying default parameters +etc). =item C<set_report_generator_sort_options %params> @@ -342,7 +283,7 @@ L<SL::ReportGenerator>: =item 2. it sets the the links for those column headers that are sortable and -=item 3. it adds the C<FORM_PARAMS> fields to the list of variables in +=item 3. it adds the C<form_params> fields to the list of variables in the report generator's export options. =back @@ -365,4 +306,6 @@ Nothing here yet. Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt> +Sven Schöling E<lt>s.schoeling@linet-services.deE<gt> + =cut -- 2.20.1
[% L.sortable_table_header('package_name') %][% L.sortable_table_header('package_name') %] [% L.sortable_table_header('run_at') %] [% L.sortable_table_header('error') %]