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

Add names to Drydock blueprints

Summary:
Ref T2015. Adds human-readable names to Drydock blueprints.

Also the new patches stuff is so much nicer.

Test Plan: Edited, created, and reviewed migrated blueprints.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D7918
This commit is contained in:
epriestley 2014-01-09 10:56:34 -08:00
parent 68de639470
commit 962aca664f
7 changed files with 72 additions and 21 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_drydock.drydock_blueprint
ADD blueprintName VARCHAR(255) NOT NULL AFTER className;

View file

@ -0,0 +1,23 @@
<?php
echo "Adding names to Drydock blueprints.\n";
$table = new DrydockBlueprint();
$conn_w = $table->establishConnection('w');
$iterator = new LiskMigrationIterator($table);
foreach ($iterator as $blueprint) {
$id = $blueprint->getID();
echo "Populating blueprint {$id}...\n";
if (!strlen($blueprint->getBlueprintName())) {
queryfx(
$conn_w,
'UPDATE %T SET blueprintName = %s WHERE id = %d',
$table->getTableName(),
pht('Blueprint %s', $id),
$id);
}
}
echo "Done.\n";

View file

@ -8,7 +8,7 @@ final class DrydockPreallocatedHostBlueprintImplementation
} }
public function getBlueprintName() { public function getBlueprintName() {
return pht('Remote Host (Preallocated)'); return pht('Preallocated Remote Hosts');
} }
public function getDescription() { public function getDescription() {

View file

@ -36,20 +36,30 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
return new Aphront400Response(); return new Aphront400Response();
} }
$blueprint = new DrydockBlueprint(); $blueprint = DrydockBlueprint::initializeNewBlueprint($viewer);
$blueprint->setClassName($class); $blueprint->setClassName($class);
$cancel_uri = $this->getApplicationURI('blueprint/'); $cancel_uri = $this->getApplicationURI('blueprint/');
} }
$v_name = $blueprint->getBlueprintName();
$e_name = true;
$errors = array();
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');
$v_name = $request->getStr('name');
if (!strlen($v_name)) {
$e_name = pht('Required');
$errors[] = pht('You must name this blueprint.');
}
// TODO: Should we use transactions here? // TODO: We should use transactions here.
$blueprint->setViewPolicy($v_view_policy); $blueprint->setViewPolicy($v_view_policy);
$blueprint->setEditPolicy($v_edit_policy); $blueprint->setEditPolicy($v_edit_policy);
$blueprint->setBlueprintName($v_name);
if (!$errors) {
$blueprint->save(); $blueprint->save();
$id = $blueprint->getID(); $id = $blueprint->getID();
@ -57,6 +67,12 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
return id(new AphrontRedirectResponse())->setURI($save_uri); return id(new AphrontRedirectResponse())->setURI($save_uri);
} }
}
$error_view = null;
if ($errors) {
$error_view = id(new AphrontErrorView())->setErrors($errors);
}
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -66,6 +82,12 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($viewer) ->setUser($viewer)
->addHiddenInput('class', $request->getStr('class')) ->addHiddenInput('class', $request->getStr('class'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setName('name')
->setValue($v_name)
->setError($e_name))
->appendChild( ->appendChild(
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel(pht('Blueprint Type')) ->setLabel(pht('Blueprint Type'))
@ -105,6 +127,7 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$box = id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())
->setHeaderText($header) ->setHeaderText($header)
->setFormError($error_view)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->buildApplicationPage(

View file

@ -33,19 +33,15 @@ final class DrydockBlueprintListController extends DrydockBlueprintController
foreach ($blueprints as $blueprint) { foreach ($blueprints as $blueprint) {
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setHeader($blueprint->getClassName()) ->setHeader($blueprint->getBlueprintName())
->setHref($this->getApplicationURI('/blueprint/'.$blueprint->getID())) ->setHref($this->getApplicationURI('/blueprint/'.$blueprint->getID()))
->setObjectName(pht('Blueprint %d', $blueprint->getID())); ->setObjectName(pht('Blueprint %d', $blueprint->getID()));
if ($blueprint->getImplementation()->isEnabled()) { if (!$blueprint->getImplementation()->isEnabled()) {
$item->addAttribute(pht('Enabled')); $item->setDisabled(true);
$item->setBarColor('green');
} else {
$item->addAttribute(pht('Disabled'));
$item->setBarColor('red');
} }
$item->addAttribute($blueprint->getImplementation()->getDescription()); $item->addAttribute($blueprint->getImplementation()->getBlueprintName());
$view->addItem($item); $view->addItem($item);
} }

View file

@ -20,10 +20,12 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
return new Aphront404Response(); return new Aphront404Response();
} }
$title = 'Blueprint '.$blueprint->getID().' '.$blueprint->getClassName(); $title = $blueprint->getBlueprintName();
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($title); ->setHeader($title)
->setUser($viewer)
->setPolicyObject($blueprint);
$actions = $this->buildActionListView($blueprint); $actions = $this->buildActionListView($blueprint);
$properties = $this->buildPropertyListView($blueprint, $actions); $properties = $this->buildPropertyListView($blueprint, $actions);
@ -99,8 +101,8 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
$view->setActionList($actions); $view->setActionList($actions);
$view->addProperty( $view->addProperty(
pht('Implementation'), pht('Type'),
$blueprint->getClassName()); $blueprint->getImplementation()->getBlueprintName());
return $view; return $view;
} }

View file

@ -3,14 +3,19 @@
final class DrydockBlueprint extends DrydockDAO final class DrydockBlueprint extends DrydockDAO
implements PhabricatorPolicyInterface { implements PhabricatorPolicyInterface {
protected $phid;
protected $className; protected $className;
protected $blueprintName;
protected $viewPolicy; protected $viewPolicy;
protected $editPolicy; protected $editPolicy;
protected $details; protected $details = array();
private $implementation = self::ATTACHABLE; private $implementation = self::ATTACHABLE;
public static function initializeNewBlueprint(PhabricatorUser $actor) {
return id(new DrydockBlueprint())
->setBlueprintName('');
}
public function getConfiguration() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,