mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 14:30:56 +01:00
Slightly modernize NuanceSource
Summary: Ref T8434. Minor cleanup/modernization. I made type selection modal (like Herald, Auth, etc) so we can render the form on the next screen based on the type. {F472519} Test Plan: Created a new source, edited an existing source. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8434 Differential Revision: https://secure.phabricator.com/D13161
This commit is contained in:
parent
1f65a50f04
commit
837e6b5ca7
9 changed files with 145 additions and 113 deletions
|
@ -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',
|
||||
|
|
|
@ -46,7 +46,8 @@ final class PhabricatorNuanceApplication extends PhabricatorApplication {
|
|||
'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',
|
||||
|
|
|
@ -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'),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue