mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-26 22:48:19 +01:00
Add a rough "Chart" Dashboard Panel
Summary: Depends on D20484. Ref T13279. Allows a chart to render as a panel. Configuring these is currently quite low-level (you have to manually copy/paste a chart key in), but works well enough. Test Plan: {F6412708} Reviewers: amckinley Reviewed By: amckinley Subscribers: yelirekim Maniphest Tasks: T13279 Differential Revision: https://secure.phabricator.com/D20485
This commit is contained in:
parent
c458b50b85
commit
ff6b13872c
5 changed files with 114 additions and 7 deletions
|
@ -2937,6 +2937,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardApplication' => 'applications/dashboard/application/PhabricatorDashboardApplication.php',
|
'PhabricatorDashboardApplication' => 'applications/dashboard/application/PhabricatorDashboardApplication.php',
|
||||||
'PhabricatorDashboardApplicationInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardApplicationInstallWorkflow.php',
|
'PhabricatorDashboardApplicationInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardApplicationInstallWorkflow.php',
|
||||||
'PhabricatorDashboardArchiveController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardArchiveController.php',
|
'PhabricatorDashboardArchiveController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardArchiveController.php',
|
||||||
|
'PhabricatorDashboardChartPanelChartTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php',
|
||||||
|
'PhabricatorDashboardChartPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardChartPanelType.php',
|
||||||
'PhabricatorDashboardColumn' => 'applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php',
|
'PhabricatorDashboardColumn' => 'applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php',
|
||||||
'PhabricatorDashboardConsoleController' => 'applications/dashboard/controller/PhabricatorDashboardConsoleController.php',
|
'PhabricatorDashboardConsoleController' => 'applications/dashboard/controller/PhabricatorDashboardConsoleController.php',
|
||||||
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
|
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
|
||||||
|
@ -8983,6 +8985,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardApplication' => 'PhabricatorApplication',
|
'PhabricatorDashboardApplication' => 'PhabricatorApplication',
|
||||||
'PhabricatorDashboardApplicationInstallWorkflow' => 'PhabricatorDashboardInstallWorkflow',
|
'PhabricatorDashboardApplicationInstallWorkflow' => 'PhabricatorDashboardInstallWorkflow',
|
||||||
'PhabricatorDashboardArchiveController' => 'PhabricatorDashboardController',
|
'PhabricatorDashboardArchiveController' => 'PhabricatorDashboardController',
|
||||||
|
'PhabricatorDashboardChartPanelChartTransaction' => 'PhabricatorDashboardPanelPropertyTransaction',
|
||||||
|
'PhabricatorDashboardChartPanelType' => 'PhabricatorDashboardPanelType',
|
||||||
'PhabricatorDashboardColumn' => 'Phobject',
|
'PhabricatorDashboardColumn' => 'Phobject',
|
||||||
'PhabricatorDashboardConsoleController' => 'PhabricatorDashboardController',
|
'PhabricatorDashboardConsoleController' => 'PhabricatorDashboardController',
|
||||||
'PhabricatorDashboardController' => 'PhabricatorController',
|
'PhabricatorDashboardController' => 'PhabricatorController',
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardChartPanelType
|
||||||
|
extends PhabricatorDashboardPanelType {
|
||||||
|
|
||||||
|
public function getPanelTypeKey() {
|
||||||
|
return 'chart';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPanelTypeName() {
|
||||||
|
return pht('Chart Panel');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
return 'fa-area-chart';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPanelTypeDescription() {
|
||||||
|
return pht('Show a chart.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newEditEngineFields(PhabricatorDashboardPanel $panel) {
|
||||||
|
$chart_field = id(new PhabricatorTextEditField())
|
||||||
|
->setKey('chartKey')
|
||||||
|
->setLabel(pht('Chart'))
|
||||||
|
->setTransactionType(
|
||||||
|
PhabricatorDashboardChartPanelChartTransaction::TRANSACTIONTYPE)
|
||||||
|
->setValue($panel->getProperty('chartKey', ''));
|
||||||
|
|
||||||
|
return array(
|
||||||
|
$chart_field,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderPanelContent(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
PhabricatorDashboardPanel $panel,
|
||||||
|
PhabricatorDashboardPanelRenderingEngine $engine) {
|
||||||
|
|
||||||
|
$engine = id(new PhabricatorChartEngine())
|
||||||
|
->setViewer($viewer);
|
||||||
|
|
||||||
|
$chart = $engine->loadChart($panel->getProperty('chartKey'));
|
||||||
|
if (!$chart) {
|
||||||
|
return pht('no such chart!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $engine->newChartView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adjustPanelHeader(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
PhabricatorDashboardPanel $panel,
|
||||||
|
PhabricatorDashboardPanelRenderingEngine $engine,
|
||||||
|
PHUIHeaderView $header) {
|
||||||
|
|
||||||
|
$key = $panel->getProperty('chartKey');
|
||||||
|
$uri = PhabricatorChartEngine::getChartURI($key);
|
||||||
|
|
||||||
|
$icon = id(new PHUIIconView())
|
||||||
|
->setIcon('fa-area-chart');
|
||||||
|
|
||||||
|
$button = id(new PHUIButtonView())
|
||||||
|
->setTag('a')
|
||||||
|
->setText(pht('View Chart'))
|
||||||
|
->setIcon($icon)
|
||||||
|
->setHref($uri)
|
||||||
|
->setColor(PHUIButtonView::GREY);
|
||||||
|
|
||||||
|
$header->addActionLink($button);
|
||||||
|
|
||||||
|
return $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardChartPanelChartTransaction
|
||||||
|
extends PhabricatorDashboardPanelPropertyTransaction {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'chart.chartKey';
|
||||||
|
|
||||||
|
protected function getPropertyKey() {
|
||||||
|
return 'chartKey';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,17 +10,14 @@ final class PhabricatorFactChartController extends PhabricatorFactController {
|
||||||
return $this->newDemoChart();
|
return $this->newDemoChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart = id(new PhabricatorFactChart())->loadOneWhere(
|
$engine = id(new PhabricatorChartEngine())
|
||||||
'chartKey = %s',
|
->setViewer($viewer);
|
||||||
$chart_key);
|
|
||||||
|
$chart = $engine->loadChart($chart_key);
|
||||||
if (!$chart) {
|
if (!$chart) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine = id(new PhabricatorChartEngine())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->setChart($chart);
|
|
||||||
|
|
||||||
// When drawing a chart, we send down a placeholder piece of HTML first,
|
// When drawing a chart, we send down a placeholder piece of HTML first,
|
||||||
// then fetch the data via async request. Determine if we're drawing
|
// then fetch the data via async request. Determine if we're drawing
|
||||||
// the structure or actually pulling the data.
|
// the structure or actually pulling the data.
|
||||||
|
|
|
@ -25,6 +25,24 @@ final class PhabricatorChartEngine
|
||||||
return $this->chart;
|
return $this->chart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadChart($chart_key) {
|
||||||
|
$chart = id(new PhabricatorFactChart())->loadOneWhere(
|
||||||
|
'chartKey = %s',
|
||||||
|
$chart_key);
|
||||||
|
|
||||||
|
if ($chart) {
|
||||||
|
$this->setChart($chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getChartURI($chart_key) {
|
||||||
|
return id(new PhabricatorFactChart())
|
||||||
|
->setChartKey($chart_key)
|
||||||
|
->getURI();
|
||||||
|
}
|
||||||
|
|
||||||
public function getStoredChart() {
|
public function getStoredChart() {
|
||||||
if (!$this->storedChart) {
|
if (!$this->storedChart) {
|
||||||
$chart = $this->getChart();
|
$chart = $this->getChart();
|
||||||
|
|
Loading…
Add table
Reference in a new issue