2013-12-03 11:09:07 +11:00
|
|
|
<?php
|
|
|
|
|
|
2013-12-26 12:30:36 -08:00
|
|
|
final class DrydockBlueprintViewController extends DrydockBlueprintController {
|
2013-12-03 11:09:07 +11:00
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
|
$this->id = $data['id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
$request = $this->getRequest();
|
2013-12-27 13:15:19 -08:00
|
|
|
$viewer = $request->getUser();
|
2013-12-03 11:09:07 +11:00
|
|
|
|
2013-12-27 13:15:19 -08:00
|
|
|
$blueprint = id(new DrydockBlueprintQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
|
->executeOne();
|
2013-12-03 11:09:07 +11:00
|
|
|
if (!$blueprint) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = 'Blueprint '.$blueprint->getID().' '.$blueprint->getClassName();
|
|
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
|
|
$actions = $this->buildActionListView($blueprint);
|
|
|
|
|
$properties = $this->buildPropertyListView($blueprint, $actions);
|
|
|
|
|
|
|
|
|
|
$blueprint_uri = 'blueprint/'.$blueprint->getID().'/';
|
|
|
|
|
$blueprint_uri = $this->getApplicationURI($blueprint_uri);
|
|
|
|
|
|
|
|
|
|
$resources = id(new DrydockResourceQuery())
|
|
|
|
|
->withBlueprintPHIDs(array($blueprint->getPHID()))
|
2013-12-27 13:15:19 -08:00
|
|
|
->setViewer($viewer)
|
2013-12-03 11:09:07 +11:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
|
|
$resource_list = $this->buildResourceListView($resources);
|
|
|
|
|
$resource_list->setNoDataString(pht('This blueprint has no resources.'));
|
|
|
|
|
|
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
|
$pager->setURI(new PhutilURI($blueprint_uri), 'offset');
|
|
|
|
|
$pager->setOffset($request->getInt('offset'));
|
|
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
$crumbs->setActionList($actions);
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID()));
|
2013-12-03 11:09:07 +11:00
|
|
|
|
|
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
|
->setHeader($header)
|
|
|
|
|
->addPropertyList($properties);
|
|
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
|
|
|
|
$crumbs,
|
|
|
|
|
$object_box,
|
|
|
|
|
$resource_list
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'device' => true,
|
|
|
|
|
'title' => $title,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildActionListView(DrydockBlueprint $blueprint) {
|
2014-01-08 14:12:27 -08:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
2013-12-03 11:09:07 +11:00
|
|
|
$view = id(new PhabricatorActionListView())
|
2014-01-08 14:12:27 -08:00
|
|
|
->setUser($viewer)
|
2013-12-03 11:09:07 +11:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
|
|
|
|
->setObject($blueprint);
|
|
|
|
|
|
|
|
|
|
$uri = '/blueprint/edit/'.$blueprint->getID().'/';
|
|
|
|
|
$uri = $this->getApplicationURI($uri);
|
|
|
|
|
|
2014-01-08 14:12:27 -08:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
|
$viewer,
|
|
|
|
|
$blueprint,
|
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
2013-12-03 11:09:07 +11:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setHref($uri)
|
2014-01-08 14:12:27 -08:00
|
|
|
->setName(pht('Edit Blueprint'))
|
2013-12-03 11:09:07 +11:00
|
|
|
->setIcon('edit')
|
2014-01-08 14:12:27 -08:00
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
|
->setDisabled(!$can_edit));
|
2013-12-03 11:09:07 +11:00
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildPropertyListView(
|
|
|
|
|
DrydockBlueprint $blueprint,
|
|
|
|
|
PhabricatorActionListView $actions) {
|
|
|
|
|
|
|
|
|
|
$view = new PHUIPropertyListView();
|
|
|
|
|
$view->setActionList($actions);
|
|
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Implementation'),
|
|
|
|
|
$blueprint->getClassName());
|
|
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|