1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 16:00:59 +01:00

Add a global setting for controlling the default main menu search scope

Summary: Fixes T13405. The default behavior of the global search bar isn't currently configurable, but can be made configurable fairly easily.

Test Plan: Changed setting as an administrator, saw setting reflected as a user with no previous preference. As a user with an existing preference, saw preference retained.

Maniphest Tasks: T13405

Differential Revision: https://secure.phabricator.com/D20787
This commit is contained in:
epriestley 2019-09-06 08:18:28 -07:00
parent adc2002d28
commit 7e2bec9280
4 changed files with 75 additions and 5 deletions

View file

@ -4655,6 +4655,7 @@ phutil_register_library_map(array(
'PhabricatorSearchScopeSetting' => 'applications/settings/setting/PhabricatorSearchScopeSetting.php',
'PhabricatorSearchSelectField' => 'applications/search/field/PhabricatorSearchSelectField.php',
'PhabricatorSearchService' => 'infrastructure/cluster/search/PhabricatorSearchService.php',
'PhabricatorSearchSettingsPanel' => 'applications/settings/panel/PhabricatorSearchSettingsPanel.php',
'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php',
'PhabricatorSearchSubscribersField' => 'applications/search/field/PhabricatorSearchSubscribersField.php',
'PhabricatorSearchTextField' => 'applications/search/field/PhabricatorSearchTextField.php',
@ -11248,9 +11249,10 @@ phutil_register_library_map(array(
'PhabricatorSearchResultBucketGroup' => 'Phobject',
'PhabricatorSearchResultView' => 'AphrontView',
'PhabricatorSearchSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorSearchScopeSetting' => 'PhabricatorInternalSetting',
'PhabricatorSearchScopeSetting' => 'PhabricatorSelectSetting',
'PhabricatorSearchSelectField' => 'PhabricatorSearchField',
'PhabricatorSearchService' => 'Phobject',
'PhabricatorSearchSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
'PhabricatorSearchStringListField' => 'PhabricatorSearchField',
'PhabricatorSearchSubscribersField' => 'PhabricatorSearchTokenizerField',
'PhabricatorSearchTextField' => 'PhabricatorSearchField',

View file

@ -0,0 +1,28 @@
<?php
final class PhabricatorSearchSettingsPanel
extends PhabricatorEditEngineSettingsPanel {
const PANELKEY = 'search';
public function getPanelName() {
return pht('Search');
}
public function getPanelMenuIcon() {
return 'fa-search';
}
public function getPanelGroupKey() {
return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY;
}
public function isTemplatePanel() {
return true;
}
public function isUserPanel() {
return false;
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorSearchScopeSetting
extends PhabricatorInternalSetting {
extends PhabricatorSelectSetting {
const SETTINGKEY = 'search-scope';
@ -9,8 +9,33 @@ final class PhabricatorSearchScopeSetting
return pht('Search Scope');
}
public function getSettingPanelKey() {
return PhabricatorSearchSettingsPanel::PANELKEY;
}
public function getSettingDefaultValue() {
return 'all';
}
protected function getControlInstructions() {
return pht(
'Choose the default behavior of the global search in the main menu.');
}
protected function getSelectOptions() {
$scopes = PhabricatorMainMenuSearchView::getGlobalSearchScopeItems(
$this->getViewer(),
new PhabricatorSettingsApplication());
$scope_map = array();
foreach ($scopes as $scope) {
if (!isset($scope['value'])) {
continue;
}
$scope_map[$scope['value']] = $scope['name'];
}
return $scope_map;
}
}

View file

@ -116,8 +116,9 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
return $form;
}
private function buildModeSelector($selector_id, $application_id) {
$viewer = $this->getViewer();
public static function getGlobalSearchScopeItems(
PhabricatorUser $viewer,
PhabricatorApplication $application) {
$items = array();
$items[] = array(
@ -132,7 +133,6 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
$application_value = null;
$application_icon = self::DEFAULT_APPLICATION_ICON;
$application = $this->getApplication();
if ($application) {
$application_value = get_class($application);
if ($application->getApplicationSearchDocumentTypes()) {
@ -185,6 +185,14 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
'href' => PhabricatorEnv::getDoclink('Search User Guide'),
);
return $items;
}
private function buildModeSelector($selector_id, $application_id) {
$viewer = $this->getViewer();
$items = self::getGlobalSearchScopeItems($viewer, $this->getApplication());
$scope_key = PhabricatorSearchScopeSetting::SETTINGKEY;
$current_value = $viewer->getUserSetting($scope_key);
@ -196,6 +204,13 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
}
}
$application = $this->getApplication();
$application_value = null;
if ($application) {
$application_value = get_class($application);
}
$selector = id(new PHUIButtonView())
->setID($selector_id)
->addClass('phabricator-main-menu-search-dropdown')