diff --git a/src/applications/fact/application/PhabricatorApplicationFact.php b/src/applications/fact/application/PhabricatorApplicationFact.php index ac7b0c55ab..0436594b50 100644 --- a/src/applications/fact/application/PhabricatorApplicationFact.php +++ b/src/applications/fact/application/PhabricatorApplicationFact.php @@ -1,34 +1,38 @@ array( '' => 'PhabricatorFactHomeController', 'chart/' => 'PhabricatorFactChartController', ), ); } } diff --git a/src/applications/fact/controller/PhabricatorFactChartController.php b/src/applications/fact/controller/PhabricatorFactChartController.php index 12e52fdaa9..434bbe077d 100644 --- a/src/applications/fact/controller/PhabricatorFactChartController.php +++ b/src/applications/fact/controller/PhabricatorFactChartController.php @@ -1,90 +1,96 @@ getRequest(); $user = $request->getUser(); $table = new PhabricatorFactRaw(); $conn_r = $table->establishConnection('r'); $table_name = $table->getTableName(); $series = $request->getStr('y1'); $specs = PhabricatorFactSpec::newSpecsForFactTypes( PhabricatorFactEngine::loadAllEngines(), array($series)); $spec = idx($specs, $series); $data = queryfx_all( $conn_r, 'SELECT valueX, epoch FROM %T WHERE factType = %s ORDER BY epoch ASC', $table_name, $series); $points = array(); $sum = 0; foreach ($data as $key => $row) { $sum += (int)$row['valueX']; $points[(int)$row['epoch']] = $sum; } if (!$points) { // NOTE: Raphael crashes Safari if you hand it series with no points. throw new Exception("No data to show!"); } // Limit amount of data passed to browser. $count = count($points); $limit = 2000; if ($count > $limit) { $i = 0; $every = ceil($count / $limit); foreach ($points as $epoch => $sum) { $i++; if ($i % $every && $i != $count) { unset($points[$epoch]); } } } $x = array_keys($points); $y = array_values($points); $id = celerity_generate_unique_node_id(); $chart = phutil_tag( 'div', array( 'id' => $id, 'style' => 'border: 1px solid #6f6f6f; '. 'margin: 1em 2em; '. 'background: #ffffff; '. 'height: 400px; ', ), ''); require_celerity_resource('raphael-core'); require_celerity_resource('raphael-g'); require_celerity_resource('raphael-g-line'); Javelin::initBehavior('line-chart', array( 'hardpoint' => $id, 'x' => array($x), 'y' => array($y), 'xformat' => 'epoch', 'colors' => array('#0000ff'), )); $panel = new AphrontPanelView(); $panel->setHeader('Count of '.$spec->getName()); $panel->appendChild($chart); - return $this->buildStandardPageResponse( - $panel, + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Chart')); + + return $this->buildApplicationPage( + array( + $crumbs, + $panel, + ), array( 'title' => 'Chart', )); } } diff --git a/src/applications/fact/controller/PhabricatorFactController.php b/src/applications/fact/controller/PhabricatorFactController.php index 18c7d8cad5..6ea55fec61 100644 --- a/src/applications/fact/controller/PhabricatorFactController.php +++ b/src/applications/fact/controller/PhabricatorFactController.php @@ -1,18 +1,5 @@ buildStandardPageView(); - - $page->setBaseURI('/fact/'); - $page->setTitle(idx($data, 'title')); - - $page->setGlyph("\xCE\xA3"); - $page->appendChild($view); - - $response = new AphrontWebpageResponse(); - return $response->setContent($page->render()); - } - } diff --git a/src/applications/fact/controller/PhabricatorFactHomeController.php b/src/applications/fact/controller/PhabricatorFactHomeController.php index 342edb7fa3..9bf6fc6496 100644 --- a/src/applications/fact/controller/PhabricatorFactHomeController.php +++ b/src/applications/fact/controller/PhabricatorFactHomeController.php @@ -1,119 +1,127 @@ getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $uri = new PhutilURI('/fact/chart/'); $uri->setQueryParam('y1', $request->getStr('y1')); return id(new AphrontRedirectResponse())->setURI($uri); } $types = array( '+N:*', '+N:DREV', 'updated', ); $engines = PhabricatorFactEngine::loadAllEngines(); $specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types); $facts = id(new PhabricatorFactAggregate())->loadAllWhere( 'factType IN (%Ls)', $types); $rows = array(); foreach ($facts as $fact) { $spec = $specs[$fact->getFactType()]; $name = $spec->getName(); $value = $spec->formatValueForDisplay($user, $fact->getValueX()); $rows[] = array($name, $value); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'Fact', 'Value', )); $table->setColumnClasses( array( 'wide', 'n', )); $panel = new AphrontPanelView(); $panel->setHeader('Facts!'); $panel->appendChild($table); $chart_form = $this->buildChartForm(); - return $this->buildStandardPageResponse( + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Home')); + + return $this->buildApplicationPage( array( + $crumbs, $chart_form, $panel, ), array( - 'title' => 'Facts!', + 'title' => 'Facts', )); } 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')) ->appendChild(phutil_tag( 'p', array(), pht('There are no facts that can be plotted yet.'))); } $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; } }