From: Sven Schöling Date: Wed, 18 Sep 2013 14:44:42 +0000 (+0200) Subject: BackgroundJob models X-Git-Tag: release-3.1.0beta1~45 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=783342e0eebf05742b2c4649aee747a4cb48eb5a;p=kivitendo-erp.git BackgroundJob models --- diff --git a/SL/Controller/BackgroundJob.pm b/SL/Controller/BackgroundJob.pm index 5f937d536..f0a1722f2 100644 --- a/SL/Controller/BackgroundJob.pm +++ b/SL/Controller/BackgroundJob.pm @@ -6,8 +6,6 @@ use parent qw(SL::Controller::Base); use SL::BackgroundJob::Base; use SL::Controller::Helper::GetModels; -use SL::Controller::Helper::Paginated; -use SL::Controller::Helper::Sorted; use SL::DB::BackgroundJob; use SL::Helper::Flash; use SL::Locale::String; @@ -16,26 +14,13 @@ use SL::System::TaskServer; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(background_job) ], - 'scalar --get_set_init' => [ qw(task_server back_to) ], + 'scalar --get_set_init' => [ qw(task_server back_to models) ], ); __PACKAGE__->run_before('check_auth'); __PACKAGE__->run_before('check_task_server'); __PACKAGE__->run_before('load_background_job', only => [ qw(edit update destroy execute) ]); -__PACKAGE__->make_paginated(ONLY => [ qw(list) ]); - -__PACKAGE__->make_sorted( - ONLY => [ qw(list) ], - - package_name => t8('Package name'), - type => t8('Execution type'), - active => t8('Active'), - cron_spec => t8('Execution schedule'), - last_run_at => t8('Last run at'), - next_run_at => t8('Next run at'), -); - # # actions # @@ -45,7 +30,8 @@ sub action_list { $self->render('background_job/list', title => $::locale->text('Background jobs'), - BACKGROUND_JOBS => $self->get_models); + BACKGROUND_JOBS => $self->models->get, + MODELS => $self->models); } sub action_new { @@ -169,4 +155,20 @@ sub init_back_to { return $::form->{back_to} || $self->url_for(action => 'list'); } +sub init_models { + SL::Controller::Helper::GetModels->new( + controller => $_[0], + model => 'BackgroundJob', + filtered => 0, + sorted => { + package_name => t8('Package name'), + type => t8('Execution type'), + active => t8('Active'), + cron_spec => t8('Execution schedule'), + last_run_at => t8('Last run at'), + next_run_at => t8('Next run at'), + }, + ); +} + 1; diff --git a/SL/Controller/Helper/GetModels.pm b/SL/Controller/Helper/GetModels.pm index a4cd973b8..0dad791ec 100644 --- a/SL/Controller/Helper/GetModels.pm +++ b/SL/Controller/Helper/GetModels.pm @@ -63,6 +63,18 @@ sub get_paginate_args { $self->paginated->get_current_paginate_params(%params); } +sub get_sort_spec { + my ($self) = @_; + + $self->sorted->specs; +} + +sub get_current_sort_params { + my ($self) = @_; + + $self->sorted->read_params; +} + sub init { my ($self, %params) = @_; diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 7c5357303..31d9a8f64 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -443,32 +443,34 @@ sub sortable_table_header { my ($self, $by, %params) = _hashify(2, @_); my $controller = $self->{CONTEXT}->stash->get('SELF'); - my $sort_spec = $controller->get_sort_spec; + my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS'); + my $sort_spec = $models->get_sort_spec; my $by_spec = $sort_spec->{$by}; - my %current_sort_params = $controller->get_current_sort_params; + my %current_sort_params = $models->get_current_sort_params; my ($image, $new_dir) = ('', $current_sort_params{dir}); my $title = delete($params{title}) || $::locale->text($by_spec->{title}); - if ($current_sort_params{by} eq $by) { - my $current_dir = $current_sort_params{dir} ? 'up' : 'down'; + if ($current_sort_params{sort_by} eq $by) { + my $current_dir = $current_sort_params{sort_dir} ? 'up' : 'down'; $image = ''; - $new_dir = 1 - ($current_sort_params{dir} || 0); + $new_dir = 1 - ($current_sort_params{sort_dir} || 0); } - $params{ $sort_spec->{FORM_PARAMS}->[0] } = $by; - $params{ $sort_spec->{FORM_PARAMS}->[1] } = ($new_dir ? '1' : '0'); + $params{ $models->sorted->form_params->[0] } = $by; + $params{ $models->sorted->form_params->[1] } = ($new_dir ? '1' : '0'); - return '' . _H($title) . $image . ''; + return '' . _H($title) . $image . ''; } sub paginate_controls { my ($self, %params) = _hashify(1, @_); my $controller = $self->{CONTEXT}->stash->get('SELF'); - my $pager = $params{models}->paginated; + my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS'); + my $pager = $models->paginated; # my $paginate_spec = $controller->get_paginate_spec; - my %paginate_params = $params{models}->get_paginate_args; + my %paginate_params = $models->get_paginate_args; my %template_params = ( pages => \%paginate_params,