Page MenuHomePhabricator

D11016.diff
No OneTemporary

D11016.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -78,6 +78,7 @@
'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 @@
'AlmanacPropertyInterface',
),
'AlmanacServiceController' => 'AlmanacController',
+ 'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
'AlmanacServiceEditController' => 'AlmanacServiceController',
'AlmanacServiceEditor' => 'PhabricatorApplicationTransactionEditor',
'AlmanacServiceListController' => 'AlmanacServiceController',
diff --git a/src/applications/almanac/query/AlmanacServiceQuery.php b/src/applications/almanac/query/AlmanacServiceQuery.php
--- a/src/applications/almanac/query/AlmanacServiceQuery.php
+++ b/src/applications/almanac/query/AlmanacServiceQuery.php
@@ -9,6 +9,8 @@
private $serviceClasses;
private $devicePHIDs;
private $locked;
+ private $namePrefix;
+ private $nameSuffix;
private $needBindings;
@@ -42,6 +44,16 @@
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 @@
(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);
diff --git a/src/applications/almanac/typeahead/AlmanacServiceDatasource.php b/src/applications/almanac/typeahead/AlmanacServiceDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/typeahead/AlmanacServiceDatasource.php
@@ -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;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 8, 9:45 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7607595
Default Alt Text
D11016.diff (3 KB)

Event Timeline