Skip to content

Commit

Permalink
ENH Add a Type and Status filter to Jobs (#385)
Browse files Browse the repository at this point in the history
* ENH Add a Type and Status filter to Jobs

* BUG Make QueueJobDescription drop down translatable
  • Loading branch information
Maxime Rainville authored Oct 4, 2022
1 parent 5a38f94 commit 986173b
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/DataObjects/QueuedJobDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\Filters\ExactMatchFilter;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use Symbiote\QueuedJobs\Services\QueuedJob;
Expand Down Expand Up @@ -126,6 +127,8 @@ class QueuedJobDescriptor extends DataObject
*/
private static $searchable_fields = [
'JobTitle',
'JobStatus' => ExactMatchFilter::class,
'JobType' => ExactMatchFilter::class
];

/**
Expand Down Expand Up @@ -393,9 +396,7 @@ public function getJobStatusValues(): array
public function getCMSFields()
{
$fields = parent::getCMSFields();
$statuses = $this->getJobStatusValues();
$runAs = $fields->fieldByName('Root.Main.RunAsID');

$fields->removeByName([
'Expiry',
'Implementation',
Expand Down Expand Up @@ -432,8 +433,8 @@ public function getCMSFields()
)
),
$jobTitle = TextField::create('JobTitle', 'Title'),
$status = DropdownField::create('JobStatus', 'Status', array_combine($statuses ?? [], $statuses ?? [])),
$jobType = DropdownField::create('JobType', 'Queue type', $this->getJobTypeValues()),
$status = $this->buildJobStatusField(),
$jobType = $this->buildJobTypeField(),
$runAs,
$startAfter = DatetimeField::create('StartAfter', 'Scheduled Start Time'),
HeaderField::create('JobTimelineTitle', 'Timeline'),
Expand Down Expand Up @@ -573,6 +574,31 @@ public function getCMSFields()
return $fields->makeReadonly();
}

/**
* Generate a Dropdown field with the list of possible job
*/
private function buildJobStatusField(): DropdownField
{
$statuses = $this->getJobStatusValues();
return DropdownField::create(
'JobStatus',
_t(__CLASS__ . '.TABLE_STATUS', 'Status'),
array_combine($statuses ?? [], $statuses ?? [])
);
}

/**
* Generate a drop down field with a list of possible job types
*/
private function buildJobTypeField(): DropdownField
{
return DropdownField::create(
'JobType',
_t(__CLASS__ . '.JOB_TYPE', 'Job Type'),
$this->getJobTypeValues()
);
}

private function getWorkerExpiry()
{
$now = DBDatetime::now();
Expand All @@ -585,4 +611,12 @@ private function getWorkerExpiry()

return $time->getTimestamp() - $now->getTimestamp();
}

public function scaffoldSearchFields($_params = null)
{
$fields = parent::scaffoldSearchFields($_params);
$fields->push($this->buildJobStatusField()->setEmptyString(''));
$fields->push($this->buildJobTypeField()->setEmptyString(''));
return $fields;
}
}

0 comments on commit 986173b

Please sign in to comment.