Differential D8917 Diff 21164 src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
<?php | <?php | ||||
final class PhabricatorDashboardPanelRenderingEngine extends Phobject { | final class PhabricatorDashboardPanelRenderingEngine extends Phobject { | ||||
private $panel; | private $panel; | ||||
private $viewer; | private $viewer; | ||||
private $enableAsyncRendering; | |||||
/** | |||||
* Allow the engine to render the panel via Ajax. | |||||
*/ | |||||
public function setEnableAsyncRendering($enable) { | |||||
$this->enableAsyncRendering = $enable; | |||||
return $this; | |||||
} | |||||
public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
$this->viewer = $viewer; | $this->viewer = $viewer; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setPanel(PhabricatorDashboardPanel $panel) { | public function setPanel(PhabricatorDashboardPanel $panel) { | ||||
$this->panel = $panel; | $this->panel = $panel; | ||||
Show All 15 Lines | if (!$panel_type) { | ||||
return $this->renderErrorPanel( | return $this->renderErrorPanel( | ||||
$panel->getName(), | $panel->getName(), | ||||
pht( | pht( | ||||
'This panel has type "%s", but that panel type is not known to '. | 'This panel has type "%s", but that panel type is not known to '. | ||||
'Phabricator.', | 'Phabricator.', | ||||
$panel->getPanelType())); | $panel->getPanelType())); | ||||
} | } | ||||
if ($this->enableAsyncRendering) { | |||||
if ($panel_type->shouldRenderAsync()) { | |||||
return $this->renderAsyncPanel($panel); | |||||
} | |||||
} | |||||
return $panel_type->renderPanel($viewer, $panel); | return $panel_type->renderPanel($viewer, $panel); | ||||
} | } | ||||
private function renderErrorPanel($title, $body) { | private function renderErrorPanel($title, $body) { | ||||
return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
->setHeaderText($title) | ->setHeaderText($title) | ||||
->setFormErrors(array($body)); | ->setFormErrors(array($body)); | ||||
} | } | ||||
private function renderAsyncPanel(PhabricatorDashboardPanel $panel) { | |||||
$panel_id = celerity_generate_unique_node_id(); | |||||
Javelin::initBehavior( | |||||
'dashboard-async-panel', | |||||
array( | |||||
'panelID' => $panel_id, | |||||
'uri' => '/dashboard/panel/render/'.$panel->getID().'/', | |||||
)); | |||||
return id(new PHUIObjectBoxView()) | |||||
->setHeaderText($panel->getName()) | |||||
->setID($panel_id) | |||||
->appendChild(pht('Loading...')); | |||||
} | |||||
} | } |