3 final class HeraldRuleSearchEngine
extends PhabricatorApplicationSearchEngine
{
5 public function getResultTypeDescription() {
6 return pht('Herald Rules');
9 public function getApplicationClassName() {
10 return 'PhabricatorHeraldApplication';
13 public function newQuery() {
14 return id(new HeraldRuleQuery())
15 ->needValidateAuthors(true);
18 protected function buildCustomSearchFields() {
19 $viewer = $this->requireViewer();
21 $rule_types = HeraldRuleTypeConfig
::getRuleTypeMap();
22 $content_types = HeraldAdapter
::getEnabledAdapterMap($viewer);
25 id(new PhabricatorUsersSearchField())
26 ->setLabel(pht('Authors'))
27 ->setKey('authorPHIDs')
28 ->setAliases(array('author', 'authors', 'authorPHID'))
30 pht('Search for rules with given authors.')),
31 id(new PhabricatorSearchCheckboxesField())
33 ->setAliases(array('ruleType'))
34 ->setLabel(pht('Rule Type'))
36 pht('Search for rules of given types.'))
37 ->setOptions($rule_types),
38 id(new PhabricatorSearchCheckboxesField())
39 ->setKey('contentTypes')
40 ->setLabel(pht('Content Type'))
42 pht('Search for rules affecting given types of content.'))
43 ->setOptions($content_types),
44 id(new PhabricatorSearchThreeStateField())
45 ->setLabel(pht('Active Rules'))
49 pht('Show Only Active Rules'),
50 pht('Show Only Inactive Rules')),
51 id(new PhabricatorSearchThreeStateField())
52 ->setLabel(pht('Disabled Rules'))
56 pht('Show Only Disabled Rules'),
57 pht('Show Only Enabled Rules')),
58 id(new PhabricatorPHIDsSearchField())
59 ->setLabel(pht('Affected Objects'))
60 ->setKey('affectedPHIDs')
61 ->setAliases(array('affectedPHID')),
65 protected function buildQueryFromParameters(array $map) {
66 $query = $this->newQuery();
68 if ($map['authorPHIDs']) {
69 $query->withAuthorPHIDs($map['authorPHIDs']);
72 if ($map['contentTypes']) {
73 $query->withContentTypes($map['contentTypes']);
76 if ($map['ruleTypes']) {
77 $query->withRuleTypes($map['ruleTypes']);
80 if ($map['disabled'] !== null) {
81 $query->withDisabled($map['disabled']);
84 if ($map['active'] !== null) {
85 $query->withActive($map['active']);
88 if ($map['affectedPHIDs']) {
89 $query->withAffectedObjectPHIDs($map['affectedPHIDs']);
95 protected function getURI($path) {
96 return '/herald/'.$path;
99 protected function getBuiltinQueryNames() {
102 if ($this->requireViewer()->isLoggedIn()) {
103 $names['authored'] = pht('Authored');
106 $names['active'] = pht('Active');
107 $names['all'] = pht('All');
112 public function buildSavedQueryFromBuiltin($query_key) {
113 $query = $this->newSavedQuery();
114 $query->setQueryKey($query_key);
116 $viewer_phid = $this->requireViewer()->getPHID();
118 switch ($query_key) {
123 ->setParameter('active', true);
126 ->setParameter('authorPHIDs', array($viewer_phid))
127 ->setParameter('disabled', false);
130 return parent
::buildSavedQueryFromBuiltin($query_key);
133 protected function renderResultList(
135 PhabricatorSavedQuery
$query,
137 assert_instances_of($rules, 'HeraldRule');
138 $viewer = $this->requireViewer();
140 $list = id(new HeraldRuleListView())
145 $result = new PhabricatorApplicationSearchResultView();
146 $result->setObjectList($list);
147 $result->setNoDataString(pht('No rules found.'));
152 protected function getNewUserBody() {
153 $create_button = id(new PHUIButtonView())
155 ->setText(pht('Create Herald Rule'))
156 ->setHref('/herald/create/')
157 ->setColor(PHUIButtonView
::GREEN
);
159 $icon = $this->getApplication()->getIcon();
160 $app_name = $this->getApplication()->getName();
161 $view = id(new PHUIBigInfoView())
163 ->setTitle(pht('Welcome to %s', $app_name))
165 pht('A flexible rules engine that can notify and act on '.
166 'other actions such as tasks, diffs, and commits.'))
167 ->addAction($create_button);