kivitendo/SL/Controller/BackgroundJobHistory.pm @ 1df575c4
23a8d2c0 | Moritz Bunkus | package SL::Controller::BackgroundJobHistory;
|
||
use strict;
|
||||
use parent qw(SL::Controller::Base);
|
||||
35f3e56a | Moritz Bunkus | use SL::Controller::Helper::GetModels;
|
||
23a8d2c0 | Moritz Bunkus | use SL::DB::BackgroundJobHistory;
|
||
use SL::Helper::Flash;
|
||||
3e52fa98 | Moritz Bunkus | use SL::Locale::String;
|
||
23a8d2c0 | Moritz Bunkus | use SL::System::TaskServer;
|
||
use Rose::Object::MakeMethods::Generic
|
||||
(
|
||||
9d015fd3 | Sven Schöling | scalar => [ qw(history filter_summary) ],
|
||
'scalar --get_set_init' => [ qw(task_server models) ],
|
||||
23a8d2c0 | Moritz Bunkus | );
|
||
__PACKAGE__->run_before('check_auth');
|
||||
__PACKAGE__->run_before('add_stylesheet');
|
||||
__PACKAGE__->run_before('check_task_server');
|
||||
#
|
||||
# actions
|
||||
#
|
||||
sub action_list {
|
||||
my ($self) = @_;
|
||||
6c5cdbeb | Moritz Bunkus | $self->make_filter_summary;
|
||
23a8d2c0 | Moritz Bunkus | $self->render('background_job_history/list',
|
||
title => $::locale->text('Background job history'),
|
||||
9d015fd3 | Sven Schöling | ENTRIES => $self->models->get,
|
||
MODELS => $self->models);
|
||||
23a8d2c0 | Moritz Bunkus | }
|
||
sub action_show {
|
||||
my ($self) = @_;
|
||||
my $back_to = $::form->{back_to} || $self->url_for(action => 'list');
|
||||
$self->history(SL::DB::BackgroundJobHistory->new(id => $::form->{id})->load);
|
||||
$self->render('background_job_history/show',
|
||||
title => $::locale->text('View background job execution result'),
|
||||
back_to => $back_to);
|
||||
}
|
||||
#
|
||||
# filters
|
||||
#
|
||||
sub check_auth {
|
||||
$::auth->assert('admin');
|
||||
}
|
||||
#
|
||||
# helpers
|
||||
#
|
||||
sub init_task_server {
|
||||
return SL::System::TaskServer->new;
|
||||
}
|
||||
sub check_task_server {
|
||||
my ($self) = @_;
|
||||
flash('warning', $::locale->text('The task server does not appear to be running.')) if !$self->task_server->is_running;
|
||||
}
|
||||
sub add_stylesheet {
|
||||
7e601869 | Moritz Bunkus | $::request->{layout}->use_stylesheet('background_jobs.css');
|
||
23a8d2c0 | Moritz Bunkus | }
|
||
6c5cdbeb | Moritz Bunkus | sub make_filter_summary {
|
||
my ($self) = @_;
|
||||
my $filter = $::form->{filter} || {};
|
||||
my @filters = (
|
||||
[ "package_name:substr::ilike", $::locale->text('Package name') ],
|
||||
[ "result:substr::ilike", $::locale->text('Result') ],
|
||||
[ "error:substr::ilike", $::locale->text('Error') ],
|
||||
[ "run_at:date::ge", $::locale->text('Run at') . " " . $::locale->text('From Date') ],
|
||||
[ "run_at:date::le", $::locale->text('Run at') . " " . $::locale->text('To Date') ],
|
||||
);
|
||||
my @filter_strings = grep { $_ }
|
||||
map { $filter->{ $_->[0] } ? $_->[1] . ' ' . $filter->{ $_->[0] } : undef }
|
||||
@filters;
|
||||
my %status = (
|
||||
b8451c6b | Moritz Bunkus | failure => $::locale->text('failed'),
|
||
6c5cdbeb | Moritz Bunkus | success => $::locale->text('succeeded'),
|
||
);
|
||||
push @filter_strings, $status{ $filter->{'status:eq_ignore_empty'} } if $filter->{'status:eq_ignore_empty'};
|
||||
$self->filter_summary(join(', ', @filter_strings));
|
||||
}
|
||||
9d015fd3 | Sven Schöling | sub init_models {
|
||
my ($self) = @_;
|
||||
SL::Controller::Helper::GetModels->new(
|
||||
controller => $self,
|
||||
sorted => {
|
||||
package_name => t8('Package name'),
|
||||
run_at => t8('Run at'),
|
||||
status => t8('Execution status'),
|
||||
result => t8('Result'),
|
||||
error => t8('Error'),
|
||||
},
|
||||
);
|
||||
}
|
||||
23a8d2c0 | Moritz Bunkus | 1;
|