From ff6b13872ccfa6f2cc8861eb7960fae706652412 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 29 Apr 2019 11:23:38 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 + .../PhabricatorDashboardChartPanelType.php | 76 +++++++++++++++++++ ...torDashboardChartPanelChartTransaction.php | 12 +++ .../PhabricatorFactChartController.php | 11 +-- .../fact/engine/PhabricatorChartEngine.php | 18 +++++ 5 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 src/applications/dashboard/paneltype/PhabricatorDashboardChartPanelType.php create mode 100644 src/applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3ecee44659..867fce8822 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardChartPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardChartPanelType.php new file mode 100644 index 0000000000..880d9c9dc2 --- /dev/null +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardChartPanelType.php @@ -0,0 +1,76 @@ +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; + } + + +} diff --git a/src/applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php b/src/applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php new file mode 100644 index 0000000000..fad5a4b191 --- /dev/null +++ b/src/applications/dashboard/xaction/panel/PhabricatorDashboardChartPanelChartTransaction.php @@ -0,0 +1,12 @@ +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. diff --git a/src/applications/fact/engine/PhabricatorChartEngine.php b/src/applications/fact/engine/PhabricatorChartEngine.php index ef962e2173..fb8c8e1151 100644 --- a/src/applications/fact/engine/PhabricatorChartEngine.php +++ b/src/applications/fact/engine/PhabricatorChartEngine.php @@ -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();