1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-11 07:11:04 +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:
epriestley 2019-04-29 11:23:38 -07:00
parent c458b50b85
commit ff6b13872c
5 changed files with 114 additions and 7 deletions

View file

@ -2937,6 +2937,8 @@ phutil_register_library_map(array(
'PhabricatorDashboardApplication' => 'applications/dashboard/application/PhabricatorDashboardApplication.php',
'PhabricatorDashboardApplicationInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardApplicationInstallWorkflow.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',
'PhabricatorDashboardConsoleController' => 'applications/dashboard/controller/PhabricatorDashboardConsoleController.php',
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
@ -8983,6 +8985,8 @@ phutil_register_library_map(array(
'PhabricatorDashboardApplication' => 'PhabricatorApplication',
'PhabricatorDashboardApplicationInstallWorkflow' => 'PhabricatorDashboardInstallWorkflow',
'PhabricatorDashboardArchiveController' => 'PhabricatorDashboardController',
'PhabricatorDashboardChartPanelChartTransaction' => 'PhabricatorDashboardPanelPropertyTransaction',
'PhabricatorDashboardChartPanelType' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardColumn' => 'Phobject',
'PhabricatorDashboardConsoleController' => 'PhabricatorDashboardController',
'PhabricatorDashboardController' => 'PhabricatorController',

View file

@ -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;
}
}

View file

@ -0,0 +1,12 @@
<?php
final class PhabricatorDashboardChartPanelChartTransaction
extends PhabricatorDashboardPanelPropertyTransaction {
const TRANSACTIONTYPE = 'chart.chartKey';
protected function getPropertyKey() {
return 'chartKey';
}
}

View file

@ -10,17 +10,14 @@ final class PhabricatorFactChartController extends PhabricatorFactController {
return $this->newDemoChart();
}
$chart = id(new PhabricatorFactChart())->loadOneWhere(
'chartKey = %s',
$chart_key);
$engine = id(new PhabricatorChartEngine())
->setViewer($viewer);
$chart = $engine->loadChart($chart_key);
if (!$chart) {
return new Aphront404Response();
}
$engine = id(new PhabricatorChartEngine())
->setViewer($viewer)
->setChart($chart);
// 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
// the structure or actually pulling the data.

View file

@ -25,6 +25,24 @@ final class PhabricatorChartEngine
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() {
if (!$this->storedChart) {
$chart = $this->getChart();