Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fact/controller/PhabricatorFactChartController.php
12256 views
1
<?php
2
3
final class PhabricatorFactChartController
4
extends PhabricatorFactController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
9
$chart_key = $request->getURIData('chartKey');
10
if (!$chart_key) {
11
return new Aphront404Response();
12
}
13
14
$engine = id(new PhabricatorChartRenderingEngine())
15
->setViewer($viewer);
16
17
$chart = $engine->loadChart($chart_key);
18
if (!$chart) {
19
return new Aphront404Response();
20
}
21
22
// When drawing a chart, we send down a placeholder piece of HTML first,
23
// then fetch the data via async request. Determine if we're drawing
24
// the structure or actually pulling the data.
25
$mode = $request->getURIData('mode');
26
$is_draw_mode = ($mode === 'draw');
27
28
$want_data = $is_draw_mode;
29
30
// In developer mode, always pull the data in the main request. We'll
31
// throw it away if we're just drawing the chart frame, but this currently
32
// makes errors quite a bit easier to debug.
33
if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
34
$want_data = true;
35
}
36
37
if ($want_data) {
38
$chart_data = $engine->newChartData();
39
if ($is_draw_mode) {
40
return id(new AphrontAjaxResponse())->setContent($chart_data);
41
}
42
}
43
44
$chart_view = $engine->newChartView();
45
46
return $this->newChartResponse($chart_view);
47
}
48
49
private function newChartResponse($chart_view) {
50
$box = id(new PHUIObjectBoxView())
51
->setHeaderText(pht('Chart'))
52
->appendChild($chart_view);
53
54
$crumbs = $this->buildApplicationCrumbs()
55
->addTextCrumb(pht('Chart'))
56
->setBorder(true);
57
58
$title = pht('Chart');
59
60
return $this->newPage()
61
->setTitle($title)
62
->setCrumbs($crumbs)
63
->appendChild(
64
array(
65
$box,
66
));
67
}
68
69
}
70
71