Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/controller/PhabricatorFactHomeController.php
<?php | <?php | ||||
final class PhabricatorFactHomeController extends PhabricatorFactController { | final class PhabricatorFactHomeController | ||||
extends PhabricatorFactController { | |||||
public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
return true; | return true; | ||||
} | } | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $this->getViewer(); | ||||
if ($request->isFormPost()) { | $chart = id(new PhabricatorDemoChartEngine()) | ||||
$uri = new PhutilURI('/fact/chart/'); | ->setViewer($viewer) | ||||
$uri->replaceQueryParam('y1', $request->getStr('y1')); | ->newStoredChart(); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | |||||
} | |||||
$chart_form = $this->buildChartForm(); | |||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->addTextCrumb(pht('Home')); | |||||
$title = pht('Facts'); | |||||
return $this->newPage() | |||||
->setTitle($title) | |||||
->setCrumbs($crumbs) | |||||
->appendChild( | |||||
array( | |||||
$chart_form, | |||||
)); | |||||
} | |||||
private function buildChartForm() { | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getUser(); | |||||
$specs = PhabricatorFact::getAllFacts(); | |||||
$options = mpull($specs, 'getName', 'getKey'); | |||||
$form = id(new AphrontFormView()) | |||||
->setUser($viewer) | |||||
->appendChild( | |||||
id(new AphrontFormSelectControl()) | |||||
->setLabel(pht('Y-Axis')) | |||||
->setName('y1') | |||||
->setOptions($options)) | |||||
->appendChild( | |||||
id(new AphrontFormSubmitControl()) | |||||
->setValue(pht('Plot Chart'))); | |||||
$panel = new PHUIObjectBoxView(); | |||||
$panel->setForm($form); | |||||
$panel->setHeaderText(pht('Plot Chart')); | |||||
return $panel; | return id(new AphrontRedirectResponse())->setURI($chart->getURI()); | ||||
} | } | ||||
} | } |