1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-29 16:08:22 +01:00

Give dashboards basic rendering and Ajax support

Summary: Ref T3583. Let dashboards "render", sorta.

Test Plan: {F149187}

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3583

Differential Revision: https://secure.phabricator.com/D8917
This commit is contained in:
epriestley 2014-04-30 14:29:14 -07:00
parent 941f0ba7ae
commit dbadfeb6b7
6 changed files with 97 additions and 0 deletions

View file

@ -1454,6 +1454,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php',
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
'PhabricatorDashboardRenderingEngine' => 'applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php',
'PhabricatorDashboardSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardSearchEngine.php',
'PhabricatorDashboardTransaction' => 'applications/dashboard/storage/PhabricatorDashboardTransaction.php',
'PhabricatorDashboardTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardTransactionEditor.php',
@ -4267,6 +4268,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorDashboardRenderingEngine' => 'Phobject',
'PhabricatorDashboardSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorDashboardTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorDashboardTransactionEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -36,11 +36,17 @@ final class PhabricatorDashboardViewController
->setHeader($header)
->addPropertyList($properties);
$rendered_dashboard = id(new PhabricatorDashboardRenderingEngine())
->setViewer($viewer)
->setDashboard($dashboard)
->renderDashboard();
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$timeline,
$rendered_dashboard,
),
array(
'title' => $title,

View file

@ -4,6 +4,15 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
private $panel;
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) {
$this->viewer = $viewer;
@ -35,6 +44,13 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
$panel->getPanelType()));
}
if ($this->enableAsyncRendering) {
if ($panel_type->shouldRenderAsync()) {
return $this->renderAsyncPanel($panel);
}
}
return $panel_type->renderPanel($viewer, $panel);
}
@ -44,4 +60,20 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
->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...'));
}
}

View file

@ -0,0 +1,34 @@
<?php
final class PhabricatorDashboardRenderingEngine extends Phobject {
private $dashboard;
private $viewer;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function setDashboard(PhabricatorDashboard $dashboard) {
$this->dashboard = $dashboard;
return $this;
}
public function renderDashboard() {
$dashboard = $this->dashboard;
$viewer = $this->viewer;
$result = array();
foreach ($dashboard->getPanels() as $panel) {
$result[] = id(new PhabricatorDashboardPanelRenderingEngine())
->setViewer($viewer)
->setPanel($panel)
->setEnableAsyncRendering(true)
->renderPanel();
}
return $result;
}
}

View file

@ -48,4 +48,10 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
->appendChild(pht('TODO: Panel content goes here.'));
}
public function shouldRenderAsync() {
// TODO: For now, just make these things random so we can catch anything
// that breaks.
return (mt_rand(0, 1) == 1);
}
}

View file

@ -0,0 +1,17 @@
/**
* @provides javelin-behavior-dashboard-async-panel
* @requires javelin-behavior
* javelin-dom
* javelin-workflow
*/
JX.behavior('dashboard-async-panel', function(config) {
var panel = JX.$(config.panelID);
panel.style.opacity = '0.5';
new JX.Workflow(config.uri)
.setHandler(function(r) {
JX.DOM.replace(panel, JX.$H(r.panelMarkup));
})
.start();
});