1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00
phorge-phorge/src/applications/drydock/controller/DrydockBlueprintListController.php
epriestley a5dc9067af Provide convenience method addTextCrumb() to PhabricatorCrumbsView
Summary: We currently have a lot of calls to `addCrumb(id(new PhabricatorCrumbView())->...)` which can be expressed much more simply with a convenience method. Nearly all crumbs are only textual.

Test Plan:
  - This was mostly automated, then I cleaned up a few unusual sites manually.
  - Bunch of grep / randomly clicking around.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: hach-que, aran

Differential Revision: https://secure.phabricator.com/D7787
2013-12-18 17:47:34 -08:00

74 lines
1.9 KiB
PHP

<?php
final class DrydockBlueprintListController extends DrydockController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$title = pht('Blueprints');
$blueprint_header = id(new PHUIHeaderView())
->setHeader($title);
$blueprints = id(new DrydockBlueprintQuery())
->setViewer($user)
->execute();
$blueprint_list = $this->buildBlueprintListView($blueprints);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $request->getRequestURI());
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('New Blueprint'))
->setHref($this->getApplicationURI('blueprint/create/'))
->setIcon('create'));
$nav = $this->buildSideNav('blueprint');
$nav->setCrumbs($crumbs);
$nav->appendChild(
array(
$blueprint_header,
$blueprint_list
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
protected function buildBlueprintListView(array $blueprints) {
assert_instances_of($blueprints, 'DrydockBlueprint');
$user = $this->getRequest()->getUser();
$view = new PHUIObjectItemListView();
foreach ($blueprints as $blueprint) {
$item = id(new PHUIObjectItemView())
->setHeader($blueprint->getClassName())
->setHref($this->getApplicationURI('/blueprint/'.$blueprint->getID()))
->setObjectName(pht('Blueprint %d', $blueprint->getID()));
if ($blueprint->getImplementation()->isEnabled()) {
$item->addAttribute(pht('Enabled'));
$item->setBarColor('green');
} else {
$item->addAttribute(pht('Disabled'));
$item->setBarColor('red');
}
$item->addAttribute($blueprint->getImplementation()->getDescription());
$view->addItem($item);
}
return $view;
}
}