From f54dfe7567697f6817d194296634a5dd953ab47e Mon Sep 17 00:00:00 2001 From: Chad Little Date: Fri, 3 Feb 2017 09:19:17 -0800 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../typeahead/PhabricatorIconDatasource.php | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/applications/files/typeahead/PhabricatorIconDatasource.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8743fc205b..033e7c15d2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/files/typeahead/PhabricatorIconDatasource.php b/src/applications/files/typeahead/PhabricatorIconDatasource.php new file mode 100644 index 0000000000..63b554a9b7 --- /dev/null +++ b/src/applications/files/typeahead/PhabricatorIconDatasource.php @@ -0,0 +1,46 @@ +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; + } + +}