mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 10:41:08 +01:00
Separate daemon task table rendering into a standalone class
Summary: Ref T5402, T6238. Pull this out into a class so the Instances app can embed task views. Test Plan: Loaded `/daemon/` and examined the content in the tables. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T6238, T5402 Differential Revision: https://secure.phabricator.com/D11090
This commit is contained in:
parent
2fe553761a
commit
c2f4ae3502
3 changed files with 87 additions and 52 deletions
|
@ -1565,6 +1565,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementWorkflow.php',
|
||||
'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php',
|
||||
'PhabricatorDaemonTaskGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php',
|
||||
'PhabricatorDaemonTasksTableView' => 'applications/daemon/view/PhabricatorDaemonTasksTableView.php',
|
||||
'PhabricatorDaemonsApplication' => 'applications/daemon/application/PhabricatorDaemonsApplication.php',
|
||||
'PhabricatorDashboard' => 'applications/dashboard/storage/PhabricatorDashboard.php',
|
||||
'PhabricatorDashboardAddPanelController' => 'applications/dashboard/controller/PhabricatorDashboardAddPanelController.php',
|
||||
|
@ -4714,6 +4715,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'PhabricatorDaemonTasksTableView' => 'AphrontView',
|
||||
'PhabricatorDaemonsApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorDashboard' => array(
|
||||
'PhabricatorDashboardDAO',
|
||||
|
|
|
@ -134,9 +134,9 @@ final class PhabricatorDaemonConsoleController
|
|||
$tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'leaseOwner IS NOT NULL');
|
||||
|
||||
$tasks_table = $this->renderTasksTable(
|
||||
$tasks,
|
||||
pht('No tasks are leased by workers.'));
|
||||
$tasks_table = id(new PhabricatorDaemonTasksTableView())
|
||||
->setTasks($tasks)
|
||||
->setNoDataString(pht('No tasks are leased by workers.'));
|
||||
|
||||
$leased_panel = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Leased Tasks'))
|
||||
|
@ -182,7 +182,9 @@ final class PhabricatorDaemonConsoleController
|
|||
$upcoming_panel = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Next In Queue'))
|
||||
->appendChild(
|
||||
$this->renderTasksTable($upcoming, pht('Task queue is empty.')));
|
||||
id(new PhabricatorDaemonTasksTableView())
|
||||
->setTasks($upcoming)
|
||||
->setNoDataString(pht('Task queue is empty.')));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(pht('Console'));
|
||||
|
@ -207,52 +209,4 @@ final class PhabricatorDaemonConsoleController
|
|||
));
|
||||
}
|
||||
|
||||
private function renderTasksTable(array $tasks, $nodata) {
|
||||
$rows = array();
|
||||
foreach ($tasks as $task) {
|
||||
$rows[] = array(
|
||||
$task->getID(),
|
||||
$task->getTaskClass(),
|
||||
$task->getLeaseOwner(),
|
||||
$task->getLeaseExpires()
|
||||
? phutil_format_relative_time($task->getLeaseExpires() - time())
|
||||
: '-',
|
||||
$task->getPriority(),
|
||||
$task->getFailureCount(),
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/daemon/task/'.$task->getID().'/',
|
||||
'class' => 'button small grey',
|
||||
),
|
||||
pht('View Task')),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
pht('ID'),
|
||||
pht('Class'),
|
||||
pht('Owner'),
|
||||
pht('Expires'),
|
||||
pht('Priority'),
|
||||
pht('Failures'),
|
||||
'',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'n',
|
||||
'wide',
|
||||
'',
|
||||
'',
|
||||
'n',
|
||||
'n',
|
||||
'action',
|
||||
));
|
||||
$table->setNoDataString($nodata);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDaemonTasksTableView extends AphrontView {
|
||||
|
||||
private $tasks;
|
||||
private $noDataString;
|
||||
|
||||
public function setTasks(array $tasks) {
|
||||
$this->tasks = $tasks;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTasks() {
|
||||
return $this->tasks;
|
||||
}
|
||||
|
||||
public function setNoDataString($no_data_string) {
|
||||
$this->noDataString = $no_data_string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNoDataString() {
|
||||
return $this->noDataString;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$tasks = $this->getTasks();
|
||||
|
||||
$rows = array();
|
||||
foreach ($tasks as $task) {
|
||||
$rows[] = array(
|
||||
$task->getID(),
|
||||
$task->getTaskClass(),
|
||||
$task->getLeaseOwner(),
|
||||
$task->getLeaseExpires()
|
||||
? phutil_format_relative_time($task->getLeaseExpires() - time())
|
||||
: '-',
|
||||
$task->getPriority(),
|
||||
$task->getFailureCount(),
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/daemon/task/'.$task->getID().'/',
|
||||
'class' => 'button small grey',
|
||||
),
|
||||
pht('View Task')),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
pht('ID'),
|
||||
pht('Class'),
|
||||
pht('Owner'),
|
||||
pht('Expires'),
|
||||
pht('Priority'),
|
||||
pht('Failures'),
|
||||
'',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'n',
|
||||
'wide',
|
||||
'',
|
||||
'',
|
||||
'n',
|
||||
'n',
|
||||
'action',
|
||||
));
|
||||
|
||||
if (strlen($this->getNoDataString())) {
|
||||
$table->setNoDataString($this->getNoDataString());
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue