From 962aca664f67dc0d1eb8eacb38d6c5e48d14959b Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 9 Jan 2014 10:56:34 -0800 Subject: [PATCH] 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 --- .../sql/autopatches/20140108.ddbpname.1.sql | 2 ++ .../sql/autopatches/20140108.ddbpname.2.php | 23 ++++++++++++ ...reallocatedHostBlueprintImplementation.php | 2 +- .../DrydockBlueprintEditController.php | 35 +++++++++++++++---- .../DrydockBlueprintListController.php | 12 +++---- .../DrydockBlueprintViewController.php | 10 +++--- .../drydock/storage/DrydockBlueprint.php | 9 +++-- 7 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 resources/sql/autopatches/20140108.ddbpname.1.sql create mode 100644 resources/sql/autopatches/20140108.ddbpname.2.php diff --git a/resources/sql/autopatches/20140108.ddbpname.1.sql b/resources/sql/autopatches/20140108.ddbpname.1.sql new file mode 100644 index 0000000000..3fe80875db --- /dev/null +++ b/resources/sql/autopatches/20140108.ddbpname.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_drydock.drydock_blueprint + ADD blueprintName VARCHAR(255) NOT NULL AFTER className; diff --git a/resources/sql/autopatches/20140108.ddbpname.2.php b/resources/sql/autopatches/20140108.ddbpname.2.php new file mode 100644 index 0000000000..ca7e3ef8b2 --- /dev/null +++ b/resources/sql/autopatches/20140108.ddbpname.2.php @@ -0,0 +1,23 @@ +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"; diff --git a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php index 554b969307..86a2b15d9d 100644 --- a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php +++ b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php @@ -8,7 +8,7 @@ final class DrydockPreallocatedHostBlueprintImplementation } public function getBlueprintName() { - return pht('Remote Host (Preallocated)'); + return pht('Preallocated Remote Hosts'); } public function getDescription() { diff --git a/src/applications/drydock/controller/DrydockBlueprintEditController.php b/src/applications/drydock/controller/DrydockBlueprintEditController.php index a749c317bd..aa3c5be4a0 100644 --- a/src/applications/drydock/controller/DrydockBlueprintEditController.php +++ b/src/applications/drydock/controller/DrydockBlueprintEditController.php @@ -36,26 +36,42 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { return new Aphront400Response(); } - $blueprint = new DrydockBlueprint(); + $blueprint = DrydockBlueprint::initializeNewBlueprint($viewer); $blueprint->setClassName($class); $cancel_uri = $this->getApplicationURI('blueprint/'); } + $v_name = $blueprint->getBlueprintName(); + $e_name = true; + $errors = array(); if ($request->isFormPost()) { $v_view_policy = $request->getStr('viewPolicy'); $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->setEditPolicy($v_edit_policy); + $blueprint->setBlueprintName($v_name); - $blueprint->save(); + if (!$errors) { + $blueprint->save(); - $id = $blueprint->getID(); - $save_uri = $this->getApplicationURI("blueprint/{$id}/"); + $id = $blueprint->getID(); + $save_uri = $this->getApplicationURI("blueprint/{$id}/"); - 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()) @@ -66,6 +82,12 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { $form = id(new AphrontFormView()) ->setUser($viewer) ->addHiddenInput('class', $request->getStr('class')) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel(pht('Name')) + ->setName('name') + ->setValue($v_name) + ->setError($e_name)) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel(pht('Blueprint Type')) @@ -105,6 +127,7 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { $box = id(new PHUIObjectBoxView()) ->setHeaderText($header) + ->setFormError($error_view) ->setForm($form); return $this->buildApplicationPage( diff --git a/src/applications/drydock/controller/DrydockBlueprintListController.php b/src/applications/drydock/controller/DrydockBlueprintListController.php index 7dd1cb12cb..bdc1953c69 100644 --- a/src/applications/drydock/controller/DrydockBlueprintListController.php +++ b/src/applications/drydock/controller/DrydockBlueprintListController.php @@ -33,19 +33,15 @@ final class DrydockBlueprintListController extends DrydockBlueprintController foreach ($blueprints as $blueprint) { $item = id(new PHUIObjectItemView()) - ->setHeader($blueprint->getClassName()) + ->setHeader($blueprint->getBlueprintName()) ->setHref($this->getApplicationURI('/blueprint/'.$blueprint->getID())) ->setObjectName(pht('Blueprint %d', $blueprint->getID())); - if ($blueprint->getImplementation()->isEnabled()) { - $item->addAttribute(pht('Enabled')); - $item->setBarColor('green'); - } else { - $item->addAttribute(pht('Disabled')); - $item->setBarColor('red'); + if (!$blueprint->getImplementation()->isEnabled()) { + $item->setDisabled(true); } - $item->addAttribute($blueprint->getImplementation()->getDescription()); + $item->addAttribute($blueprint->getImplementation()->getBlueprintName()); $view->addItem($item); } diff --git a/src/applications/drydock/controller/DrydockBlueprintViewController.php b/src/applications/drydock/controller/DrydockBlueprintViewController.php index 8526f42d9c..d9b22479a8 100644 --- a/src/applications/drydock/controller/DrydockBlueprintViewController.php +++ b/src/applications/drydock/controller/DrydockBlueprintViewController.php @@ -20,10 +20,12 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { return new Aphront404Response(); } - $title = 'Blueprint '.$blueprint->getID().' '.$blueprint->getClassName(); + $title = $blueprint->getBlueprintName(); $header = id(new PHUIHeaderView()) - ->setHeader($title); + ->setHeader($title) + ->setUser($viewer) + ->setPolicyObject($blueprint); $actions = $this->buildActionListView($blueprint); $properties = $this->buildPropertyListView($blueprint, $actions); @@ -99,8 +101,8 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { $view->setActionList($actions); $view->addProperty( - pht('Implementation'), - $blueprint->getClassName()); + pht('Type'), + $blueprint->getImplementation()->getBlueprintName()); return $view; } diff --git a/src/applications/drydock/storage/DrydockBlueprint.php b/src/applications/drydock/storage/DrydockBlueprint.php index 06f2375563..2e61e8e2db 100644 --- a/src/applications/drydock/storage/DrydockBlueprint.php +++ b/src/applications/drydock/storage/DrydockBlueprint.php @@ -3,14 +3,19 @@ final class DrydockBlueprint extends DrydockDAO implements PhabricatorPolicyInterface { - protected $phid; protected $className; + protected $blueprintName; protected $viewPolicy; protected $editPolicy; - protected $details; + protected $details = array(); private $implementation = self::ATTACHABLE; + public static function initializeNewBlueprint(PhabricatorUser $actor) { + return id(new DrydockBlueprint()) + ->setBlueprintName(''); + } + public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true,