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;
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
#
$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 {
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;
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 = '<img border="0" src="image/' . $current_dir . '.png">';
- $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 '<a href="' . $controller->get_callback(%params) . '">' . _H($title) . $image . '</a>';
+ return '<a href="' . $models->get_callback(%params) . '">' . _H($title) . $image . '</a>';
}
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,