Changeset View
Changeset View
Standalone View
Standalone View
src/view/page/menu/PhabricatorMainMenuSearchView.php
| <?php | <?php | ||||
| final class PhabricatorMainMenuSearchView extends AphrontView { | final class PhabricatorMainMenuSearchView extends AphrontView { | ||||
| private $id; | private $id; | ||||
| private $application; | |||||
| public function setApplication(PhabricatorApplication $application) { | |||||
| $this->application = $application; | |||||
| return $this; | |||||
| } | |||||
| public function getApplication() { | |||||
| return $this->application; | |||||
| } | |||||
| public function getID() { | public function getID() { | ||||
| if (!$this->id) { | if (!$this->id) { | ||||
| $this->id = celerity_generate_unique_node_id(); | $this->id = celerity_generate_unique_node_id(); | ||||
| } | } | ||||
| return $this->id; | return $this->id; | ||||
| } | } | ||||
| Show All 17 Lines | $target = javelin_tag( | ||||
| 'div', | 'div', | ||||
| array( | array( | ||||
| 'id' => $target_id, | 'id' => $target_id, | ||||
| 'class' => 'phabricator-main-menu-search-target', | 'class' => 'phabricator-main-menu-search-target', | ||||
| ), | ), | ||||
| ''); | ''); | ||||
| $search_datasource = new PhabricatorSearchDatasource(); | $search_datasource = new PhabricatorSearchDatasource(); | ||||
| $scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE; | |||||
| Javelin::initBehavior( | Javelin::initBehavior( | ||||
| 'phabricator-search-typeahead', | 'phabricator-search-typeahead', | ||||
| array( | array( | ||||
| 'id' => $target_id, | 'id' => $target_id, | ||||
| 'input' => $search_id, | 'input' => $search_id, | ||||
| 'button' => $button_id, | 'button' => $button_id, | ||||
| 'src' => $search_datasource->getDatasourceURI(), | 'src' => $search_datasource->getDatasourceURI(), | ||||
| 'limit' => 10, | 'limit' => 10, | ||||
| 'placeholder' => pht('Search'), | 'placeholder' => pht('Search'), | ||||
| 'scopeUpdateURI' => '/settings/adjust/?key='.$scope_key, | |||||
| )); | )); | ||||
| $primary_input = phutil_tag( | $primary_input = phutil_tag( | ||||
| 'input', | 'input', | ||||
| array( | array( | ||||
| 'type' => 'hidden', | 'type' => 'hidden', | ||||
| 'name' => 'search:primary', | 'name' => 'search:primary', | ||||
| 'value' => 'true', | 'value' => 'true', | ||||
| )); | )); | ||||
| $search_text = javelin_tag( | $search_text = javelin_tag( | ||||
| 'span', | 'span', | ||||
| array( | array( | ||||
| 'aural' => true, | 'aural' => true, | ||||
| ), | ), | ||||
| pht('Search')); | pht('Search')); | ||||
| $selector = $this->buildModeSelector(); | |||||
| $form = phabricator_form( | $form = phabricator_form( | ||||
| $user, | $user, | ||||
| array( | array( | ||||
| 'action' => '/search/', | 'action' => '/search/', | ||||
| 'method' => 'POST', | 'method' => 'POST', | ||||
| ), | ), | ||||
| phutil_tag_div('phabricator-main-menu-search-container', array( | phutil_tag_div('phabricator-main-menu-search-container', array( | ||||
| $input, | $input, | ||||
| phutil_tag( | phutil_tag( | ||||
| 'button', | 'button', | ||||
| array( | array( | ||||
| 'id' => $button_id, | 'id' => $button_id, | ||||
| 'class' => 'phui-icon-view phui-font-fa fa-search', | 'class' => 'phui-icon-view phui-font-fa fa-search', | ||||
| ), | ), | ||||
| $search_text), | $search_text), | ||||
| $selector, | |||||
| $primary_input, | $primary_input, | ||||
| $target, | $target, | ||||
| ))); | ))); | ||||
| return $form; | return $form; | ||||
| } | } | ||||
| private function buildModeSelector() { | |||||
| $viewer = $this->getUser(); | |||||
| $items = array(); | |||||
| $items[] = array( | |||||
| 'name' => pht('Search'), | |||||
| ); | |||||
| $items[] = array( | |||||
| 'icon' => 'fa-globe', | |||||
| 'name' => pht('Search All Documents'), | |||||
| 'value' => 'all', | |||||
| ); | |||||
| $application_value = null; | |||||
| $application_icon = 'fa-file-o'; | |||||
| $application = $this->getApplication(); | |||||
| if ($application) { | |||||
| $application_value = get_class($application); | |||||
| if ($application->getApplicationSearchDocumentTypes()) { | |||||
| $application_icon = $application->getFontIcon(); | |||||
| } | |||||
| } | |||||
| $items[] = array( | |||||
| 'icon' => $application_icon, | |||||
| 'name' => pht('Search Current Application'), | |||||
| 'value' => PhabricatorSearchController::SCOPE_CURRENT_APPLICATION, | |||||
| ); | |||||
| $items[] = array( | |||||
| 'name' => pht('Saved Queries'), | |||||
| ); | |||||
| $engine = id(new PhabricatorSearchApplicationSearchEngine()) | |||||
| ->setViewer($viewer); | |||||
| $engine_queries = $engine->loadEnabledNamedQueries(); | |||||
| $query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey'); | |||||
| foreach ($query_map as $query_key => $query_name) { | |||||
| if ($query_key == 'all') { | |||||
| // Skip the builtin "All" query since it's redundant with the default | |||||
| // setting. | |||||
| continue; | |||||
| } | |||||
| $items[] = array( | |||||
| 'icon' => 'fa-search', | |||||
| 'name' => $query_name, | |||||
| 'value' => $query_key, | |||||
| ); | |||||
| } | |||||
| $items[] = array( | |||||
| 'name' => pht('More Options'), | |||||
| ); | |||||
| $items[] = array( | |||||
| 'icon' => 'fa-search-plus', | |||||
| 'name' => pht('Advanced Search'), | |||||
| 'href' => '/search/query/advanced/', | |||||
| ); | |||||
| /* TODO: Write this. | |||||
| $items[] = array( | |||||
| 'icon' => 'fa-book', | |||||
| 'name' => pht('User Guide: Search'), | |||||
| 'href' => PhabricatorEnv::getDoclink('User Guide: Search'), | |||||
| ); | |||||
| */ | |||||
| $scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE; | |||||
| $current_value = $viewer->loadPreferences()->getPreference( | |||||
| $scope_key, | |||||
| 'all'); | |||||
| $current_icon = 'fa-globe'; | |||||
| foreach ($items as $item) { | |||||
| if (idx($item, 'value') == $current_value) { | |||||
| $current_icon = $item['icon']; | |||||
| break; | |||||
| } | |||||
| } | |||||
| $selector = id(new PHUIButtonView()) | |||||
| ->addClass('phabricator-main-menu-search-dropdown') | |||||
| ->addSigil('global-search-dropdown') | |||||
| ->setMetadata( | |||||
| array( | |||||
| 'items' => $items, | |||||
| 'icon' => $current_icon, | |||||
| 'value' => $current_value, | |||||
| )) | |||||
| ->setIcon( | |||||
| id(new PHUIIconView()) | |||||
| ->addSigil('global-search-dropdown-icon') | |||||
| ->setIconFont($current_icon)) | |||||
| ->setDropdown(true); | |||||
| $input = javelin_tag( | |||||
| 'input', | |||||
| array( | |||||
| 'type' => 'hidden', | |||||
| 'sigil' => 'global-search-dropdown-input', | |||||
| 'name' => 'search:scope', | |||||
| 'value' => $current_value, | |||||
| )); | |||||
| $application_input = javelin_tag( | |||||
| 'input', | |||||
| array( | |||||
| 'type' => 'hidden', | |||||
| 'sigil' => 'global-search-dropdown-app', | |||||
| 'name' => 'search:application', | |||||
| 'value' => $application_value, | |||||
| )); | |||||
| return array($selector, $input, $application_input); | |||||
| } | |||||
| } | } | ||||