@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 73 lines 1.9 kB view raw
1<?php 2 3final class PhabricatorFactChartController 4 extends PhabricatorFactController { 5 6 public function shouldAllowPublic() { 7 return true; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $request->getViewer(); 12 13 $chart_key = $request->getURIData('chartKey'); 14 if (!$chart_key) { 15 return new Aphront404Response(); 16 } 17 18 $engine = id(new PhabricatorChartRenderingEngine()) 19 ->setViewer($viewer); 20 21 $chart = $engine->loadChart($chart_key); 22 if (!$chart) { 23 return new Aphront404Response(); 24 } 25 26 // When drawing a chart, we send down a placeholder piece of HTML first, 27 // then fetch the data via async request. Determine if we're drawing 28 // the structure or actually pulling the data. 29 $mode = $request->getURIData('mode'); 30 $is_draw_mode = ($mode === 'draw'); 31 32 $want_data = $is_draw_mode; 33 34 // In developer mode, always pull the data in the main request. We'll 35 // throw it away if we're just drawing the chart frame, but this currently 36 // makes errors quite a bit easier to debug. 37 if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) { 38 $want_data = true; 39 } 40 41 if ($want_data) { 42 $chart_data = $engine->newChartData(); 43 if ($is_draw_mode) { 44 return id(new AphrontAjaxResponse())->setContent($chart_data); 45 } 46 } 47 48 $chart_view = $engine->newChartView(); 49 50 return $this->newChartResponse($chart_view); 51 } 52 53 private function newChartResponse($chart_view) { 54 $box = id(new PHUIObjectBoxView()) 55 ->setHeaderText(pht('Chart')) 56 ->appendChild($chart_view); 57 58 $crumbs = $this->buildApplicationCrumbs() 59 ->addTextCrumb(pht('Chart')) 60 ->setBorder(true); 61 62 $title = pht('Chart'); 63 64 return $this->newPage() 65 ->setTitle($title) 66 ->setCrumbs($crumbs) 67 ->appendChild( 68 array( 69 $box, 70 )); 71 } 72 73}