forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorProjectTriggerSearchEngine.php
155 lines (129 loc) · 4.12 KB
/
PhabricatorProjectTriggerSearchEngine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
final class PhabricatorProjectTriggerSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Triggers');
}
public function getApplicationClassName() {
return 'PhabricatorProjectApplication';
}
public function newQuery() {
return id(new PhabricatorProjectTriggerQuery())
->needUsage(true);
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Active'))
->setKey('isActive')
->setOptions(
pht('(Show All)'),
pht('Show Only Active Triggers'),
pht('Show Only Inactive Triggers')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['isActive'] !== null) {
if ($map['isActive']) {
$query->withActiveColumnCountBetween(1, null);
} else {
$query->withActiveColumnCountBetween(null, 0);
}
}
return $query;
}
protected function getURI($path) {
return '/project/trigger/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
$names['active'] = pht('Active Triggers');
$names['all'] = pht('All Triggers');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'active':
return $query->setParameter('isActive', true);
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $triggers,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($triggers, 'PhabricatorProjectTrigger');
$viewer = $this->requireViewer();
$example_phids = array();
foreach ($triggers as $trigger) {
$example_phid = $trigger->getUsage()->getExamplePHID();
if ($example_phid) {
$example_phids[] = $example_phid;
}
}
$handles = $viewer->loadHandles($example_phids);
$list = id(new PHUIObjectItemListView())
->setViewer($viewer);
foreach ($triggers as $trigger) {
$usage = $trigger->getUsage();
$column_handle = null;
$have_column = false;
$example_phid = $usage->getExamplePHID();
if ($example_phid) {
$column_handle = $handles[$example_phid];
if ($column_handle->isComplete()) {
if (!$column_handle->getPolicyFiltered()) {
$have_column = true;
}
}
}
$column_count = $usage->getColumnCount();
$active_count = $usage->getActiveColumnCount();
if ($have_column) {
if ($active_count > 1) {
$usage_description = pht(
'Used on %s and %s other active column(s).',
$column_handle->renderLink(),
new PhutilNumber($active_count - 1));
} else if ($column_count > 1) {
$usage_description = pht(
'Used on %s and %s other column(s).',
$column_handle->renderLink(),
new PhutilNumber($column_count - 1));
} else {
$usage_description = pht(
'Used on %s.',
$column_handle->renderLink());
}
} else {
if ($active_count) {
$usage_description = pht(
'Used on %s active column(s).',
new PhutilNumber($active_count));
} else if ($column_count) {
$usage_description = pht(
'Used on %s column(s).',
new PhutilNumber($column_count));
} else {
$usage_description = pht(
'Unused trigger.');
}
}
$item = id(new PHUIObjectItemView())
->setObjectName($trigger->getObjectName())
->setHeader($trigger->getDisplayName())
->setHref($trigger->getURI())
->addAttribute($usage_description)
->setDisabled(!$active_count);
$list->addItem($item);
}
return id(new PhabricatorApplicationSearchResultView())
->setObjectList($list)
->setNoDataString(pht('No triggers found.'));
}
}