diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 4b078a54b3..9034cf434c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1138,6 +1138,7 @@ phutil_register_library_map(array( 'NuanceRequestorViewController' => 'applications/nuance/controller/NuanceRequestorViewController.php', 'NuanceSchemaSpec' => 'applications/nuance/storage/NuanceSchemaSpec.php', 'NuanceSource' => 'applications/nuance/storage/NuanceSource.php', + 'NuanceSourceCreateController' => 'applications/nuance/controller/NuanceSourceCreateController.php', 'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php', 'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php', 'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php', @@ -4455,6 +4456,7 @@ phutil_register_library_map(array( 'NuanceQueue' => array( 'NuanceDAO', 'PhabricatorPolicyInterface', + 'PhabricatorApplicationTransactionInterface', ), 'NuanceQueueEditController' => 'NuanceController', 'NuanceQueueEditor' => 'PhabricatorApplicationTransactionEditor', @@ -4481,6 +4483,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', ), + 'NuanceSourceCreateController' => 'NuanceController', 'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability', 'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability', 'NuanceSourceDefinition' => 'Phobject', diff --git a/src/applications/nuance/application/PhabricatorNuanceApplication.php b/src/applications/nuance/application/PhabricatorNuanceApplication.php index 31f06c4b64..617499c7bc 100644 --- a/src/applications/nuance/application/PhabricatorNuanceApplication.php +++ b/src/applications/nuance/application/PhabricatorNuanceApplication.php @@ -46,7 +46,8 @@ final class PhabricatorNuanceApplication extends PhabricatorApplication { 'source/' => array( 'view/(?P[1-9]\d*)/' => 'NuanceSourceViewController', 'edit/(?P[1-9]\d*)/' => 'NuanceSourceEditController', - 'new/' => 'NuanceSourceEditController', + 'new/(?P[^/]+)/' => 'NuanceSourceEditController', + 'create/' => 'NuanceSourceCreateController', ), 'queue/' => array( 'view/(?P[1-9]\d*)/' => 'NuanceQueueViewController', diff --git a/src/applications/nuance/controller/NuanceSourceCreateController.php b/src/applications/nuance/controller/NuanceSourceCreateController.php new file mode 100644 index 0000000000..22dd41024c --- /dev/null +++ b/src/applications/nuance/controller/NuanceSourceCreateController.php @@ -0,0 +1,57 @@ +requireApplicationCapability( + NuanceSourceManageCapability::CAPABILITY); + + $viewer = $this->getViewer(); + $map = NuanceSourceDefinition::getAllDefinitions(); + $cancel_uri = $this->getApplicationURI('source/'); + + if ($request->isFormPost()) { + $type = $request->getStr('type'); + if (isset($map[$type])) { + $uri = $this->getApplicationURI('source/new/'.$type.'/'); + return id(new AphrontRedirectResponse())->setURI($uri); + } + } + + $source_types = id(new AphrontFormRadioButtonControl()) + ->setName('type') + ->setLabel(pht('Source Type')); + + foreach ($map as $type => $definition) { + $source_types->addButton( + $type, + $definition->getName(), + $definition->getSourceDescription()); + } + + $form = id(new AphrontFormView()) + ->setUser($viewer) + ->appendChild($source_types) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue(pht('Continue')) + ->addCancelButton($cancel_uri)); + + $box = id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Choose Source Type')) + ->appendChild($form); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Sources'), $cancel_uri); + $crumbs->addTextCrumb(pht('New')); + + return $this->buildApplicationPage( + array( + $crumbs, + $box, + ), + array( + 'title' => pht('Choose Source Type'), + )); + } +} diff --git a/src/applications/nuance/controller/NuanceSourceEditController.php b/src/applications/nuance/controller/NuanceSourceEditController.php index 7b4f20ba67..79bc8c94dc 100644 --- a/src/applications/nuance/controller/NuanceSourceEditController.php +++ b/src/applications/nuance/controller/NuanceSourceEditController.php @@ -2,35 +2,32 @@ final class NuanceSourceEditController extends NuanceController { - private $sourceID; - - public function setSourceID($source_id) { - $this->sourceID = $source_id; - return $this; - } - public function getSourceID() { - return $this->sourceID; - } - - public function willProcessRequest(array $data) { - $this->setSourceID(idx($data, 'id')); - } - - public function processRequest() { + public function handleRequest(AphrontRequest $request) { $can_edit = $this->requireApplicationCapability( NuanceSourceManageCapability::CAPABILITY); - $request = $this->getRequest(); - $user = $request->getUser(); + $viewer = $this->getViewer(); - $source_id = $this->getSourceID(); + $sources_uri = $this->getApplicationURI('source/'); + + $source_id = $request->getURIData('id'); $is_new = !$source_id; if ($is_new) { - $source = NuanceSource::initializeNewSource($user); + $source = NuanceSource::initializeNewSource($viewer); + + $type = $request->getURIData('type'); + $map = NuanceSourceDefinition::getAllDefinitions(); + + if (empty($map[$type])) { + return new Aphront404Response(); + } + + $source->setType($type); + $cancel_uri = $sources_uri; } else { $source = id(new NuanceSourceQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withIDs(array($source_id)) ->requireCapabilities( array( @@ -38,14 +35,14 @@ final class NuanceSourceEditController extends NuanceController { PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); - } - - if (!$source) { - return new Aphront404Response(); + if (!$source) { + return new Aphront404Response(); + } + $cancel_uri = $source->getURI(); } $definition = NuanceSourceDefinition::getDefinitionForSource($source); - $definition->setActor($user); + $definition->setActor($viewer); $response = $definition->buildEditLayout($request); if ($response instanceof AphrontResponse) { @@ -54,6 +51,15 @@ final class NuanceSourceEditController extends NuanceController { $layout = $response; $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Sources'), $sources_uri); + + if ($is_new) { + $crumbs->addTextCrumb(pht('New')); + } else { + $crumbs->addTextCrumb($source->getName(), $cancel_uri); + $crumbs->addTextCrumb(pht('Edit')); + } + return $this->buildApplicationPage( array( $crumbs, diff --git a/src/applications/nuance/controller/NuanceSourceViewController.php b/src/applications/nuance/controller/NuanceSourceViewController.php index 60487582d1..edff9fb0a1 100644 --- a/src/applications/nuance/controller/NuanceSourceViewController.php +++ b/src/applications/nuance/controller/NuanceSourceViewController.php @@ -2,30 +2,13 @@ final class NuanceSourceViewController extends NuanceController { - private $sourceID; + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); - public function setSourceID($source_id) { - $this->sourceID = $source_id; - return $this; - } - public function getSourceID() { - return $this->sourceID; - } - - public function willProcessRequest(array $data) { - $this->setSourceID($data['id']); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - $source_id = $this->getSourceID(); $source = id(new NuanceSourceQuery()) ->setViewer($viewer) - ->withIDs(array($source_id)) + ->withIDs(array($request->getURIData('id'))) ->executeOne(); - if (!$source) { return new Aphront404Response(); } @@ -37,10 +20,6 @@ final class NuanceSourceViewController extends NuanceController { new NuanceSourceTransactionQuery()); $timeline->setShouldTerminate(true); - $title = pht('%s', $source->getName()); - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb($title); - $header = $this->buildHeaderView($source); $actions = $this->buildActionView($source); $properties = $this->buildPropertyView($source, $actions); @@ -49,6 +28,12 @@ final class NuanceSourceViewController extends NuanceController { ->setHeader($header) ->addPropertyList($properties); + $title = $source->getName(); + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Sources'), $this->getApplicationURI('source/')); + + $crumbs->addTextCrumb($title); + return $this->buildApplicationPage( array( $crumbs, @@ -58,12 +43,10 @@ final class NuanceSourceViewController extends NuanceController { array( 'title' => $title, )); - } - - private function buildHeaderView(NuanceSource $source) { - $viewer = $this->getRequest()->getUser(); + private function buildHeaderView(NuanceSource $source) { + $viewer = $this->getViewer(); $header = id(new PHUIHeaderView()) ->setUser($viewer) @@ -74,7 +57,7 @@ final class NuanceSourceViewController extends NuanceController { } private function buildActionView(NuanceSource $source) { - $viewer = $this->getRequest()->getUser(); + $viewer = $this->getViewer(); $id = $source->getID(); $actions = id(new PhabricatorActionListView()) diff --git a/src/applications/nuance/query/NuanceSourceQuery.php b/src/applications/nuance/query/NuanceSourceQuery.php index 77421656e7..ee4b964ee3 100644 --- a/src/applications/nuance/query/NuanceSourceQuery.php +++ b/src/applications/nuance/query/NuanceSourceQuery.php @@ -5,7 +5,6 @@ final class NuanceSourceQuery private $ids; private $phids; - private $creatorPHIDs; private $types; public function withIDs(array $ids) { @@ -18,66 +17,52 @@ final class NuanceSourceQuery return $this; } - public function withCreatorPHIDs(array $phids) { - $this->CreatorPHIDs = $phids; - return $this; - } - public function withTypes($types) { $this->types = $types; return $this; } - protected function loadPage() { $table = new NuanceSource(); - $conn_r = $table->establishConnection('r'); + $conn = $table->establishConnection('r'); $data = queryfx_all( - $conn_r, - 'SELECT * FROM %T %Q %Q %Q', + $conn, + '%Q FROM %T %Q %Q %Q', + $this->buildSelectClause($conn), $table->getTableName(), - $this->buildWhereClause($conn_r), - $this->buildOrderClause($conn_r), - $this->buildLimitClause($conn_r)); + $this->buildWhereClause($conn), + $this->buildOrderClause($conn), + $this->buildLimitClause($conn)); return $table->loadAllFromArray($data); } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); - $where[] = $this->buildPagingClause($conn_r); - - if ($this->creatorPHIDs) { + if ($this->types !== null) { $where[] = qsprintf( - $conn_r, - 'creatorPHID IN (%Ls)', - $this->creatorPHIDs); - } - - if ($this->types) { - $where[] = qsprintf( - $conn_r, - 'type IN (%Ld)', + $conn, + 'type IN (%Ls)', $this->types); } - if ($this->ids) { + if ($this->ids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'id IN (%Ld)', $this->ids); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'phid IN (%Ls)', $this->phids); } - return $this->formatWhereClause($where); + return $where; } } diff --git a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php index 1d49b17c55..f6e709eb5b 100644 --- a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php +++ b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php @@ -7,6 +7,10 @@ final class NuancePhabricatorFormSourceDefinition return pht('Phabricator Form'); } + public function getSourceDescription() { + return pht('Create a web form that submits into a Nuance queue.'); + } + public function getSourceTypeConstant() { return 'phabricator-form'; } diff --git a/src/applications/nuance/source/NuanceSourceDefinition.php b/src/applications/nuance/source/NuanceSourceDefinition.php index b2092dfdff..8b26976f9f 100644 --- a/src/applications/nuance/source/NuanceSourceDefinition.php +++ b/src/applications/nuance/source/NuanceSourceDefinition.php @@ -9,9 +9,11 @@ abstract class NuanceSourceDefinition extends Phobject { $this->actor = $actor; return $this; } + public function getActor() { return $this->actor; } + public function requireActor() { $actor = $this->getActor(); if (!$actor) { @@ -25,9 +27,11 @@ abstract class NuanceSourceDefinition extends Phobject { $this->sourceObject = $source; return $this; } + public function getSourceObject() { return $this->sourceObject; } + public function requireSourceObject() { $source = $this->getSourceObject(); if (!$source) { @@ -36,19 +40,6 @@ abstract class NuanceSourceDefinition extends Phobject { return $source; } - public static function getSelectOptions() { - $definitions = self::getAllDefinitions(); - - $options = array(); - foreach ($definitions as $definition) { - $key = $definition->getSourceTypeConstant(); - $name = $definition->getName(); - $options[$key] = $name; - } - - return $options; - } - /** * Gives a @{class:NuanceSourceDefinition} object for a given * @{class:NuanceSource}. Note you still need to @{method:setActor} @@ -67,6 +58,8 @@ abstract class NuanceSourceDefinition extends Phobject { static $definitions; if ($definitions === null) { + $definitions = array(); + $objects = id(new PhutilSymbolLoader()) ->setAncestorClass(__CLASS__) ->loadObjects(); @@ -82,9 +75,10 @@ abstract class NuanceSourceDefinition extends Phobject { $conflict, $name)); } + $definitions[$key] = $definition; } - $definitions = $objects; } + return $definitions; } @@ -93,6 +87,12 @@ abstract class NuanceSourceDefinition extends Phobject { */ abstract public function getName(); + + /** + * Human readable description of this source, a sentence or two long. + */ + abstract public function getSourceDescription(); + /** * This should be a any VARCHAR(32). * @@ -193,13 +193,7 @@ abstract class NuanceSourceDefinition extends Phobject { ->setLabel(pht('Name')) ->setName('name') ->setError($e_name) - ->setValue($source->getName())) - ->appendChild( - id(new AphrontFormSelectControl()) - ->setLabel(pht('Type')) - ->setName('type') - ->setOptions(self::getSelectOptions()) - ->setValue($source->getType())); + ->setValue($source->getName())); $form = $this->augmentEditForm($form, $ex); diff --git a/src/applications/nuance/storage/NuanceSource.php b/src/applications/nuance/storage/NuanceSource.php index 423f70fd76..01f0d6e620 100644 --- a/src/applications/nuance/storage/NuanceSource.php +++ b/src/applications/nuance/storage/NuanceSource.php @@ -57,13 +57,9 @@ final class NuanceSource extends NuanceDAO $edit_policy = $app->getPolicy( NuanceSourceDefaultEditCapability::CAPABILITY); - $definitions = NuanceSourceDefinition::getAllDefinitions(); - $lucky_definition = head($definitions); - return id(new NuanceSource()) ->setViewPolicy($view_policy) - ->setEditPolicy($edit_policy) - ->setType($lucky_definition->getSourceTypeConstant()); + ->setEditPolicy($edit_policy); } @@ -90,6 +86,9 @@ final class NuanceSource extends NuanceDAO } +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW,