Page MenuHomePhabricator

D13161.diff
No OneTemporary

D13161.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1138,6 +1138,7 @@
'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 @@
'NuanceQueue' => array(
'NuanceDAO',
'PhabricatorPolicyInterface',
+ 'PhabricatorApplicationTransactionInterface',
),
'NuanceQueueEditController' => 'NuanceController',
'NuanceQueueEditor' => 'PhabricatorApplicationTransactionEditor',
@@ -4481,6 +4483,7 @@
'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
--- a/src/applications/nuance/application/PhabricatorNuanceApplication.php
+++ b/src/applications/nuance/application/PhabricatorNuanceApplication.php
@@ -46,7 +46,8 @@
'source/' => array(
'view/(?P<id>[1-9]\d*)/' => 'NuanceSourceViewController',
'edit/(?P<id>[1-9]\d*)/' => 'NuanceSourceEditController',
- 'new/' => 'NuanceSourceEditController',
+ 'new/(?P<type>[^/]+)/' => 'NuanceSourceEditController',
+ 'create/' => 'NuanceSourceCreateController',
),
'queue/' => array(
'view/(?P<id>[1-9]\d*)/' => 'NuanceQueueViewController',
diff --git a/src/applications/nuance/controller/NuanceSourceCreateController.php b/src/applications/nuance/controller/NuanceSourceCreateController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/controller/NuanceSourceCreateController.php
@@ -0,0 +1,57 @@
+<?php
+
+final class NuanceSourceCreateController extends NuanceController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $can_edit = $this->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
--- 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();
+
+ $sources_uri = $this->getApplicationURI('source/');
- $source_id = $this->getSourceID();
+ $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 @@
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 @@
$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
--- 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 @@
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 @@
->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 @@
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 @@
}
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
--- a/src/applications/nuance/query/NuanceSourceQuery.php
+++ b/src/applications/nuance/query/NuanceSourceQuery.php
@@ -5,7 +5,6 @@
private $ids;
private $phids;
- private $creatorPHIDs;
private $types;
public function withIDs(array $ids) {
@@ -18,66 +17,52 @@
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();
-
- $where[] = $this->buildPagingClause($conn_r);
-
- if ($this->creatorPHIDs) {
- $where[] = qsprintf(
- $conn_r,
- 'creatorPHID IN (%Ls)',
- $this->creatorPHIDs);
- }
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
- if ($this->types) {
+ if ($this->types !== null) {
$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
--- a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
+++ b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
@@ -7,6 +7,10 @@
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
--- a/src/applications/nuance/source/NuanceSourceDefinition.php
+++ b/src/applications/nuance/source/NuanceSourceDefinition.php
@@ -9,9 +9,11 @@
$this->actor = $actor;
return $this;
}
+
public function getActor() {
return $this->actor;
}
+
public function requireActor() {
$actor = $this->getActor();
if (!$actor) {
@@ -25,9 +27,11 @@
$this->sourceObject = $source;
return $this;
}
+
public function getSourceObject() {
return $this->sourceObject;
}
+
public function requireSourceObject() {
$source = $this->getSourceObject();
if (!$source) {
@@ -36,19 +40,6 @@
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 @@
static $definitions;
if ($definitions === null) {
+ $definitions = array();
+
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
@@ -82,9 +75,10 @@
$conflict,
$name));
}
+ $definitions[$key] = $definition;
}
- $definitions = $objects;
}
+
return $definitions;
}
@@ -93,6 +87,12 @@
*/
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 @@
->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
--- a/src/applications/nuance/storage/NuanceSource.php
+++ b/src/applications/nuance/storage/NuanceSource.php
@@ -57,13 +57,9 @@
$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 @@
}
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 5:32 PM (13 h, 11 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6919192
Default Alt Text
D13161.diff (15 KB)

Event Timeline