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

Move Passphrase to SearchField

Summary: Prepares for bringing spaces and a new object policy here.

Test Plan: Used all search controls dozens of times.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D13384
This commit is contained in:
epriestley 2015-06-22 11:28:15 -07:00
parent 76194a0dc1
commit bc6d0478b4
2 changed files with 44 additions and 72 deletions

View file

@ -53,19 +53,12 @@ final class PassphraseCredentialQuery
return $this;
}
public function newResultObject() {
return new PassphraseCredential();
}
protected function loadPage() {
$table = new PassphraseCredential();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($rows);
return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $page) {
@ -99,61 +92,59 @@ final class PassphraseCredentialQuery
return $page;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
$where[] = $this->buildPagingClause($conn_r);
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);
}
if ($this->credentialTypes) {
if ($this->credentialTypes !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'credentialType in (%Ls)',
$this->credentialTypes);
}
if ($this->providesTypes) {
if ($this->providesTypes !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'providesType IN (%Ls)',
$this->providesTypes);
}
if ($this->isDestroyed !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'isDestroyed = %d',
(int)$this->isDestroyed);
}
if ($this->allowConduit !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'allowConduit = %d',
(int)$this->allowConduit);
}
if (strlen($this->nameContains)) {
$where[] = qsprintf(
$conn_r,
'name LIKE %~',
$this->nameContains);
$conn,
'LOWER(name) LIKE %~',
phutil_utf8_strtolower($this->nameContains));
}
return $this->formatWhereClause($where);
return $where;
}
public function getQueryApplicationClass() {

View file

@ -11,58 +11,39 @@ final class PassphraseCredentialSearchEngine
return 'PhabricatorPassphraseApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'isDestroyed',
$this->readBoolFromRequest($request, 'isDestroyed'));
$saved->setParameter('name', $request->getStr('name'));
return $saved;
public function newQuery() {
return new PassphraseCredentialQuery();
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PassphraseCredentialQuery());
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Status'))
->setKey('isDestroyed')
->setOptions(
pht('Show All'),
pht('Show Only Destroyed Credentials'),
pht('Show Only Active Credentials')),
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name'),
);
}
$destroyed = $saved->getParameter('isDestroyed');
if ($destroyed !== null) {
$query->withIsDestroyed($destroyed);
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['isDestroyed'] !== null) {
$query->withIsDestroyed($map['isDestroyed']);
}
$name = $saved->getParameter('name');
if (strlen($name)) {
$query->withNameContains($name);
if (strlen($map['name'])) {
$query->withNameContains($map['name']);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$name = $saved_query->getParameter('name');
$form
->appendChild(
id(new AphrontFormSelectControl())
->setName('isDestroyed')
->setLabel(pht('Status'))
->setValue($this->getBoolFromQuery($saved_query, 'isDestroyed'))
->setOptions(
array(
'' => pht('Show All Credentials'),
'false' => pht('Show Only Active Credentials'),
'true' => pht('Show Only Destroyed Credentials'),
)))
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Name Contains'))
->setValue($name));
}
protected function getURI($path) {
return '/passphrase/'.$path;
}