2012-07-27 22:46:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFactHomeController extends PhabricatorFactController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
2012-07-28 02:29:44 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-07-30 19:44:08 +02:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$uri = new PhutilURI('/fact/chart/');
|
|
|
|
$uri->setQueryParam('y1', $request->getStr('y1'));
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
|
|
|
}
|
|
|
|
|
2012-07-28 02:29:44 +02:00
|
|
|
$types = array(
|
|
|
|
'+N:*',
|
|
|
|
'+N:DREV',
|
|
|
|
'updated',
|
|
|
|
);
|
|
|
|
|
|
|
|
$engines = PhabricatorFactEngine::loadAllEngines();
|
|
|
|
$specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types);
|
2012-07-27 22:46:01 +02:00
|
|
|
|
|
|
|
$facts = id(new PhabricatorFactAggregate())->loadAllWhere(
|
2012-07-28 02:29:44 +02:00
|
|
|
'factType IN (%Ls)',
|
|
|
|
$types);
|
2012-07-27 22:46:01 +02:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($facts as $fact) {
|
2012-07-28 02:29:44 +02:00
|
|
|
$spec = $specs[$fact->getFactType()];
|
|
|
|
|
|
|
|
$name = $spec->getName();
|
|
|
|
$value = $spec->formatValueForDisplay($user, $fact->getValueX());
|
|
|
|
|
2013-02-09 21:10:16 +01:00
|
|
|
$rows[] = array($name, $value);
|
2012-07-27 22:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Fact',
|
|
|
|
'Value',
|
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'wide',
|
|
|
|
'n',
|
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Facts!');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
2012-07-30 19:44:08 +02:00
|
|
|
$chart_form = $this->buildChartForm();
|
|
|
|
|
2012-07-27 22:46:01 +02:00
|
|
|
return $this->buildStandardPageResponse(
|
2012-07-30 19:44:08 +02:00
|
|
|
array(
|
|
|
|
$chart_form,
|
|
|
|
$panel,
|
|
|
|
),
|
2012-07-27 22:46:01 +02:00
|
|
|
array(
|
|
|
|
'title' => 'Facts!',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:44:08 +02:00
|
|
|
private function buildChartForm() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$table = new PhabricatorFactRaw();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$table_name = $table->getTableName();
|
|
|
|
|
|
|
|
$facts = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT DISTINCT factType from %T',
|
|
|
|
$table_name);
|
|
|
|
|
|
|
|
$specs = PhabricatorFactSpec::newSpecsForFactTypes(
|
|
|
|
PhabricatorFactEngine::loadAllEngines(),
|
|
|
|
ipull($facts, 'factType'));
|
|
|
|
|
|
|
|
$options = array();
|
|
|
|
foreach ($specs as $spec) {
|
|
|
|
if ($spec->getUnit() == PhabricatorFactSpec::UNIT_COUNT) {
|
|
|
|
$options[$spec->getType()] = $spec->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$options) {
|
|
|
|
return id(new AphrontErrorView())
|
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
|
|
|
|
->setTitle(pht('No Chartable Facts'))
|
2013-02-07 01:53:49 +01:00
|
|
|
->appendChild(phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
|
|
|
pht('There are no facts that can be plotted yet.')));
|
2012-07-30 19:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel('Y-Axis')
|
|
|
|
->setName('y1')
|
|
|
|
->setOptions($options))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Plot Chart'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->appendChild($form);
|
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
|
|
|
$panel->setHeader('Plot Chart');
|
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
2012-07-27 22:46:01 +02:00
|
|
|
}
|