Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/query/HeraldWebhookSearchEngine.php
12256 views
1
<?php
2
3
final class HeraldWebhookSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Webhooks');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorHeraldApplication';
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
protected function renderResultList(
72
array $hooks,
73
PhabricatorSavedQuery $query,
74
array $handles) {
75
assert_instances_of($hooks, 'HeraldWebhook');
76
77
$viewer = $this->requireViewer();
78
79
$list = id(new PHUIObjectItemListView())
80
->setViewer($viewer);
81
foreach ($hooks as $hook) {
82
$item = id(new PHUIObjectItemView())
83
->setObjectName(pht('Webhook %d', $hook->getID()))
84
->setHeader($hook->getName())
85
->setHref($hook->getURI())
86
->addAttribute($hook->getWebhookURI());
87
88
$item->addIcon($hook->getStatusIcon(), $hook->getStatusDisplayName());
89
90
if ($hook->isDisabled()) {
91
$item->setDisabled(true);
92
}
93
94
$list->addItem($item);
95
}
96
97
return id(new PhabricatorApplicationSearchResultView())
98
->setObjectList($list)
99
->setNoDataString(pht('No webhooks found.'));
100
}
101
102
}
103
104