diff --git a/.editorconfig b/.editorconfig index 47ae637b..da4df3ae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,8 +10,9 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[{*.yml,package.json}] +[{*.yml,*.ss,*.css,*.json}] indent_size = 2 +indent_style = space # The indent size used in the package.json file cannot be changed: # https://github.com/npm/npm/pull/3180#issuecomment-16336516 diff --git a/client/styles/task-runner.css b/client/styles/task-runner.css new file mode 100644 index 00000000..5dc8f76b --- /dev/null +++ b/client/styles/task-runner.css @@ -0,0 +1,105 @@ +/* This file is manually maintained, it is not generated from SCSS sources */ + +.task__selector { + display: inline-block; + height: 42px; + margin: 0; + opacity: 0.2; + transform: translateX(-203px); + width: 199px; +} + +.task__selector:after { + background-color: #5c5c5c; + content: ' '; + display: inline-block; + height: 42px; + transition: all 0.2s; + width: 199px; +} + +.task__selector:checked:after, +.task__selector:hover:after { + background-color: #000000; +} + +.task__label { + border-bottom: 1px solid #000000; + border-right: 1px solid #000000; + display: inline-block; + font-weight: bold; + margin-left: -208px; + padding: 10px 20px; + text-align: center; + transform: translateY(-15px); + width: 158px; +} + +.task__label:first-child { + margin-left: 0; +} + +.task__tab { + display: none; + margin: 15px; +} + +.task__selector--immediate:checked ~ .task__tab--immediate, +.task__selector--universal:checked ~ .task__tab--universal, +.task__selector--queue-only:checked ~ .task__tab--queue-only { + display: block; +} + +.task__list { + border-left: 1px solid #000000; + border-top: 1px solid #000000; + display: grid; + grid-template-columns: 1fr; + margin-top: 15px; +} + +@media (min-width:992px) { + .task__list { + grid-template-columns: 1fr 1fr; + } +} + +.task__item { + border-bottom: 1px solid #000000; + border-right: 1px solid #000000; + display: flex; + flex-direction: column; + justify-content: space-between; + padding: 15px; + transition: background-color 0.2s; +} + +.task__item:hover { + background-color: #ffffff; +} + +.task__item .description { + margin-bottom: 25px; +} + +.task__button { + border: 1px solid #000000; + border-radius: 5px; + background-color: #f6f7f8; + display: inline-block; + padding: 10px 15px; + text-decoration: none; + transition: background-color 0.2s; +} + +.task__button--queued:hover { + background-color: #ebffeb; +} + +.task__button--immediate:hover { + background-color: #ffebeb; +} + +.task__button + .task__button { + margin-left: 25px; +} diff --git a/composer.json b/composer.json index a88dadbd..e613b14a 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,11 @@ }, "minimum-stability": "dev", "prefer-stable": true, - "extra": [], + "extra": { + "expose": [ + "client/styles" + ] + }, "replace": { "silverstripe/queuedjobs": "self.version" }, diff --git a/src/Controllers/QueuedTaskRunner.php b/src/Controllers/QueuedTaskRunner.php index 6d548b1a..4d48cb8c 100644 --- a/src/Controllers/QueuedTaskRunner.php +++ b/src/Controllers/QueuedTaskRunner.php @@ -7,9 +7,13 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Dev\BuildTask; use SilverStripe\Dev\DebugView; use SilverStripe\Dev\TaskRunner; +use SilverStripe\ORM\ArrayList; +use SilverStripe\View\ArrayData; +use SilverStripe\View\ViewableData; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; use Symbiote\QueuedJobs\Jobs\RunBuildTaskJob; use Symbiote\QueuedJobs\Services\QueuedJobService; @@ -62,6 +66,12 @@ class QueuedTaskRunner extends TaskRunner public function index() { + if (Director::is_cli()) { + // CLI mode - revert to default behaviour + return parent::index(); + } + + $baseUrl = Director::absoluteBaseURL(); $tasks = $this->getTasks(); $blacklist = (array) $this->config()->get('task_blacklist'); @@ -69,78 +79,72 @@ public function index() $backlistedTasks = []; $queuedOnlyTasks = []; - // Web mode - if (!Director::is_cli()) { - $renderer = new DebugView(); - echo $renderer->renderHeader(); - echo $renderer->renderInfo( - "SilverStripe Development Tools: Tasks (QueuedJobs version)", - Director::absoluteBaseURL() - ); - $base = Director::absoluteBaseURL(); - - echo "
"; - echo "

