From 2c597c2df21ae8025159665f39845ccfe9b7dabd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 30 Mar 2015 11:32:55 +0200 Subject: [PATCH] BackgroundJobs optional als json ausliefern --- SL/Controller/BackgroundJob.pm | 12 +++++++++++- SL/Controller/CsvImport.pm | 7 ++++++- SL/DB/BackgroundJob.pm | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SL/Controller/BackgroundJob.pm b/SL/Controller/BackgroundJob.pm index b68829797..3e89ecc02 100644 --- a/SL/Controller/BackgroundJob.pm +++ b/SL/Controller/BackgroundJob.pm @@ -19,7 +19,7 @@ use Rose::Object::MakeMethods::Generic __PACKAGE__->run_before('check_auth'); __PACKAGE__->run_before('check_task_server'); -__PACKAGE__->run_before('load_background_job', only => [ qw(edit update destroy execute) ]); +__PACKAGE__->run_before('load_background_job', only => [ qw(edit update destroy execute show) ]); # # actions @@ -51,6 +51,16 @@ sub action_edit { JOB_CLASSES => [ SL::BackgroundJob::Base->get_known_job_classes ]); } +sub action_show { + my ($self) = @_; + + if ($::request->type eq 'json') { + $self->render(\ SL::JSON::to_json($self->background_job->as_tree), { type => 'json' }); + } else { + $self->action_edit; + } +} + sub action_create { my ($self) = @_; diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 3cd0da24f..19922109f 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -17,6 +17,7 @@ use SL::Controller::CsvImport::Inventory; use SL::Controller::CsvImport::Shipto; use SL::Controller::CsvImport::Project; use SL::Controller::CsvImport::Order; +use SL::JSON; use SL::BackgroundJob::CsvImport; use SL::System::TaskServer; @@ -318,7 +319,11 @@ sub test_and_import_deferred { $self->{deferred} = 1; - $self->render_inputs; + if ($::request->type eq 'json') { + $self->render(\ SL::JSON::to_json($self->{background_job}->as_tree), { type => 'json' }) + } else { + $self->render_inputs; + } } sub test_and_import { diff --git a/SL/DB/BackgroundJob.pm b/SL/DB/BackgroundJob.pm index b567d364e..10e319ba3 100644 --- a/SL/DB/BackgroundJob.pm +++ b/SL/DB/BackgroundJob.pm @@ -5,6 +5,8 @@ use strict; use DateTime::Event::Cron; use English qw(-no_match_vars); +use Rose::DB::Object::Helpers qw(as_tree); + use SL::DB::MetaSetup::BackgroundJob; use SL::DB::Manager::BackgroundJob; -- 2.20.1