From 986173b1eabb2a367e34f53855daccfdb323a3e1 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Wed, 5 Oct 2022 09:47:16 +1300 Subject: [PATCH] ENH Add a Type and Status filter to Jobs (#385) * ENH Add a Type and Status filter to Jobs * BUG Make QueueJobDescription drop down translatable --- src/DataObjects/QueuedJobDescriptor.php | 42 ++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/DataObjects/QueuedJobDescriptor.php b/src/DataObjects/QueuedJobDescriptor.php index d5256317..cedaaffc 100644 --- a/src/DataObjects/QueuedJobDescriptor.php +++ b/src/DataObjects/QueuedJobDescriptor.php @@ -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; @@ -126,6 +127,8 @@ class QueuedJobDescriptor extends DataObject */ private static $searchable_fields = [ 'JobTitle', + 'JobStatus' => ExactMatchFilter::class, + 'JobType' => ExactMatchFilter::class ]; /** @@ -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', @@ -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'), @@ -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(); @@ -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; + } }