mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
Add a contextual "scope" dropdown for searches
Summary: Add a "Search for ... in (document group)" thing that picks the current scope based on the current application. Test Plan: Conducted searches in several browsers. Reviewers: btrahan, skrul Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T858 Differential Revision: https://secure.phabricator.com/D1610
This commit is contained in:
parent
6e48bfcb0a
commit
cd651001b6
16 changed files with 149 additions and 29 deletions
|
@ -723,6 +723,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSearchQuery' => 'applications/search/storage/query',
|
||||
'PhabricatorSearchRelationship' => 'applications/search/constants/relationship',
|
||||
'PhabricatorSearchResultView' => 'applications/search/view/searchresult',
|
||||
'PhabricatorSearchScope' => 'applications/search/constants/scope',
|
||||
'PhabricatorSearchSelectController' => 'applications/search/controller/select',
|
||||
'PhabricatorSearchUserIndexer' => 'applications/search/index/indexer/user',
|
||||
'PhabricatorSetup' => 'infrastructure/setup',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,6 +35,7 @@ abstract class DifferentialController extends PhabricatorController {
|
|||
$page->setGlyph("\xE2\x9A\x99");
|
||||
$page->appendChild($view);
|
||||
$page->setIsLoggedOut($viewer_is_anonymous);
|
||||
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_OPEN_REVISIONS);
|
||||
|
||||
$response = new AphrontWebpageResponse();
|
||||
return $response->setContent($page->render());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
),
|
||||
),
|
||||
null);
|
||||
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_COMMITS);
|
||||
|
||||
$page->appendChild($view);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/diffusion/query/pathid/base')
|
|||
phutil_require_module('phabricator', 'applications/diffusion/request/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/base');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
phutil_require_module('phabricator', 'view/layout/crumbs');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -29,6 +29,7 @@ abstract class ManiphestController extends PhabricatorController {
|
|||
$page->setTitle(idx($data, 'title'));
|
||||
$page->setGlyph("\xE2\x9A\x93");
|
||||
$page->appendChild($view);
|
||||
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_OPEN_TASKS);
|
||||
|
||||
$response = new AphrontWebpageResponse();
|
||||
return $response->setContent($page->render());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -39,6 +39,7 @@ abstract class PhrictionController extends PhabricatorController {
|
|||
);
|
||||
$page->setTabs($tabs, idx($data, 'tab'));
|
||||
$page->appendChild($view);
|
||||
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_WIKI);
|
||||
|
||||
$response = new AphrontWebpageResponse();
|
||||
return $response->setContent($page->render());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group search
|
||||
*/
|
||||
final class PhabricatorSearchScope {
|
||||
|
||||
const SCOPE_ALL = 'all';
|
||||
const SCOPE_OPEN_REVISIONS = 'open-revisions';
|
||||
const SCOPE_OPEN_TASKS = 'open-tasks';
|
||||
const SCOPE_COMMITS = 'commits';
|
||||
const SCOPE_WIKI = 'wiki';
|
||||
|
||||
public static function getScopeOptions() {
|
||||
return array(
|
||||
self::SCOPE_ALL => 'All Documents',
|
||||
self::SCOPE_OPEN_TASKS => 'Open Tasks',
|
||||
self::SCOPE_WIKI => 'Wiki Documents',
|
||||
self::SCOPE_OPEN_REVISIONS => 'Open Revisions',
|
||||
self::SCOPE_COMMITS => 'Commits',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
10
src/applications/search/constants/scope/__init__.php
Normal file
10
src/applications/search/constants/scope/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorSearchScope.php');
|
|
@ -44,24 +44,53 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController {
|
|||
if ($request->isFormPost()) {
|
||||
$query->setQuery($request->getStr('query'));
|
||||
|
||||
if (strlen($request->getStr('type'))) {
|
||||
$query->setParameter('type', $request->getStr('type'));
|
||||
}
|
||||
if ($request->getStr('scope')) {
|
||||
switch ($request->getStr('scope')) {
|
||||
case PhabricatorSearchScope::SCOPE_OPEN_REVISIONS:
|
||||
$query->setParameter('open', 1);
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_DREV);
|
||||
break;
|
||||
case PhabricatorSearchScope::SCOPE_OPEN_TASKS:
|
||||
$query->setParameter('open', 1);
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_TASK);
|
||||
break;
|
||||
case PhabricatorSearchScope::SCOPE_WIKI:
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
||||
break;
|
||||
case PhabricatorSearchScope::SCOPE_COMMITS:
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CMIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (strlen($request->getStr('type'))) {
|
||||
$query->setParameter('type', $request->getStr('type'));
|
||||
}
|
||||
|
||||
if ($request->getArr('author')) {
|
||||
$query->setParameter('author', $request->getArr('author'));
|
||||
}
|
||||
if ($request->getArr('author')) {
|
||||
$query->setParameter('author', $request->getArr('author'));
|
||||
}
|
||||
|
||||
if ($request->getArr('owner')) {
|
||||
$query->setParameter('owner', $request->getArr('owner'));
|
||||
}
|
||||
if ($request->getArr('owner')) {
|
||||
$query->setParameter('owner', $request->getArr('owner'));
|
||||
}
|
||||
|
||||
if ($request->getInt('open')) {
|
||||
$query->setParameter('open', $request->getInt('open'));
|
||||
}
|
||||
if ($request->getInt('open')) {
|
||||
$query->setParameter('open', $request->getInt('open'));
|
||||
}
|
||||
|
||||
if ($request->getArr('project')) {
|
||||
$query->setParameter('project', $request->getArr('project'));
|
||||
if ($request->getArr('project')) {
|
||||
$query->setParameter('project', $request->getArr('project'));
|
||||
}
|
||||
}
|
||||
|
||||
$query->save();
|
||||
|
@ -215,7 +244,7 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController {
|
|||
$results,
|
||||
),
|
||||
array(
|
||||
'title' => 'Results: what',
|
||||
'title' => 'Search Results',
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'aphront/response/404');
|
|||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/phid/constants');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
phutil_require_module('phabricator', 'applications/search/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/search/selector/base');
|
||||
phutil_require_module('phabricator', 'applications/search/storage/query');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -34,12 +34,27 @@ class AphrontFormSelectControl extends AphrontFormControl {
|
|||
}
|
||||
|
||||
protected function renderInput() {
|
||||
$options = array();
|
||||
foreach ($this->getOptions() as $value => $label) {
|
||||
$options[] = phutil_render_tag(
|
||||
return self::renderSelectTag(
|
||||
$this->getValue(),
|
||||
$this->getOptions(),
|
||||
array(
|
||||
'name' => $this->getName(),
|
||||
'disabled' => $this->getDisabled() ? 'disabled' : null,
|
||||
'id' => $this->getID(),
|
||||
));
|
||||
}
|
||||
|
||||
public static function renderSelectTag(
|
||||
$selected,
|
||||
array $options,
|
||||
array $attrs = array()) {
|
||||
|
||||
$option_tags = array();
|
||||
foreach ($options as $value => $label) {
|
||||
$option_tags[] = phutil_render_tag(
|
||||
'option',
|
||||
array(
|
||||
'selected' => ($value == $this->getValue()) ? 'selected' : null,
|
||||
'selected' => ($value == $selected) ? 'selected' : null,
|
||||
'value' => $value,
|
||||
),
|
||||
phutil_escape_html($label));
|
||||
|
@ -47,12 +62,8 @@ class AphrontFormSelectControl extends AphrontFormControl {
|
|||
|
||||
return phutil_render_tag(
|
||||
'select',
|
||||
array(
|
||||
'name' => $this->getName(),
|
||||
'disabled' => $this->getDisabled() ? 'disabled' : null,
|
||||
'id' => $this->getID(),
|
||||
),
|
||||
implode("\n", $options));
|
||||
$attrs,
|
||||
implode("\n", $option_tags));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class PhabricatorStandardPageView extends AphrontPageView {
|
|||
private $showChrome = true;
|
||||
private $isFrameable = false;
|
||||
private $disableConsole;
|
||||
private $searchDefaultScope;
|
||||
|
||||
public function setIsAdminInterface($is_admin_interface) {
|
||||
$this->isAdminInterface = $is_admin_interface;
|
||||
|
@ -103,6 +104,15 @@ class PhabricatorStandardPageView extends AphrontPageView {
|
|||
return $this->showChrome;
|
||||
}
|
||||
|
||||
public function setSearchDefaultScope($search_default_scope) {
|
||||
$this->searchDefaultScope = $search_default_scope;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSearchDefaultScope() {
|
||||
return $this->searchDefaultScope;
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$use_glyph = true;
|
||||
$request = $this->getRequest();
|
||||
|
@ -279,6 +289,14 @@ class PhabricatorStandardPageView extends AphrontPageView {
|
|||
'style' => 'display: inline',
|
||||
),
|
||||
'<input type="text" name="query" />'.
|
||||
' in '.
|
||||
AphrontFormSelectControl::renderSelectTag(
|
||||
$this->getSearchDefaultScope(),
|
||||
PhabricatorSearchScope::getScopeOptions(),
|
||||
array(
|
||||
'name' => 'scope',
|
||||
)).
|
||||
' '.
|
||||
'<button>Search</button>');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
phutil_require_module('phabricator', 'aphront/console/plugin/errorlog/api');
|
||||
phutil_require_module('phabricator', 'aphront/request');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/preferences');
|
||||
phutil_require_module('phabricator', 'applications/search/constants/scope');
|
||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
phutil_require_module('phabricator', 'infrastructure/javelin/api');
|
||||
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
|
||||
phutil_require_module('phabricator', 'view/form/control/select');
|
||||
phutil_require_module('phabricator', 'view/page/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
|
|
Loading…
Reference in a new issue