diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1443,6 +1443,8 @@ '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 @@ 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 --- a/src/applications/dashboard/application/PhabricatorApplicationDashboard.php +++ b/src/applications/dashboard/application/PhabricatorApplicationDashboard.php @@ -29,6 +29,7 @@ => '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 --- /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 --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php @@ -38,11 +38,17 @@ ->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 @@ ->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 --- /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 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php @@ -39,4 +39,13 @@ return $types; } + public function renderPanel( + PhabricatorUser $viewer, + PhabricatorDashboardPanel $panel) { + + return id(new PHUIObjectBoxView()) + ->setHeaderText($panel->getName()) + ->appendChild(pht('TODO: Panel content goes here.')); + } + }