mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Let dashboard panels render in a very basic way
Summary: Ref T3583. This implements very primitive panel rendering on the panel detail page, and an ajaxable standalone view. Test Plan: {F149135} {F149136} {F149137} {F149138} Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3583 Differential Revision: https://secure.phabricator.com/D8913
This commit is contained in:
parent
ea954c37e4
commit
0916af5336
6 changed files with 126 additions and 0 deletions
|
@ -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',
|
||||
|
|
|
@ -29,6 +29,7 @@ final class PhabricatorApplicationDashboard extends PhabricatorApplication {
|
|||
=> 'PhabricatorDashboardPanelListController',
|
||||
'create/' => 'PhabricatorDashboardPanelCreateController',
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController',
|
||||
'render/(?P<id>\d+)/' => 'PhabricatorDashboardPanelRenderController',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDashboardPanelRenderController
|
||||
extends PhabricatorDashboardController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->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,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
|
||||
|
||||
private $panel;
|
||||
private $viewer;
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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.'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue