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
|
|
|
|
Move Drydock logs to PHIDs and increased structure
Summary:
Ref T9252. Several general changes here:
- Moves logs to use PHIDs instead of IDs. This generally improves flexibility (for example, it's a lot easier to render handles).
- Adds `blueprintPHID` to logs. Although you can usually figure this out from the leasePHID or resourcePHID, it lets us query relevant logs on Blueprint views.
- Instead of making logs a top-level object, make them strictly a sub-object of Blueprints, Resources and Leases. So you go Drydock > Lease > Logs, etc., to get to logs.
- I might restore the "everything" view eventually, but it doesn't interact well with policies and I'm not sure it's very useful. A policy-violating `bin/drydock log` might be cleaner.
- Policy-wise, we always show you that logs exist, we just don't show you log content if it's about something you can't see. This is similar to seeing restricted handles in other applications.
- Instead of just having a message, give logs "type" + "data". This will let logs be more structured and translatable. This is similar to recent changes to Herald which seem to have worked well.
Test Plan:
Added some placeholder log writes, viewed those logs in the UI.
{F855199}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T9252
Differential Revision: https://secure.phabricator.com/D14196
2015-10-01 08:06:23 -07:00
|
|
|
$log_query = id(new DrydockLogQuery())
|
|
|
|
|
->withBlueprintPHIDs(array($blueprint->getPHID()));
|
|
|
|
|
|
|
|
|
|
$log_box = $this->buildLogBox(
|
|
|
|
|
$log_query,
|
|
|
|
|
$this->getApplicationURI("blueprint/{$id}/logs/query/all/"));
|
|
|
|
|
|
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,
|
Move Drydock logs to PHIDs and increased structure
Summary:
Ref T9252. Several general changes here:
- Moves logs to use PHIDs instead of IDs. This generally improves flexibility (for example, it's a lot easier to render handles).
- Adds `blueprintPHID` to logs. Although you can usually figure this out from the leasePHID or resourcePHID, it lets us query relevant logs on Blueprint views.
- Instead of making logs a top-level object, make them strictly a sub-object of Blueprints, Resources and Leases. So you go Drydock > Lease > Logs, etc., to get to logs.
- I might restore the "everything" view eventually, but it doesn't interact well with policies and I'm not sure it's very useful. A policy-violating `bin/drydock log` might be cleaner.
- Policy-wise, we always show you that logs exist, we just don't show you log content if it's about something you can't see. This is similar to seeing restricted handles in other applications.
- Instead of just having a message, give logs "type" + "data". This will let logs be more structured and translatable. This is similar to recent changes to Herald which seem to have worked well.
Test Plan:
Added some placeholder log writes, viewed those logs in the UI.
{F855199}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T9252
Differential Revision: https://secure.phabricator.com/D14196
2015-10-01 08:06:23 -07:00
|
|
|
$log_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
|
|
|
}
|