diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 89c5a2be53..fb486a2134 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1443,6 +1443,8 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php', 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php', 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', + 'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php', + 'PhabricatorDashboardPanelRenderingEngine' => 'applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php', 'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php', 'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php', 'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php', @@ -4253,6 +4255,8 @@ phutil_register_library_map(array( 1 => 'PhabricatorApplicationSearchResultsControllerInterface', ), 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController', + 'PhabricatorDashboardPanelRenderingEngine' => 'Phobject', 'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/dashboard/application/PhabricatorApplicationDashboard.php b/src/applications/dashboard/application/PhabricatorApplicationDashboard.php index 97bfd47375..c4f5d05fbc 100644 --- a/src/applications/dashboard/application/PhabricatorApplicationDashboard.php +++ b/src/applications/dashboard/application/PhabricatorApplicationDashboard.php @@ -29,6 +29,7 @@ final class PhabricatorApplicationDashboard extends PhabricatorApplication { => 'PhabricatorDashboardPanelListController', 'create/' => 'PhabricatorDashboardPanelCreateController', 'edit/(?:(?P\d+)/)?' => 'PhabricatorDashboardPanelEditController', + 'render/(?P\d+)/' => 'PhabricatorDashboardPanelRenderController', ), ), ); diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php new file mode 100644 index 0000000000..501ab16fc9 --- /dev/null +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php @@ -0,0 +1,53 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $panel = id(new PhabricatorDashboardPanelQuery()) + ->setViewer($viewer) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$panel) { + return new Aphront404Response(); + } + + $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine()) + ->setViewer($viewer) + ->setPanel($panel) + ->renderPanel(); + + if ($request->isAjax()) { + return id(new AphrontAjaxResponse()) + ->setContent( + array( + 'panelMarkup' => $rendered_panel, + )); + } + + $crumbs = $this->buildApplicationCrumbs() + ->addTextCrumb(pht('Panels'), $this->getApplicationURI('panel/')) + ->addTextCrumb($panel->getMonogram(), '/'.$panel->getMonogram()) + ->addTextCrumb(pht('Standalone View')); + + return $this->buildApplicationPage( + array( + $crumbs, + $rendered_panel, + ), + array( + 'title' => array(pht('Panel'), $panel->getName()), + 'device' => true, + )); + } + +} diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php index 737e4ca04c..a3a63a0965 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php @@ -38,11 +38,17 @@ final class PhabricatorDashboardPanelViewController ->setHeader($header) ->addPropertyList($properties); + $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine()) + ->setViewer($viewer) + ->setPanel($panel) + ->renderPanel(); + return $this->buildApplicationPage( array( $crumbs, $box, $timeline, + $rendered_panel, ), array( 'title' => $title, @@ -80,6 +86,12 @@ final class PhabricatorDashboardPanelViewController ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('View Standalone')) + ->setIcon('preview') + ->setHref($this->getApplicationURI("panel/render/{$id}/"))); + return $actions; } diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php new file mode 100644 index 0000000000..79df752b0d --- /dev/null +++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php @@ -0,0 +1,47 @@ +viewer = $viewer; + return $this; + } + + public function setPanel(PhabricatorDashboardPanel $panel) { + $this->panel = $panel; + return $this; + } + + public function renderPanel() { + $panel = $this->panel; + $viewer = $this->viewer; + + if (!$panel) { + return $this->renderErrorPanel( + pht('Missing Panel'), + pht('This panel does not exist.')); + } + + $panel_type = $panel->getImplementation(); + if (!$panel_type) { + return $this->renderErrorPanel( + $panel->getName(), + pht( + 'This panel has type "%s", but that panel type is not known to '. + 'Phabricator.', + $panel->getPanelType())); + } + + return $panel_type->renderPanel($viewer, $panel); + } + + private function renderErrorPanel($title, $body) { + return id(new PHUIObjectBoxView()) + ->setHeaderText($title) + ->setFormErrors(array($body)); + } + +} diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php index 821384cd83..d86f0ab2a7 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php @@ -39,4 +39,13 @@ abstract class PhabricatorDashboardPanelType extends Phobject { return $types; } + public function renderPanel( + PhabricatorUser $viewer, + PhabricatorDashboardPanel $panel) { + + return id(new PHUIObjectBoxView()) + ->setHeaderText($panel->getName()) + ->appendChild(pht('TODO: Panel content goes here.')); + } + }