1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00

Slightly modernize NuanceQueue

Summary: Ref T8434. Touch things up a bit. This also cleans up the missing ApplicationTransactionInterface for T6367.

Test Plan: Didn't create a new queue. Didn't edit an existing queue.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: jeremyb, epriestley

Maniphest Tasks: T8434

Differential Revision: https://secure.phabricator.com/D13160
This commit is contained in:
epriestley 2015-06-05 10:43:37 -07:00
parent ef90007a21
commit 1f65a50f04
3 changed files with 67 additions and 43 deletions

View file

@ -2,43 +2,36 @@
final class NuanceQueueEditController extends NuanceController { final class NuanceQueueEditController extends NuanceController {
private $queueID; public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
public function setQueueID($queue_id) { $queue_id = $request->getURIData('id');
$this->queueID = $queue_id;
return $this;
}
public function getQueueID() {
return $this->queueID;
}
public function willProcessRequest(array $data) {
$this->setQueueID(idx($data, 'id'));
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$queue_id = $this->getQueueID();
$is_new = !$queue_id; $is_new = !$queue_id;
if ($is_new) { if ($is_new) {
$queue = new NuanceQueue(); $queue = NuanceQueue::initializeNewQueue();
} else { } else {
$queue = id(new NuanceQueueQuery()) $queue = id(new NuanceQueueQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($queue_id)) ->withIDs(array($queue_id))
->executeOne(); ->executeOne();
} if (!$queue) {
return new Aphront404Response();
if (!$queue) { }
return new Aphront404Response();
} }
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$title = 'TODO'; $crumbs->addTextCrumb(
pht('Queues'),
$this->getApplicationURI('queue/'));
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'));
}
return $this->buildApplicationPage( return $this->buildApplicationPage(
$crumbs, $crumbs,

View file

@ -18,39 +18,38 @@ final class NuanceQueueQuery
protected function loadPage() { protected function loadPage() {
$table = new NuanceQueue(); $table = new NuanceQueue();
$conn_r = $table->establishConnection('r'); $conn = $table->establishConnection('r');
$data = queryfx_all( $data = queryfx_all(
$conn_r, $conn,
'SELECT FROM %T %Q %Q %Q', '%Q FROM %T %Q %Q %Q',
$this->buildSelectClause($conn),
$table->getTableName(), $table->getTableName(),
$this->buildWhereClause($conn_r), $this->buildWhereClause($conn),
$this->buildOrderClause($conn_r), $this->buildOrderClause($conn),
$this->buildLimitClause($conn_r)); $this->buildLimitClause($conn));
return $table->loadAllFromArray($data); return $table->loadAllFromArray($data);
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
$where[] = $this->buildPagingClause($conn_r); if ($this->ids !== null) {
if ($this->ids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'id IN (%Ld)', 'id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
return $this->formatWhereClause($where); return $where;
} }
} }

View file

@ -2,7 +2,9 @@
final class NuanceQueue final class NuanceQueue
extends NuanceDAO extends NuanceDAO
implements PhabricatorPolicyInterface { implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface {
protected $name; protected $name;
protected $mailKey; protected $mailKey;
@ -24,6 +26,10 @@ final class NuanceQueue
NuanceQueuePHIDType::TYPECONST); NuanceQueuePHIDType::TYPECONST);
} }
public static function initializeNewQueue() {
return new NuanceQueue();
}
public function save() { public function save() {
if (!$this->getMailKey()) { if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20)); $this->setMailKey(Filesystem::readRandomCharacters(20));
@ -35,6 +41,10 @@ final class NuanceQueue
return '/nuance/queue/view/'.$this->getID().'/'; return '/nuance/queue/view/'.$this->getID().'/';
} }
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() { public function getCapabilities() {
return array( return array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -59,4 +69,26 @@ final class NuanceQueue
return null; return null;
} }
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new NuanceQueueEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new NuanceQueueTransaction();
}
public function willRenderTimeline(
PhabricatorApplicationTransactionView $timeline,
AphrontRequest $request) {
return $timeline;
}
} }