Queueable jobs

\n"; - echo "

By default these jobs will be added the job queue, rather than run immediately

\n"; - echo "
"; - - echo "
"; - echo "

Non-queueable tasks

\n"; - echo "

These tasks shouldn't be added the queuejobs queue, but you can run them immediately.

\n"; - echo "
"; - - echo "
"; - echo "

Queueable only tasks

\n"; - echo "

These tasks must be be added the queuejobs queue, running it immediately is not allowed.

\n"; - echo "
"; - echo $renderer->renderFooter(); + $universalTaskList->push(ArrayData::create([ + 'QueueLink' => $baseUrl . 'dev/tasks/queue/' . $task['segment'], + 'TaskLink' => $baseUrl . 'dev/tasks/' . $task['segment'], + 'Title' => $task['title'], + 'Description' => $task['description'], + ])); + } - // CLI mode - revert to default behaviour - } else { - return parent::index(); + // Non-queueable tasks + $immediateTaskList = ArrayList::create(); + + foreach ($backlistedTasks as $task) { + $immediateTaskList->push(ArrayData::create([ + 'TaskLink' => $baseUrl . 'dev/tasks/' . $task['segment'], + 'Title' => $task['title'], + 'Description' => $task['description'], + ])); } + + // Queue only tasks + $queueOnlyTaskList = ArrayList::create(); + + foreach ($queuedOnlyTasks as $task) { + $queueOnlyTaskList->push(ArrayData::create([ + 'QueueLink' => $baseUrl . 'dev/tasks/queue/' . $task['segment'], + 'Title' => $task['title'], + 'Description' => $task['description'], + ])); + } + + $renderer = DebugView::create(); + $header = $renderer->renderHeader(); + $cssPath = ModuleResourceLoader::singleton()->resolveURL( + 'symbiote/silverstripe-queuedjobs:client/styles/task-runner.css' + ); + + // inject task runner CSS into the heaader + $cssInclude = sprintf('', $cssPath); + $header = str_replace('', $cssInclude . '', $header); + + $data = [ + 'UniversalTasks' => $universalTaskList, + 'ImmediateTasks' => $immediateTaskList, + 'QueueOnlyTasks' => $queueOnlyTaskList, + 'Header' => $header, + 'Footer' => $renderer->renderFooter(), + 'Info' => $renderer->renderInfo('SilverStripe Development Tools: Tasks (QueuedJobs version)', $baseUrl), + ]; + + return ViewableData::create()->renderWith(static::class, $data); } diff --git a/templates/Symbiote/QueuedJobs/Controllers/QueuedTaskRunner.ss b/templates/Symbiote/QueuedJobs/Controllers/QueuedTaskRunner.ss new file mode 100644 index 00000000..4625b2f7 --- /dev/null +++ b/templates/Symbiote/QueuedJobs/Controllers/QueuedTaskRunner.ss @@ -0,0 +1,74 @@ +$Header.RAW +$Info.RAW + +
+ + + + + + + +
+

Queueable tasks

+

By default these jobs will be added the job queue, rather than run immediately.

+ <% if $UniversalTasks.Count > 0 %> +
+ <% loop $UniversalTasks %> +
+
+

$Title

+

$Description

+
+
+ Run immediately + Add to queue +
+
+ <% end_loop %> +
+ <% end_if %> +
+ +
+

Non-queueable tasks

+

These tasks shouldn't be added the queuejobs queue, but you can run them immediately.

+ <% if $ImmediateTasks.Count > 0 %> +
+ <% loop $ImmediateTasks %> +
+
+

$Title

+

$Description

+
+
+ Run immediately +
+
+ <% end_loop %> +
+ <% end_if %> +
+ +
+

Queueable only tasks

+

These tasks must be be added the queuejobs queue, running it immediately is not allowed.

+ <% if $QueueOnlyTasks.Count > 0 %> +
+ <% loop $QueueOnlyTasks %> +
+
+

$Title

+

$Description

+
+
+ Add to queue +
+
+ <% end_loop %> +
+ <% end_if %> +
+
+ +$Footer.RAW