mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Move Nuance Queues to EditEngine
Summary: Ref T10537. Update queue editing to use EditEngine. Test Plan: - Created a new queue. - Edited an existing queue. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10537 Differential Revision: https://secure.phabricator.com/D15431
This commit is contained in:
parent
6872b96808
commit
86768737c5
7 changed files with 96 additions and 143 deletions
|
@ -1436,6 +1436,7 @@ phutil_register_library_map(array(
|
|||
'NuanceQueueController' => 'applications/nuance/controller/NuanceQueueController.php',
|
||||
'NuanceQueueDatasource' => 'applications/nuance/typeahead/NuanceQueueDatasource.php',
|
||||
'NuanceQueueEditController' => 'applications/nuance/controller/NuanceQueueEditController.php',
|
||||
'NuanceQueueEditEngine' => 'applications/nuance/editor/NuanceQueueEditEngine.php',
|
||||
'NuanceQueueEditor' => 'applications/nuance/editor/NuanceQueueEditor.php',
|
||||
'NuanceQueueListController' => 'applications/nuance/controller/NuanceQueueListController.php',
|
||||
'NuanceQueuePHIDType' => 'applications/nuance/phid/NuanceQueuePHIDType.php',
|
||||
|
@ -5683,6 +5684,7 @@ phutil_register_library_map(array(
|
|||
'NuanceQueueController' => 'NuanceController',
|
||||
'NuanceQueueDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'NuanceQueueEditController' => 'NuanceQueueController',
|
||||
'NuanceQueueEditEngine' => 'PhabricatorEditEngine',
|
||||
'NuanceQueueEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'NuanceQueueListController' => 'NuanceQueueController',
|
||||
'NuanceQueuePHIDType' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -45,16 +45,16 @@ final class PhabricatorNuanceApplication extends PhabricatorApplication {
|
|||
'new/' => 'NuanceItemEditController',
|
||||
),
|
||||
'source/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'NuanceSourceListController',
|
||||
$this->getQueryRoutePattern() => 'NuanceSourceListController',
|
||||
'view/(?P<id>[1-9]\d*)/' => 'NuanceSourceViewController',
|
||||
'edit/(?P<id>[1-9]\d*)/' => 'NuanceSourceEditController',
|
||||
'new/(?P<type>[^/]+)/' => 'NuanceSourceEditController',
|
||||
'create/' => 'NuanceSourceCreateController',
|
||||
),
|
||||
'queue/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'NuanceQueueListController',
|
||||
$this->getQueryRoutePattern() => 'NuanceQueueListController',
|
||||
$this->getEditRoutePattern('edit/') => 'NuanceQueueEditController',
|
||||
'view/(?P<id>[1-9]\d*)/' => 'NuanceQueueViewController',
|
||||
'edit/(?P<id>[1-9]\d*)/' => 'NuanceQueueEditController',
|
||||
'new/' => 'NuanceQueueEditController',
|
||||
),
|
||||
'requestor/' => array(
|
||||
|
|
|
@ -4,133 +4,9 @@ final class NuanceQueueEditController
|
|||
extends NuanceQueueController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$queues_uri = $this->getApplicationURI('queue/');
|
||||
|
||||
$queue_id = $request->getURIData('id');
|
||||
$is_new = !$queue_id;
|
||||
if ($is_new) {
|
||||
$queue = NuanceQueue::initializeNewQueue();
|
||||
$cancel_uri = $queues_uri;
|
||||
} else {
|
||||
$queue = id(new NuanceQueueQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($queue_id))
|
||||
->executeOne();
|
||||
if (!$queue) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
$cancel_uri = $queue->getURI();
|
||||
}
|
||||
|
||||
$v_name = $queue->getName();
|
||||
$e_name = true;
|
||||
$v_edit = $queue->getEditPolicy();
|
||||
$v_view = $queue->getViewPolicy();
|
||||
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$e_name = null;
|
||||
|
||||
$v_name = $request->getStr('name');
|
||||
$v_edit = $request->getStr('editPolicy');
|
||||
$v_view = $request->getStr('viewPolicy');
|
||||
|
||||
$type_name = NuanceQueueTransaction::TYPE_NAME;
|
||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(new NuanceQueueTransaction())
|
||||
->setTransactionType($type_name)
|
||||
->setNewValue($v_name);
|
||||
|
||||
$xactions[] = id(new NuanceQueueTransaction())
|
||||
->setTransactionType($type_view)
|
||||
->setNewValue($v_view);
|
||||
|
||||
$xactions[] = id(new NuanceQueueTransaction())
|
||||
->setTransactionType($type_edit)
|
||||
->setNewValue($v_edit);
|
||||
|
||||
$editor = id(new NuanceQueueEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true);
|
||||
|
||||
try {
|
||||
|
||||
$editor->applyTransactions($queue, $xactions);
|
||||
|
||||
$uri = $queue->getURI();
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
|
||||
$e_name = $ex->getShortMessage($type_name);
|
||||
}
|
||||
}
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(pht('Queues'), $queues_uri);
|
||||
|
||||
if ($is_new) {
|
||||
$title = pht('Create Queue');
|
||||
$crumbs->addTextCrumb(pht('Create'));
|
||||
} else {
|
||||
$title = pht('Edit %s', $queue->getName());
|
||||
$crumbs->addTextCrumb($queue->getName(), $queue->getURI());
|
||||
$crumbs->addTextCrumb(pht('Edit'));
|
||||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($queue)
|
||||
->execute();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Name'))
|
||||
->setName('name')
|
||||
->setError($e_name)
|
||||
->setValue($v_name))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($queue)
|
||||
->setPolicies($policies)
|
||||
->setValue($v_view)
|
||||
->setName('viewPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($queue)
|
||||
->setPolicies($policies)
|
||||
->setValue($v_edit)
|
||||
->setName('editPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue(pht('Save')));
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->setValidationException($validation_exception)
|
||||
->appendChild($form);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$box,
|
||||
),
|
||||
array(
|
||||
'title' => $title,
|
||||
));
|
||||
return id(new NuanceQueueEditEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
80
src/applications/nuance/editor/NuanceQueueEditEngine.php
Normal file
80
src/applications/nuance/editor/NuanceQueueEditEngine.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
final class NuanceQueueEditEngine
|
||||
extends PhabricatorEditEngine {
|
||||
|
||||
const ENGINECONST = 'nuance.queue';
|
||||
|
||||
public function isEngineConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Nuance Queues');
|
||||
}
|
||||
|
||||
public function getSummaryHeader() {
|
||||
return pht('Edit Nuance Queue Configurations');
|
||||
}
|
||||
|
||||
public function getSummaryText() {
|
||||
return pht('This engine is used to edit Nuance queues.');
|
||||
}
|
||||
|
||||
public function getEngineApplicationClass() {
|
||||
return 'PhabricatorNuanceApplication';
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
return NuanceQueue::initializeNewQueue();
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return new NuanceQueueQuery();
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
return pht('Create Queue');
|
||||
}
|
||||
|
||||
protected function getObjectCreateButtonText($object) {
|
||||
return pht('Create Queue');
|
||||
}
|
||||
|
||||
protected function getObjectEditTitleText($object) {
|
||||
return pht('Edit Queue: %s', $object->getName());
|
||||
}
|
||||
|
||||
protected function getObjectEditShortText($object) {
|
||||
return pht('Edit Queue');
|
||||
}
|
||||
|
||||
protected function getObjectCreateShortText() {
|
||||
return pht('Create Queue');
|
||||
}
|
||||
|
||||
protected function getEditorURI() {
|
||||
return '/nuance/queue/edit/';
|
||||
}
|
||||
|
||||
protected function getObjectCreateCancelURI($object) {
|
||||
return '/nuance/queue/';
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
return $object->getURI();
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setDescription(pht('Name of the queue.'))
|
||||
->setTransactionType(NuanceQueueTransaction::TYPE_NAME)
|
||||
->setIsRequired(true)
|
||||
->setValue($object->getName()),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -68,6 +68,7 @@ final class NuanceQueueEditor
|
|||
|
||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
||||
}
|
||||
|
||||
protected function validateTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
$type,
|
||||
|
|
|
@ -27,7 +27,9 @@ final class NuanceQueue
|
|||
}
|
||||
|
||||
public static function initializeNewQueue() {
|
||||
return new NuanceQueue();
|
||||
return id(new self())
|
||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
|
|
|
@ -12,18 +12,6 @@ final class NuanceQueueTransaction extends NuanceTransaction {
|
|||
return new NuanceQueueTransactionComment();
|
||||
}
|
||||
|
||||
public function shouldHide() {
|
||||
$old = $this->getOldValue();
|
||||
$type = $this->getTransactionType();
|
||||
|
||||
switch ($type) {
|
||||
case self::TYPE_NAME:
|
||||
return ($old === null);
|
||||
}
|
||||
|
||||
return parent::shouldHide();
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
@ -32,6 +20,10 @@ final class NuanceQueueTransaction extends NuanceTransaction {
|
|||
$author_phid = $this->getAuthorPHID();
|
||||
|
||||
switch ($type) {
|
||||
case PhabricatorTransactions::TYPE_CREATE:
|
||||
return pht(
|
||||
'%s created this queue.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
case self::TYPE_NAME:
|
||||
return pht(
|
||||
'%s renamed this queue from "%s" to "%s".',
|
||||
|
|
Loading…
Reference in a new issue