1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-01 18:30:59 +01:00

Make Drydock blueprint create workflow somewhat more standard

Summary: Ref T2015. This workflow is a little weird (runs in a dialog, no edit-before-create step, lots of internal classnames). Make it a little more standard.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D7908
This commit is contained in:
epriestley 2014-01-08 14:12:27 -08:00
parent 324ee4e4d5
commit 5502fca5f4
9 changed files with 126 additions and 79 deletions

View file

@ -38,7 +38,7 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockBlueprintListController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockBlueprintListController',
'(?P<id>[1-9]\d*)/' => 'DrydockBlueprintViewController', '(?P<id>[1-9]\d*)/' => 'DrydockBlueprintViewController',
'create/' => 'DrydockBlueprintCreateController', 'create/' => 'DrydockBlueprintCreateController',
'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController', 'edit/(?:(?P<id>[1-9]\d*)/)?' => 'DrydockBlueprintEditController',
), ),
'resource/' => array( 'resource/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockResourceListController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockResourceListController',

View file

@ -19,6 +19,7 @@ abstract class DrydockBlueprintImplementation {
abstract public function isEnabled(); abstract public function isEnabled();
abstract public function getBlueprintName();
abstract public function getDescription(); abstract public function getDescription();
public function getBlueprintClass() { public function getBlueprintClass() {
@ -388,6 +389,10 @@ abstract class DrydockBlueprintImplementation {
return idx($groups, $type, array()); return idx($groups, $type, array());
} }
public static function getNamedImplementation($class) {
return idx(self::getAllBlueprintImplementations(), $class);
}
protected function newResourceTemplate($name) { protected function newResourceTemplate($name) {
$resource = id(new DrydockResource()) $resource = id(new DrydockResource())
->setBlueprintPHID($this->getInstance()->getPHID()) ->setBlueprintPHID($this->getInstance()->getPHID())

View file

@ -7,8 +7,13 @@ final class DrydockLocalHostBlueprintImplementation
return false; return false;
} }
public function getBlueprintName() {
return pht('Local Host');
}
public function getDescription() { public function getDescription() {
return pht('Allocates storage on the local host.'); return pht(
'Allows Drydock to run on the local host.');
} }
public function canAllocateMoreResources(array $pool) { public function canAllocateMoreResources(array $pool) {

View file

@ -7,8 +7,12 @@ final class DrydockPreallocatedHostBlueprintImplementation
return true; return true;
} }
public function getBlueprintName() {
return pht('Remote Host (Preallocated)');
}
public function getDescription() { public function getDescription() {
return pht('Leases out preallocated, remote hosts.'); return pht('Allows Drydock to run on specific remote hosts you configure.');
} }
public function canAllocateMoreResources(array $pool) { public function canAllocateMoreResources(array $pool) {

View file

@ -7,8 +7,12 @@ final class DrydockWorkingCopyBlueprintImplementation
return true; return true;
} }
public function getBlueprintName() {
return pht('Working Copy');
}
public function getDescription() { public function getDescription() {
return pht('Allocates out working copies of repositories.'); return pht('Allows Drydock to check out working copies of repositories.');
} }
protected function canAllocateLease( protected function canAllocateLease(

View file

@ -10,56 +10,75 @@ final class DrydockBlueprintCreateController
$implementations = $implementations =
DrydockBlueprintImplementation::getAllBlueprintImplementations(); DrydockBlueprintImplementation::getAllBlueprintImplementations();
$errors = array();
$e_blueprint = null;
if ($request->isFormPost()) { if ($request->isFormPost()) {
$class = $request->getStr('blueprint-type'); $class = $request->getStr('blueprint-type');
if (!isset($implementations[$class])) { if (!isset($implementations[$class])) {
return $this->createDialog($implementations); $e_blueprint = pht('Required');
$errors[] = pht('You must choose a blueprint type.');
} }
$blueprint = id(new DrydockBlueprint()) if (!$errors) {
->setClassName($class) $edit_uri = $this->getApplicationURI('blueprint/edit/?class='.$class);
->setDetails(array()) return id(new AphrontRedirectResponse())->setURI($edit_uri);
->setViewPolicy(PhabricatorPolicies::POLICY_ADMIN) }
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
->save();
$edit_uri = $this->getApplicationURI(
"blueprint/edit/".$blueprint->getID()."/");
return id(new AphrontRedirectResponse())->setURI($edit_uri);
} }
return $this->createDialog($implementations); $error_view = null;
} if ($errors) {
$error_view = id(new AphrontErrorView())
function createDialog(array $implementations) { ->setErrors($errors);
$request = $this->getRequest(); }
$viewer = $request->getUser();
$control = id(new AphrontFormRadioButtonControl()) $control = id(new AphrontFormRadioButtonControl())
->setName('blueprint-type'); ->setName('blueprint-type')
->setLabel(pht('Blueprint Type'))
->setError($e_blueprint);
foreach ($implementations as $implementation_name => $implementation) { foreach ($implementations as $implementation_name => $implementation) {
$control $disabled = !$implementation->isEnabled();
->addButton(
$implementation_name, $control->addButton(
$implementation->getBlueprintClass(), $implementation_name,
$implementation->getDescription()); $implementation->getBlueprintName(),
array(
pht('Provides: %s', $implementation->getType()),
phutil_tag('br'),
phutil_tag('br'),
$implementation->getDescription(),
),
$disabled ? 'disabled' : null,
$disabled);
} }
$dialog = new AphrontDialogView(); $title = pht('Create New Blueprint');
$dialog->setTitle(pht('Create New Blueprint')) $crumbs = $this->buildApplicationCrumbs();
->setUser($viewer) $crumbs->addTextCrumb(pht('New Blueprint'));
->addSubmitButton(pht('Create Blueprint'))
->addCancelButton($this->getApplicationURI('blueprint/')); $form = id(new AphrontFormView())
$dialog->appendChild( ->setUser($viewer)
phutil_tag( ->appendChild($control)
'p', ->appendChild(
array(), id(new AphrontFormSubmitControl())
pht( ->addCancelButton($this->getApplicationURI('blueprint/'))
'Select what type of blueprint you want to create: '))); ->setValue(pht('Continue')));
$dialog->appendChild($control);
return id(new AphrontDialogResponse())->setDialog($dialog); $box = id(new PHUIObjectBoxView())
->setFormError($error_view)
->setHeaderText($title)
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$box,
),
array(
'title' => $title,
'device' => true,
));
} }
} }

View file

@ -25,10 +25,23 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
if (!$blueprint) { if (!$blueprint) {
return new Aphront404Response(); return new Aphront404Response();
} }
$impl = $blueprint->getImplementation();
$cancel_uri = $this->getApplicationURI('blueprint/'.$this->id.'/');
} else { } else {
$class = $request->getStr('class');
$impl = DrydockBlueprintImplementation::getNamedImplementation($class);
if (!$impl || !$impl->isEnabled()) {
return new Aphront400Response();
}
$blueprint = new DrydockBlueprint(); $blueprint = new DrydockBlueprint();
$blueprint->setClassName($class);
$cancel_uri = $this->getApplicationURI('blueprint/');
} }
if ($request->isFormPost()) { if ($request->isFormPost()) {
$v_view_policy = $request->getStr('viewPolicy'); $v_view_policy = $request->getStr('viewPolicy');
$v_edit_policy = $request->getStr('editPolicy'); $v_edit_policy = $request->getStr('editPolicy');
@ -39,8 +52,10 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$blueprint->save(); $blueprint->save();
return id(new AphrontRedirectResponse()) $id = $blueprint->getID();
->setURI('/drydock/blueprint/'); $save_uri = $this->getApplicationURI("blueprint/{$id}/");
return id(new AphrontRedirectResponse())->setURI($save_uri);
} }
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
@ -48,21 +63,13 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
->setObject($blueprint) ->setObject($blueprint)
->execute(); ->execute();
if ($request->isAjax()) { $form = id(new AphrontFormView())
$form = id(new PHUIFormLayoutView()) ->setUser($viewer)
->setUser($viewer); ->addHiddenInput('class', $request->getStr('class'))
} else {
$form = id(new AphrontFormView())
->setUser($viewer);
}
$form
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormStaticControl())
->setName('className') ->setLabel(pht('Blueprint Type'))
->setLabel(pht('Implementation')) ->setValue($impl->getBlueprintName()))
->setValue($blueprint->getClassName())
->setDisabled(true))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setName('viewPolicy') ->setName('viewPolicy')
@ -78,27 +85,23 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$title = pht('Edit Blueprint'); if ($blueprint->getID()) {
$header = pht('Edit Blueprint %d', $blueprint->getID()); $title = pht('Edit Blueprint');
$crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID())); $header = pht('Edit Blueprint %d', $blueprint->getID());
$crumbs->addTextCrumb(pht('Edit')); $crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID()));
$crumbs->addTextCrumb(pht('Edit'));
if ($request->isAjax()) { $submit = pht('Save Blueprint');
$dialog = id(new AphrontDialogView()) } else {
->setUser($viewer) $title = pht('New Blueprint');
->setWidth(AphrontDialogView::WIDTH_FORM) $header = pht('New Blueprint');
->setTitle($title) $crumbs->addTextCrumb(pht('New Blueprint'));
->appendChild($form) $submit = pht('Create Blueprint');
->addSubmitButton(pht('Edit Blueprint'))
->addCancelButton($this->getApplicationURI());
return id(new AphrontDialogResponse())->setDialog($dialog);
} }
$form->appendChild( $form->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Save')) ->setValue($submit)
->addCancelButton($this->getApplicationURI())); ->addCancelButton($cancel_uri));
$box = id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())
->setHeaderText($header) ->setHeaderText($header)

View file

@ -65,21 +65,28 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
} }
private function buildActionListView(DrydockBlueprint $blueprint) { private function buildActionListView(DrydockBlueprint $blueprint) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorActionListView()) $view = id(new PhabricatorActionListView())
->setUser($this->getRequest()->getUser()) ->setUser($viewer)
->setObjectURI($this->getRequest()->getRequestURI()) ->setObjectURI($this->getRequest()->getRequestURI())
->setObject($blueprint); ->setObject($blueprint);
$uri = '/blueprint/edit/'.$blueprint->getID().'/'; $uri = '/blueprint/edit/'.$blueprint->getID().'/';
$uri = $this->getApplicationURI($uri); $uri = $this->getApplicationURI($uri);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$blueprint,
PhabricatorPolicyCapability::CAN_EDIT);
$view->addAction( $view->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setHref($uri) ->setHref($uri)
->setName(pht('Edit Blueprint Policies')) ->setName(pht('Edit Blueprint'))
->setIcon('edit') ->setIcon('edit')
->setWorkflow(true) ->setWorkflow(!$can_edit)
->setDisabled(false)); ->setDisabled(!$can_edit));
return $view; return $view;
} }

View file

@ -33,7 +33,7 @@ final class HarbormasterStepAddController
if ($request->isDialogFormPost()) { if ($request->isDialogFormPost()) {
$class = $request->getStr('step-type'); $class = $request->getStr('step-type');
if (!in_array($class, $implementations)) { if (!in_array($class, $implementations)) {
return $this->createDialog($implementations); return $this->createDialog($implementations, $cancel_uri);
} }
$steps = $plan->loadOrderedBuildSteps(); $steps = $plan->loadOrderedBuildSteps();