From c2f4ae3502d8bb8f627ba7fa8feb12ce4fec49aa Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 30 Dec 2014 10:00:06 -0800 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../PhabricatorDaemonConsoleController.php | 58 ++------------ .../view/PhabricatorDaemonTasksTableView.php | 79 +++++++++++++++++++ 3 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 src/applications/daemon/view/PhabricatorDaemonTasksTableView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 19b88ebcc6..786da18b2d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php b/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php index 1c7a4cf27a..98fe5ecc87 100644 --- a/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php +++ b/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php @@ -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; - } - } diff --git a/src/applications/daemon/view/PhabricatorDaemonTasksTableView.php b/src/applications/daemon/view/PhabricatorDaemonTasksTableView.php new file mode 100644 index 0000000000..4fded0b68a --- /dev/null +++ b/src/applications/daemon/view/PhabricatorDaemonTasksTableView.php @@ -0,0 +1,79 @@ +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; + } + +}