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

Improve PhamePost search options

Summary: Ref T9360. This adds ability to search posts by blog(s) and by type better.

Test Plan:
Create some posts, search for them.

{F1705961}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9360

Differential Revision: https://secure.phabricator.com/D16199
This commit is contained in:
Chad Little 2016-06-30 12:54:20 -07:00
parent 163f2c4262
commit 23ec515afc
4 changed files with 81 additions and 7 deletions

View file

@ -3794,6 +3794,7 @@ phutil_register_library_map(array(
'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php', 'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php',
'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php',
'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php',
'PhameBlogDatasource' => 'applications/phame/typeahead/PhameBlogDatasource.php',
'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php', 'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php',
'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php',
'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php', 'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php',
@ -8698,6 +8699,7 @@ phutil_register_library_map(array(
'PhameBlogArchiveController' => 'PhameBlogController', 'PhameBlogArchiveController' => 'PhameBlogController',
'PhameBlogController' => 'PhameController', 'PhameBlogController' => 'PhameController',
'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability',
'PhameBlogDatasource' => 'PhabricatorTypeaheadDatasource',
'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhameBlogEditController' => 'PhameBlogController', 'PhameBlogEditController' => 'PhameBlogController',
'PhameBlogEditEngine' => 'PhabricatorEditEngine', 'PhameBlogEditEngine' => 'PhabricatorEditEngine',

View file

@ -139,6 +139,14 @@ final class PhameBlogViewController extends PhameLiveController {
->setDisabled(!$can_edit) ->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)); ->setWorkflow(!$can_edit));
$actions->addAction(
id(new PhabricatorActionView())
->setUser($viewer)
->setIcon('fa-search')
->setHref(
$this->getApplicationURI('post/?blog='.$blog->getPHID()))
->setName(pht('Search Posts')));
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setUser($viewer) ->setUser($viewer)

View file

@ -18,25 +18,36 @@ final class PhamePostSearchEngine
protected function buildQueryFromParameters(array $map) { protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery(); $query = $this->newQuery();
if (strlen($map['visibility'])) { if ($map['visibility']) {
$query->withVisibility(array($map['visibility'])); $query->withVisibility($map['visibility']);
} }
if ($map['blogPHIDs']) {
$query->withBlogPHIDs($map['blogPHIDs']);
}
return $query; return $query;
} }
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
return array( return array(
id(new PhabricatorSearchSelectField()) id(new PhabricatorSearchCheckboxesField())
->setKey('visibility') ->setKey('visibility')
->setLabel(pht('Visibility')) ->setLabel(pht('Visibility'))
->setOptions( ->setOptions(
array( array(
'' => pht('All'),
PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
PhameConstants::VISIBILITY_DRAFT => pht('Draft'), PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'), PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'),
)), )),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Blogs'))
->setKey('blogPHIDs')
->setAliases(array('blog', 'blogs', 'blogPHIDs'))
->setDescription(
pht('Search for posts within certain blogs.'))
->setDatasource(new PhameBlogDatasource()),
); );
} }
@ -63,13 +74,13 @@ final class PhamePostSearchEngine
return $query; return $query;
case 'live': case 'live':
return $query->setParameter( return $query->setParameter(
'visibility', PhameConstants::VISIBILITY_PUBLISHED); 'visibility', array(PhameConstants::VISIBILITY_PUBLISHED));
case 'draft': case 'draft':
return $query->setParameter( return $query->setParameter(
'visibility', PhameConstants::VISIBILITY_DRAFT); 'visibility', array(PhameConstants::VISIBILITY_DRAFT));
case 'archived': case 'archived':
return $query->setParameter( return $query->setParameter(
'visibility', PhameConstants::VISIBILITY_ARCHIVED); 'visibility', array(PhameConstants::VISIBILITY_ARCHIVED));
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);

View file

@ -0,0 +1,53 @@
<?php
final class PhameBlogDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Blogs');
}
public function getPlaceholderText() {
return pht('Type a blog name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPhameApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$blogs = id(new PhameBlogQuery())
->setViewer($viewer)
->needProfileImage(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->execute();
$results = array();
foreach ($blogs as $blog) {
$closed = null;
$status = $blog->getStatus();
if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) {
$closed = pht('Archived');
}
$results[] = id(new PhabricatorTypeaheadResult())
->setName($blog->getName())
->setClosed($closed)
->addAttribute(pht('Phame Blog'))
->setImageURI($blog->getProfileImageURI())
->setPHID($blog->getPHID());
}
$results = $this->filterResultsAgainstTokens($results);
return $results;
}
}