1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01: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; return $this;
} }
public function newResultObject() {
return new PassphraseCredential();
}
protected function loadPage() { protected function loadPage() {
$table = new PassphraseCredential(); return $this->loadStandardPage($this->newResultObject());
$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);
} }
protected function willFilterPage(array $page) { protected function willFilterPage(array $page) {
@ -99,61 +92,59 @@ final class PassphraseCredentialQuery
return $page; return $page;
} }
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);
} }
if ($this->credentialTypes) { if ($this->credentialTypes !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'credentialType in (%Ls)', 'credentialType in (%Ls)',
$this->credentialTypes); $this->credentialTypes);
} }
if ($this->providesTypes) { if ($this->providesTypes !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'providesType IN (%Ls)', 'providesType IN (%Ls)',
$this->providesTypes); $this->providesTypes);
} }
if ($this->isDestroyed !== null) { if ($this->isDestroyed !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'isDestroyed = %d', 'isDestroyed = %d',
(int)$this->isDestroyed); (int)$this->isDestroyed);
} }
if ($this->allowConduit !== null) { if ($this->allowConduit !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'allowConduit = %d', 'allowConduit = %d',
(int)$this->allowConduit); (int)$this->allowConduit);
} }
if (strlen($this->nameContains)) { if (strlen($this->nameContains)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'name LIKE %~', 'LOWER(name) LIKE %~',
$this->nameContains); phutil_utf8_strtolower($this->nameContains));
} }
return $this->formatWhereClause($where); return $where;
} }
public function getQueryApplicationClass() { public function getQueryApplicationClass() {

View file

@ -11,58 +11,39 @@ final class PassphraseCredentialSearchEngine
return 'PhabricatorPassphraseApplication'; return 'PhabricatorPassphraseApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new PassphraseCredentialQuery();
$saved->setParameter(
'isDestroyed',
$this->readBoolFromRequest($request, 'isDestroyed'));
$saved->setParameter('name', $request->getStr('name'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildCustomSearchFields() {
$query = id(new PassphraseCredentialQuery()); 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'); protected function buildQueryFromParameters(array $map) {
if ($destroyed !== null) { $query = $this->newQuery();
$query->withIsDestroyed($destroyed);
if ($map['isDestroyed'] !== null) {
$query->withIsDestroyed($map['isDestroyed']);
} }
$name = $saved->getParameter('name'); if (strlen($map['name'])) {
if (strlen($name)) { $query->withNameContains($map['name']);
$query->withNameContains($name);
} }
return $query; 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) { protected function getURI($path) {
return '/passphrase/'.$path; return '/passphrase/'.$path;
} }