]> wagnertech.de Git - mfinanz.git/blob - SL/Controller/BackgroundJobHistory.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / Controller / BackgroundJobHistory.pm
1 package SL::Controller::BackgroundJobHistory;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Controller::Helper::GetModels;
8 use SL::DB::BackgroundJobHistory;
9 use SL::Helper::Flash;
10 use SL::Locale::String;
11 use SL::System::TaskServer;
12
13 use Rose::Object::MakeMethods::Generic
14 (
15   scalar                  => [ qw(history filter_summary) ],
16   'scalar --get_set_init' => [ qw(task_server models) ],
17 );
18
19 __PACKAGE__->run_before('check_auth');
20 __PACKAGE__->run_before('add_stylesheet');
21 __PACKAGE__->run_before('check_task_server');
22
23 #
24 # actions
25 #
26
27 sub action_list {
28   my ($self) = @_;
29
30   $self->make_filter_summary;
31
32   $self->setup_list_action_bar;
33   $self->render('background_job_history/list',
34                 title   => $::locale->text('Background job history'),
35                 ENTRIES => $self->models->get,
36                 MODELS  => $self->models);
37 }
38
39 sub action_show {
40   my ($self) = @_;
41
42   my $back_to = $::form->{back_to} || $self->url_for(action => 'list');
43
44   $self->history(SL::DB::BackgroundJobHistory->new(id => $::form->{id})->load);
45   $self->setup_show_action_bar;
46   $self->render('background_job_history/show',
47                 title   => $::locale->text('View background job execution result'),
48                 back_to => $back_to);
49 }
50
51 #
52 # filters
53 #
54
55 sub check_auth {
56   $::auth->assert('admin');
57 }
58
59 #
60 # helpers
61 #
62
63 sub init_task_server {
64   return SL::System::TaskServer->new;
65 }
66
67 sub check_task_server {
68   my ($self) = @_;
69   flash('warning', $::locale->text('The task server does not appear to be running.')) if !$self->task_server->is_running;
70 }
71
72 sub add_stylesheet {
73   $::request->{layout}->use_stylesheet('background_jobs.css');
74 }
75
76 sub make_filter_summary {
77   my ($self)  = @_;
78
79   my $filter  = $::form->{filter} || {};
80   my @filters = (
81     [ "package_name:substr::ilike", $::locale->text('Package name')                                ],
82     [ "result:substr::ilike",       $::locale->text('Result')                                      ],
83     [ "error:substr::ilike",        $::locale->text('Error')                                       ],
84     [ "run_at:date::ge",            $::locale->text('Run at') . " " . $::locale->text('From Date') ],
85     [ "run_at:date::le",            $::locale->text('Run at') . " " . $::locale->text('To Date')   ],
86   );
87
88   my @filter_strings = grep { $_ }
89                        map  { $filter->{ $_->[0] } ? $_->[1] . ' ' . $filter->{ $_->[0] } : undef }
90                        @filters;
91
92   my %status = (
93     failure  => $::locale->text('failed'),
94     success  => $::locale->text('succeeded'),
95   );
96   push @filter_strings, $status{ $filter->{'status:eq_ignore_empty'} } if $filter->{'status:eq_ignore_empty'};
97
98   $self->filter_summary(join(', ', @filter_strings));
99 }
100
101 sub init_models {
102   my ($self) = @_;
103
104   SL::Controller::Helper::GetModels->new(
105     controller => $self,
106     sorted => {
107       package_name => t8('Package name'),
108       description  => t8('Description'),
109       run_at       => t8('Run at'),
110       status       => t8('Execution status'),
111       result       => t8('Result'),
112       error        => t8('Error'),
113     },
114   );
115 }
116
117 sub setup_list_action_bar {
118   my ($self) = @_;
119
120   for my $bar ($::request->layout->get('actionbar')) {
121     $bar->add(
122       link => [
123         t8('Server control'),
124         link => $self->url_for(controller => 'TaskServer', action => 'show'),
125       ],
126       link => [
127         t8('List of jobs'),
128         link => $self->url_for(controller => 'BackgroundJob', action => 'list'),
129       ],
130     );
131   }
132 }
133
134 sub setup_show_action_bar {
135   my ($self) = @_;
136
137   for my $bar ($::request->layout->get('actionbar')) {
138     $bar->add(
139       link => [
140         t8('Back'),
141         link => $self->url_for(action => 'list'),
142       ],
143     );
144   }
145 }
146
147 1;