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
|
|
|
|
2015-07-27 07:56:52 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
$id = $request->getURIData('id');
|
2013-12-03 11:09:07 +11:00
|
|
|
|
2013-12-27 13:15:19 -08:00
|
|
|
$blueprint = id(new DrydockBlueprintQuery())
|
|
|
|
|
->setViewer($viewer)
|
2015-07-27 07:56:52 -07:00
|
|
|
->withIDs(array($id))
|
2013-12-27 13:15:19 -08:00
|
|
|
->executeOne();
|
2013-12-03 11:09:07 +11:00
|
|
|
if (!$blueprint) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 10:56:34 -08:00
|
|
|
$title = $blueprint->getBlueprintName();
|
2013-12-03 11:09:07 +11:00
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
2014-01-09 10:56:34 -08:00
|
|
|
->setHeader($title)
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setPolicyObject($blueprint);
|
2013-12-03 11:09:07 +11:00
|
|
|
|
2015-09-24 10:18:17 -07:00
|
|
|
if ($blueprint->getIsDisabled()) {
|
|
|
|
|
$header->setStatus('fa-ban', 'red', pht('Disabled'));
|
|
|
|
|
} else {
|
|
|
|
|
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 11:09:07 +11:00
|
|
|
$actions = $this->buildActionListView($blueprint);
|
|
|
|
|
$properties = $this->buildPropertyListView($blueprint, $actions);
|
|
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
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);
|
|
|
|
|
|
2014-08-12 08:39:00 +10:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
|
$blueprint,
|
|
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
|
|
|
|
$field_list
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->readFieldsFromStorage($blueprint);
|
|
|
|
|
|
|
|
|
|
$field_list->appendFieldsToPropertyList(
|
|
|
|
|
$blueprint,
|
|
|
|
|
$viewer,
|
|
|
|
|
$properties);
|
|
|
|
|
|
2015-09-24 13:52:43 -07:00
|
|
|
$resource_box = $this->buildResourceBox($blueprint);
|
2015-09-21 04:45:43 -07:00
|
|
|
|
2014-12-03 13:16:15 -08:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
|
$blueprint,
|
|
|
|
|
new DrydockBlueprintTransactionQuery());
|
|
|
|
|
$timeline->setShouldTerminate(true);
|
2014-01-09 12:19:54 -08:00
|
|
|
|
2013-12-03 11:09:07 +11:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
|
|
|
|
$crumbs,
|
|
|
|
|
$object_box,
|
2015-09-21 04:45:43 -07:00
|
|
|
$resource_box,
|
2014-01-09 12:19:54 -08:00
|
|
|
$timeline,
|
2013-12-03 11:09:07 +11:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'title' => $title,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildActionListView(DrydockBlueprint $blueprint) {
|
2015-09-24 10:18:17 -07:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
$id = $blueprint->getID();
|
2014-01-08 14:12:27 -08:00
|
|
|
|
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);
|
|
|
|
|
|
2015-09-24 10:18:17 -07:00
|
|
|
$edit_uri = $this->getApplicationURI("blueprint/edit/{$id}/");
|
2013-12-03 11:09:07 +11:00
|
|
|
|
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())
|
2015-09-24 10:18:17 -07:00
|
|
|
->setHref($edit_uri)
|
2014-01-08 14:12:27 -08:00
|
|
|
->setName(pht('Edit Blueprint'))
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-pencil')
|
2014-01-08 14:12:27 -08:00
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
|
->setDisabled(!$can_edit));
|
2013-12-03 11:09:07 +11:00
|
|
|
|
2015-09-24 10:18:17 -07:00
|
|
|
if (!$blueprint->getIsDisabled()) {
|
|
|
|
|
$disable_name = pht('Disable Blueprint');
|
|
|
|
|
$disable_icon = 'fa-ban';
|
|
|
|
|
$disable_uri = $this->getApplicationURI("blueprint/{$id}/disable/");
|
|
|
|
|
} else {
|
|
|
|
|
$disable_name = pht('Enable Blueprint');
|
|
|
|
|
$disable_icon = 'fa-check';
|
|
|
|
|
$disable_uri = $this->getApplicationURI("blueprint/{$id}/enable/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setHref($disable_uri)
|
|
|
|
|
->setName($disable_name)
|
|
|
|
|
->setIcon($disable_icon)
|
|
|
|
|
->setWorkflow(true)
|
|
|
|
|
->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(
|
2014-01-09 10:56:34 -08:00
|
|
|
pht('Type'),
|
|
|
|
|
$blueprint->getImplementation()->getBlueprintName());
|
2013-12-03 11:09:07 +11:00
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 13:52:43 -07:00
|
|
|
private function buildResourceBox(DrydockBlueprint $blueprint) {
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
|
|
$resources = id(new DrydockResourceQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withBlueprintPHIDs(array($blueprint->getPHID()))
|
|
|
|
|
->withStatuses(
|
|
|
|
|
array(
|
|
|
|
|
DrydockResourceStatus::STATUS_PENDING,
|
|
|
|
|
DrydockResourceStatus::STATUS_ACTIVE,
|
|
|
|
|
))
|
|
|
|
|
->setLimit(100)
|
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
|
|
$resource_list = id(new DrydockResourceListView())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setResources($resources)
|
|
|
|
|
->render()
|
|
|
|
|
->setNoDataString(pht('This blueprint has no active resources.'));
|
|
|
|
|
|
|
|
|
|
$id = $blueprint->getID();
|
|
|
|
|
$resources_uri = "blueprint/{$id}/resources/query/all/";
|
|
|
|
|
$resources_uri = $this->getApplicationURI($resources_uri);
|
|
|
|
|
|
|
|
|
|
$resource_header = id(new PHUIHeaderView())
|
|
|
|
|
->setHeader(pht('Active Resources'))
|
|
|
|
|
->addActionLink(
|
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
|
->setTag('a')
|
|
|
|
|
->setHref($resources_uri)
|
|
|
|
|
->setIconFont('fa-search')
|
|
|
|
|
->setText(pht('View All Resources')));
|
|
|
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
|
->setHeader($resource_header)
|
|
|
|
|
->setObjectList($resource_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-12-03 11:09:07 +11:00
|
|
|
}
|