@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HeraldWebhookSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('Webhooks');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorHeraldApplication::class;
12 }
13
14 public function newQuery() {
15 return new HeraldWebhookQuery();
16 }
17
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
20
21 if ($map['statuses']) {
22 $query->withStatuses($map['statuses']);
23 }
24
25 return $query;
26 }
27
28 protected function buildCustomSearchFields() {
29 return array(
30 id(new PhabricatorSearchCheckboxesField())
31 ->setKey('statuses')
32 ->setLabel(pht('Status'))
33 ->setDescription(
34 pht('Search for archived or active pastes.'))
35 ->setOptions(HeraldWebhook::getStatusDisplayNameMap()),
36 );
37 }
38
39 protected function getURI($path) {
40 return '/herald/webhook/'.$path;
41 }
42
43 protected function getBuiltinQueryNames() {
44 $names = array();
45
46 $names['active'] = pht('Active');
47 $names['all'] = pht('All');
48
49 return $names;
50 }
51
52 public function buildSavedQueryFromBuiltin($query_key) {
53 $query = $this->newSavedQuery();
54 $query->setQueryKey($query_key);
55
56 switch ($query_key) {
57 case 'all':
58 return $query;
59 case 'active':
60 return $query->setParameter(
61 'statuses',
62 array(
63 HeraldWebhook::HOOKSTATUS_FIREHOSE,
64 HeraldWebhook::HOOKSTATUS_ENABLED,
65 ));
66 }
67
68 return parent::buildSavedQueryFromBuiltin($query_key);
69 }
70
71 /**
72 * @param array<HeraldWebhook> $hooks
73 * @param PhabricatorSavedQuery $query
74 * @param array<PhabricatorObjectHandle> $handles
75 */
76 protected function renderResultList(
77 array $hooks,
78 PhabricatorSavedQuery $query,
79 array $handles) {
80 assert_instances_of($hooks, HeraldWebhook::class);
81
82 $viewer = $this->requireViewer();
83
84 $list = id(new PHUIObjectItemListView())
85 ->setViewer($viewer);
86 foreach ($hooks as $hook) {
87 $item = id(new PHUIObjectItemView())
88 ->setObjectName(pht('Webhook %d', $hook->getID()))
89 ->setHeader($hook->getName())
90 ->setHref($hook->getURI())
91 ->addAttribute($hook->getWebhookURI());
92
93 $item->addIcon($hook->getStatusIcon(), $hook->getStatusDisplayName());
94
95 if ($hook->isDisabled()) {
96 $item->setDisabled(true);
97 }
98
99 $list->addItem($item);
100 }
101
102 return id(new PhabricatorApplicationSearchResultView())
103 ->setObjectList($list)
104 ->setNoDataString(pht('No webhooks found.'));
105 }
106
107}