Skip to content

Commit

Permalink
Merge pull request #312 from silverstripe-terraformers/feature/advanc…
Browse files Browse the repository at this point in the history
…ed-edit-from

NEW: Show job data in descriptor edit form.
  • Loading branch information
emteknetnz authored Sep 14, 2020
2 parents bbc147e + 00cd5bd commit 1d65324
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,17 @@ As a consequence, the work might end up being very fragmented and each chunk may

Some projects do not mind this however, so this solution may still be quite suitable.

## Show job data

In case you need an easy access to additonal job data via CMS for debug purposes enable the `show_job_data` option by including the configuration below.

```yaml
Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor:
show_job_data: true
```
This will add Job data and Messages raw tabs to the job descriptor edit form. Displayed information is read only.
## Contributing
### Translations
Expand Down
38 changes: 38 additions & 0 deletions src/DataObjects/QueuedJobDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand Down Expand Up @@ -132,6 +133,14 @@ class QueuedJobDescriptor extends DataObject
*/
private static $default_sort = 'Created DESC';

/**
* Show job data and raw messages in the edit form
*
* @config
* @var bool
*/
private static $show_job_data = false;

public function requireDefaultRecords()
{
parent::requireDefaultRecords();
Expand Down Expand Up @@ -318,6 +327,21 @@ public function getJobTypeString()
return isset($map[$this->JobType]) ? $map[$this->JobType] : '(Unknown)';
}

/**
* @return string|null
*/
public function getSavedJobDataPreview()
{
return $this->SavedJobData;
}

/**
* @return string|null
*/
public function getMessagesRaw()
{
return $this->SavedJobMessages;
}

/**
* Return a map of numeric JobType values to localisable string representations.
Expand Down Expand Up @@ -507,6 +531,20 @@ public function getCMSFields()
$fields->addFieldToTab('Root.Messages', LiteralField::create('Messages', $this->getMessages()));
}

if ($this->config()->get('show_job_data')) {
$fields->addFieldsToTab('Root.JobData', [
$jobDataPreview = TextareaField::create('SavedJobDataPreview', 'Job Data'),
]);

$jobDataPreview->setReadonly(true);

$fields->addFieldsToTab('Root.MessagesRaw', [
$messagesRaw = TextareaField::create('MessagesRaw', 'Messages Raw'),
]);

$messagesRaw->setReadonly(true);
}

if (Permission::check('ADMIN')) {
return $fields;
}
Expand Down

0 comments on commit 1d65324

Please sign in to comment.