1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

Add a basic icon typeahead

Summary: Fixes T11971, adds a basic typeahead for selecting an icon.

Test Plan:
http://local.phacility.com/typeahead/browse/PhabricatorIconDatasource/

{F2561013}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T11971

Differential Revision: https://secure.phabricator.com/D17301
This commit is contained in:
Chad Little 2017-02-03 09:19:17 -08:00
parent fd0591e168
commit f54dfe7567
2 changed files with 48 additions and 0 deletions

View file

@ -2848,6 +2848,7 @@ phutil_register_library_map(array(
'PhabricatorIDsSearchEngineExtension' => 'applications/search/engineextension/PhabricatorIDsSearchEngineExtension.php',
'PhabricatorIDsSearchField' => 'applications/search/field/PhabricatorIDsSearchField.php',
'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php',
'PhabricatorIconDatasource' => 'applications/files/typeahead/PhabricatorIconDatasource.php',
'PhabricatorIconRemarkupRule' => 'applications/macro/markup/PhabricatorIconRemarkupRule.php',
'PhabricatorIconSet' => 'applications/files/iconset/PhabricatorIconSet.php',
'PhabricatorIconSetEditField' => 'applications/transactions/editfield/PhabricatorIconSetEditField.php',
@ -7907,6 +7908,7 @@ phutil_register_library_map(array(
'PhabricatorIDsSearchEngineExtension' => 'PhabricatorSearchEngineExtension',
'PhabricatorIDsSearchField' => 'PhabricatorSearchField',
'PhabricatorIRCProtocolAdapter' => 'PhabricatorProtocolAdapter',
'PhabricatorIconDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorIconRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorIconSet' => 'Phobject',
'PhabricatorIconSetEditField' => 'PhabricatorEditField',

View file

@ -0,0 +1,46 @@
<?php
final class PhabricatorIconDatasource extends PhabricatorTypeaheadDatasource {
public function getPlaceholderText() {
return pht('Type an icon name...');
}
public function getBrowseTitle() {
return pht('Browse Icons');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorFilesApplication';
}
public function loadResults() {
$results = $this->buildResults();
return $this->filterResultsAgainstTokens($results);
}
protected function renderSpecialTokens(array $values) {
return $this->renderTokensFromResults($this->buildResults(), $values);
}
private function buildResults() {
$raw_query = $this->getRawQuery();
$icons = id(new PHUIIconView())->getIcons();
$results = array();
foreach ($icons as $icon) {
$display_name = str_replace('fa-', '', $icon);
$result = id(new PhabricatorTypeaheadResult())
->setPHID($icon)
->setName($icon)
->setIcon($icon)
->setDisplayname($display_name)
->addAttribute($icon);
$results[$icon] = $result;
}
return $results;
}
}