Revision 783342e0
Von Sven Schöling vor etwa 11 Jahren hinzugefügt
SL/Controller/BackgroundJob.pm | ||
---|---|---|
6 | 6 |
|
7 | 7 |
use SL::BackgroundJob::Base; |
8 | 8 |
use SL::Controller::Helper::GetModels; |
9 |
use SL::Controller::Helper::Paginated; |
|
10 |
use SL::Controller::Helper::Sorted; |
|
11 | 9 |
use SL::DB::BackgroundJob; |
12 | 10 |
use SL::Helper::Flash; |
13 | 11 |
use SL::Locale::String; |
... | ... | |
16 | 14 |
use Rose::Object::MakeMethods::Generic |
17 | 15 |
( |
18 | 16 |
scalar => [ qw(background_job) ], |
19 |
'scalar --get_set_init' => [ qw(task_server back_to) ], |
|
17 |
'scalar --get_set_init' => [ qw(task_server back_to models) ],
|
|
20 | 18 |
); |
21 | 19 |
|
22 | 20 |
__PACKAGE__->run_before('check_auth'); |
23 | 21 |
__PACKAGE__->run_before('check_task_server'); |
24 | 22 |
__PACKAGE__->run_before('load_background_job', only => [ qw(edit update destroy execute) ]); |
25 | 23 |
|
26 |
__PACKAGE__->make_paginated(ONLY => [ qw(list) ]); |
|
27 |
|
|
28 |
__PACKAGE__->make_sorted( |
|
29 |
ONLY => [ qw(list) ], |
|
30 |
|
|
31 |
package_name => t8('Package name'), |
|
32 |
type => t8('Execution type'), |
|
33 |
active => t8('Active'), |
|
34 |
cron_spec => t8('Execution schedule'), |
|
35 |
last_run_at => t8('Last run at'), |
|
36 |
next_run_at => t8('Next run at'), |
|
37 |
); |
|
38 |
|
|
39 | 24 |
# |
40 | 25 |
# actions |
41 | 26 |
# |
... | ... | |
45 | 30 |
|
46 | 31 |
$self->render('background_job/list', |
47 | 32 |
title => $::locale->text('Background jobs'), |
48 |
BACKGROUND_JOBS => $self->get_models); |
|
33 |
BACKGROUND_JOBS => $self->models->get, |
|
34 |
MODELS => $self->models); |
|
49 | 35 |
} |
50 | 36 |
|
51 | 37 |
sub action_new { |
... | ... | |
169 | 155 |
return $::form->{back_to} || $self->url_for(action => 'list'); |
170 | 156 |
} |
171 | 157 |
|
158 |
sub init_models { |
|
159 |
SL::Controller::Helper::GetModels->new( |
|
160 |
controller => $_[0], |
|
161 |
model => 'BackgroundJob', |
|
162 |
filtered => 0, |
|
163 |
sorted => { |
|
164 |
package_name => t8('Package name'), |
|
165 |
type => t8('Execution type'), |
|
166 |
active => t8('Active'), |
|
167 |
cron_spec => t8('Execution schedule'), |
|
168 |
last_run_at => t8('Last run at'), |
|
169 |
next_run_at => t8('Next run at'), |
|
170 |
}, |
|
171 |
); |
|
172 |
} |
|
173 |
|
|
172 | 174 |
1; |
SL/Controller/Helper/GetModels.pm | ||
---|---|---|
63 | 63 |
$self->paginated->get_current_paginate_params(%params); |
64 | 64 |
} |
65 | 65 |
|
66 |
sub get_sort_spec { |
|
67 |
my ($self) = @_; |
|
68 |
|
|
69 |
$self->sorted->specs; |
|
70 |
} |
|
71 |
|
|
72 |
sub get_current_sort_params { |
|
73 |
my ($self) = @_; |
|
74 |
|
|
75 |
$self->sorted->read_params; |
|
76 |
} |
|
77 |
|
|
66 | 78 |
sub init { |
67 | 79 |
my ($self, %params) = @_; |
68 | 80 |
|
SL/Template/Plugin/L.pm | ||
---|---|---|
443 | 443 |
my ($self, $by, %params) = _hashify(2, @_); |
444 | 444 |
|
445 | 445 |
my $controller = $self->{CONTEXT}->stash->get('SELF'); |
446 |
my $sort_spec = $controller->get_sort_spec; |
|
446 |
my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS'); |
|
447 |
my $sort_spec = $models->get_sort_spec; |
|
447 | 448 |
my $by_spec = $sort_spec->{$by}; |
448 |
my %current_sort_params = $controller->get_current_sort_params;
|
|
449 |
my %current_sort_params = $models->get_current_sort_params;
|
|
449 | 450 |
my ($image, $new_dir) = ('', $current_sort_params{dir}); |
450 | 451 |
my $title = delete($params{title}) || $::locale->text($by_spec->{title}); |
451 | 452 |
|
452 |
if ($current_sort_params{by} eq $by) { |
|
453 |
my $current_dir = $current_sort_params{dir} ? 'up' : 'down'; |
|
453 |
if ($current_sort_params{sort_by} eq $by) {
|
|
454 |
my $current_dir = $current_sort_params{sort_dir} ? 'up' : 'down';
|
|
454 | 455 |
$image = '<img border="0" src="image/' . $current_dir . '.png">'; |
455 |
$new_dir = 1 - ($current_sort_params{dir} || 0); |
|
456 |
$new_dir = 1 - ($current_sort_params{sort_dir} || 0);
|
|
456 | 457 |
} |
457 | 458 |
|
458 |
$params{ $sort_spec->{FORM_PARAMS}->[0] } = $by;
|
|
459 |
$params{ $sort_spec->{FORM_PARAMS}->[1] } = ($new_dir ? '1' : '0');
|
|
459 |
$params{ $models->sorted->form_params->[0] } = $by;
|
|
460 |
$params{ $models->sorted->form_params->[1] } = ($new_dir ? '1' : '0');
|
|
460 | 461 |
|
461 |
return '<a href="' . $controller->get_callback(%params) . '">' . _H($title) . $image . '</a>';
|
|
462 |
return '<a href="' . $models->get_callback(%params) . '">' . _H($title) . $image . '</a>';
|
|
462 | 463 |
} |
463 | 464 |
|
464 | 465 |
sub paginate_controls { |
465 | 466 |
my ($self, %params) = _hashify(1, @_); |
466 | 467 |
|
467 | 468 |
my $controller = $self->{CONTEXT}->stash->get('SELF'); |
468 |
my $pager = $params{models}->paginated; |
|
469 |
my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS'); |
|
470 |
my $pager = $models->paginated; |
|
469 | 471 |
# my $paginate_spec = $controller->get_paginate_spec; |
470 | 472 |
|
471 |
my %paginate_params = $params{models}->get_paginate_args;
|
|
473 |
my %paginate_params = $models->get_paginate_args;
|
|
472 | 474 |
|
473 | 475 |
my %template_params = ( |
474 | 476 |
pages => \%paginate_params, |
Auch abrufbar als: Unified diff
BackgroundJob models