2011-04-01 02:06:33 +02:00
|
|
|
<?php
|
|
|
|
|
2012-09-11 18:56:40 +02:00
|
|
|
final class PhabricatorUIExampleRenderController extends PhabricatorController {
|
2011-04-01 02:06:33 +02:00
|
|
|
|
2014-04-22 00:32:03 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-02 00:40:26 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$id = $request->getURIData('class');
|
2011-04-01 02:06:33 +02:00
|
|
|
|
2015-08-13 23:49:00 +02:00
|
|
|
$classes = id(new PhutilClassMapQuery())
|
2011-04-01 02:06:33 +02:00
|
|
|
->setAncestorClass('PhabricatorUIExample')
|
2015-08-13 23:49:00 +02:00
|
|
|
->setSortMethod('getName')
|
|
|
|
->execute();
|
2011-04-01 02:06:33 +02:00
|
|
|
|
2012-09-11 18:56:40 +02:00
|
|
|
$nav = new AphrontSideNavFilterView();
|
|
|
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/')));
|
2011-04-01 02:06:33 +02:00
|
|
|
|
|
|
|
foreach ($classes as $class => $obj) {
|
|
|
|
$name = $obj->getName();
|
2012-09-11 18:56:40 +02:00
|
|
|
$nav->addFilter($class, $name);
|
2011-04-01 02:06:33 +02:00
|
|
|
}
|
|
|
|
|
2015-08-02 00:40:26 +02:00
|
|
|
$selected = $nav->selectFilter($id, head_key($classes));
|
2012-09-11 18:56:40 +02:00
|
|
|
|
2011-04-01 02:06:33 +02:00
|
|
|
$example = $classes[$selected];
|
|
|
|
$example->setRequest($this->getRequest());
|
|
|
|
|
2012-10-03 19:21:39 +02:00
|
|
|
$result = $example->renderExample();
|
|
|
|
if ($result instanceof AphrontResponse) {
|
|
|
|
// This allows examples to generate dialogs, etc., for demonstration.
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:33:47 +02:00
|
|
|
require_celerity_resource('phabricator-ui-example-css');
|
|
|
|
|
2014-04-22 00:32:03 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($example->getName());
|
|
|
|
|
2015-05-22 21:50:01 +02:00
|
|
|
$note = id(new PHUIInfoView())
|
|
|
|
->setTitle(pht('%s (%s)', $example->getName(), get_class($example)))
|
|
|
|
->appendChild($example->getDescription())
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NODATA);
|
2011-04-01 02:06:33 +02:00
|
|
|
|
2014-04-22 00:32:03 +02:00
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2015-05-22 21:50:01 +02:00
|
|
|
$note,
|
2014-04-22 00:32:03 +02:00
|
|
|
$result,
|
|
|
|
));
|
2011-04-01 02:06:33 +02:00
|
|
|
|
2012-09-11 18:56:40 +02:00
|
|
|
return $this->buildApplicationPage(
|
2011-04-01 02:06:33 +02:00
|
|
|
$nav,
|
|
|
|
array(
|
2014-04-22 00:32:03 +02:00
|
|
|
'title' => $example->getName(),
|
2011-04-01 02:06:33 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|