mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add an Almanac service typeahead datasource
Summary: Ref T5833. Ref T6238. This will probably be useful somewhere in the upstream eventually, and is materially useful in the Instances application right now. Test Plan: tippy typey typey Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6238, T5833 Differential Revision: https://secure.phabricator.com/D11016
This commit is contained in:
parent
9c6467d867
commit
e0f4e19c3f
3 changed files with 71 additions and 0 deletions
|
@ -78,6 +78,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php',
|
||||
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
|
||||
'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php',
|
||||
'AlmanacServiceDatasource' => 'applications/almanac/typeahead/AlmanacServiceDatasource.php',
|
||||
'AlmanacServiceEditController' => 'applications/almanac/controller/AlmanacServiceEditController.php',
|
||||
'AlmanacServiceEditor' => 'applications/almanac/editor/AlmanacServiceEditor.php',
|
||||
'AlmanacServiceListController' => 'applications/almanac/controller/AlmanacServiceListController.php',
|
||||
|
@ -3112,6 +3113,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacPropertyInterface',
|
||||
),
|
||||
'AlmanacServiceController' => 'AlmanacController',
|
||||
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'AlmanacServiceEditController' => 'AlmanacServiceController',
|
||||
'AlmanacServiceEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'AlmanacServiceListController' => 'AlmanacServiceController',
|
||||
|
|
|
@ -9,6 +9,8 @@ final class AlmanacServiceQuery
|
|||
private $serviceClasses;
|
||||
private $devicePHIDs;
|
||||
private $locked;
|
||||
private $namePrefix;
|
||||
private $nameSuffix;
|
||||
|
||||
private $needBindings;
|
||||
|
||||
|
@ -42,6 +44,16 @@ final class AlmanacServiceQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withNamePrefix($prefix) {
|
||||
$this->namePrefix = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNameSuffix($suffix) {
|
||||
$this->nameSuffix = $suffix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needBindings($need_bindings) {
|
||||
$this->needBindings = $need_bindings;
|
||||
return $this;
|
||||
|
@ -126,6 +138,20 @@ final class AlmanacServiceQuery
|
|||
(int)$this->locked);
|
||||
}
|
||||
|
||||
if ($this->namePrefix !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'service.name LIKE %>',
|
||||
$this->namePrefix);
|
||||
}
|
||||
|
||||
if ($this->nameSuffix !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'service.name LIKE %<',
|
||||
$this->nameSuffix);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacServiceDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a service name...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorAlmanacApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$services = id(new AlmanacServiceQuery())
|
||||
->setViewer($viewer)
|
||||
->withNamePrefix($raw_query)
|
||||
->setLimit($this->getLimit())
|
||||
->execute();
|
||||
|
||||
if ($services) {
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(mpull($services, 'getPHID'))
|
||||
->execute();
|
||||
} else {
|
||||
$handles = array();
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($handles as $handle) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName($handle->getName())
|
||||
->setPHID($handle->getPHID());
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue