Skip to content

Commit

Permalink
NEW: Task runner better UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Jun 8, 2020
1 parent 817b1f5 commit 30e9164
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 67 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
indent_size = 2
[{*.yml,*.ss,*.css,*.json}]
indent_size = 4
indent_style = space

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
58 changes: 58 additions & 0 deletions client/styles/task-runner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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__panel {
display: none;
}

.task__selector--immediate:checked ~ .task__panel--immediate,
.task__selector--universal:checked ~ .task__panel--universal,
.task__selector--queue-only:checked ~ .task__panel--queue-only {
display: block;
}

.task__button--notice:hover {
background-color: #ebffeb;
}

.task__button + .task__button {
margin-left: 25px;
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": [],
"extra": {
"expose": [
"client/styles"
]
},
"replace": {
"silverstripe/queuedjobs": "self.version"
},
Expand Down
138 changes: 74 additions & 64 deletions src/Controllers/QueuedTaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,85 +66,91 @@ 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');
$queuedOnlyList = (array) $this->config()->get('queued_only_tasks');
$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 "<div class=\"options\">";
echo "<h2>Queueable jobs</h2>\n";
echo "<p>By default these jobs will be added the job queue, rather than run immediately</p>\n";
echo "<ul>";
foreach ($tasks as $task) {
if (in_array($task['class'], $blacklist)) {
$backlistedTasks[] = $task;

continue;
}
// universal tasks
$universalTaskList = ArrayList::create();

if (in_array($task['class'], $queuedOnlyList)) {
$queuedOnlyTasks[] = $task;
foreach ($tasks as $task) {
if (in_array($task['class'], $blacklist)) {
$backlistedTasks[] = $task;

continue;
}
continue;
}

$queueLink = $base . "dev/tasks/queue/" . $task['segment'];
$immediateLink = $base . "dev/tasks/" . $task['segment'];
if (in_array($task['class'], $queuedOnlyList)) {
$queuedOnlyTasks[] = $task;

echo "<li><p>";
echo "<a href=\"$queueLink\">" . $task['title'] . "</a> <a style=\"font-size: 80%; padding-left: 20px\""
. " href=\"$immediateLink\">[run immediately]</a><br />";
echo "<span class=\"description\">" . $task['description'] . "</span>";
echo "</p></li>\n";
}
echo "</ul></div>";

echo "<div class=\"options\">";
echo "<h2>Non-queueable tasks</h2>\n";
echo "<p>These tasks shouldn't be added the queuejobs queue, but you can run them immediately.</p>\n";
echo "<ul>";
foreach ($backlistedTasks as $task) {
$immediateLink = $base . "dev/tasks/" . $task['segment'];

echo "<li><p>";
echo "<a href=\"$immediateLink\">" . $task['title'] . "</a><br />";
echo "<span class=\"description\">" . $task['description'] . "</span>";
echo "</p></li>\n";
continue;
}
echo "</ul></div>";

echo "<div class=\"options\">";
echo "<h2>Queueable only tasks</h2>\n";
echo "<p>These tasks must be be added the queuejobs queue, running it immediately is not allowed.</p>\n";
echo "<ul>";
foreach ($queuedOnlyTasks as $task) {
$queueLink = $base . "dev/tasks/queue/" . $task['segment'];

echo "<li><p>";
echo "<a href=\"$queueLink\">" . $task['title'] . "</a><br />";
echo "<span class=\"description\">" . $task['description'] . "</span>";
echo "</p></li>\n";
}
echo "</ul></div>";

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();

$cssIncludes = [
'silverstripe/framework:client/styles/task-runner.css',
'symbiote/silverstripe-queuedjobs:client/styles/task-runner.css',
];

foreach ($cssIncludes as $cssResource) {
$cssPath = ModuleResourceLoader::singleton()->resolveURL($cssResource);

// inject CSS into the heaader
$cssInclude = sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssPath);
$header = str_replace('</head>', $cssInclude . '</head>', $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);
}


Expand Down
74 changes: 74 additions & 0 deletions templates/Symbiote/QueuedJobs/Controllers/QueuedTaskRunner.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
$Header.RAW
$Info.RAW

<div class="task">
<label class="task__label" for="tab-universal-tasks">Queueable task</label>
<input type="radio" id="tab-universal-tasks" class="task__selector task__selector--universal" name="task__selector" checked="checked" />
<label class="task__label" for="tab-immediate-tasks">Non-queueable tasks</label>
<input type="radio" id="tab-immediate-tasks" class="task__selector task__selector--immediate" name="task__selector" />
<label class="task__label" for="tab-queue-only-tasks">Queueable only tasks</label>
<input type="radio" id="tab-queue-only-tasks" class="task__selector task__selector--queue-only" name="task__selector" />

<div class="task__panel task__panel--universal">
<h2>Queueable tasks</h2>
<p>By default these jobs will be added the job queue, rather than run immediately.</p>
<% if $UniversalTasks.Count > 0 %>
<div class="task__list">
<% loop $UniversalTasks %>
<div class="task__item">
<div>
<h3>$Title</h3>
<p class="description">$Description</p>
</div>
<div>
<a href="{$TaskLink.ATT}" class="task__button task__button--warning">Run immediately</a>
<a href="{$QueueLink.ATT}" class="task__button task__button--notice">Add to queue</a>
</div>
</div>
<% end_loop %>
</div>
<% end_if %>
</div>

<div class="task__panel task__panel--immediate">
<h2>Non-queueable tasks</h2>
<p>These tasks shouldn't be added the queuejobs queue, but you can run them immediately.</p>
<% if $ImmediateTasks.Count > 0 %>
<div class="task__list">
<% loop $ImmediateTasks %>
<div class="task__item">
<div>
<h3>$Title</h3>
<p class="description">$Description</p>
</div>
<div>
<a href="{$TaskLink.ATT}" class="task__button task__button--warning">Run immediately</a>
</div>
</div>
<% end_loop %>
</div>
<% end_if %>
</div>

<div class="task__panel task__panel--queue-only">
<h2>Queueable only tasks</h2>
<p>These tasks must be be added the queuejobs queue, running it immediately is not allowed.</p>
<% if $QueueOnlyTasks.Count > 0 %>
<div class="task__list">
<% loop $QueueOnlyTasks %>
<div class="task__item">
<div>
<h3>$Title</h3>
<p class="description">$Description</p>
</div>
<div>
<a href="{$QueueLink.ATT}" class="task__button task__button--notice">Add to queue</a>
</div>
</div>
<% end_loop %>
</div>
<% end_if %>
</div>
</div>

$Footer.RAW

0 comments on commit 30e9164

Please sign in to comment.