Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/meta/query/PhabricatorAppSearchEngine.php
12256 views
1
<?php
2
3
final class PhabricatorAppSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Applications');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorApplicationsApplication';
12
}
13
14
public function getPageSize(PhabricatorSavedQuery $saved) {
15
return INF;
16
}
17
18
public function buildSavedQueryFromRequest(AphrontRequest $request) {
19
$saved = new PhabricatorSavedQuery();
20
21
$saved->setParameter('name', $request->getStr('name'));
22
23
$saved->setParameter(
24
'installed',
25
$this->readBoolFromRequest($request, 'installed'));
26
$saved->setParameter(
27
'prototypes',
28
$this->readBoolFromRequest($request, 'prototypes'));
29
$saved->setParameter(
30
'firstParty',
31
$this->readBoolFromRequest($request, 'firstParty'));
32
$saved->setParameter(
33
'launchable',
34
$this->readBoolFromRequest($request, 'launchable'));
35
$saved->setParameter(
36
'appemails',
37
$this->readBoolFromRequest($request, 'appemails'));
38
39
return $saved;
40
}
41
42
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
43
$query = id(new PhabricatorApplicationQuery())
44
->setOrder(PhabricatorApplicationQuery::ORDER_NAME)
45
->withUnlisted(false);
46
47
$name = $saved->getParameter('name');
48
if ($name !== null && strlen($name)) {
49
$query->withNameContains($name);
50
}
51
52
$installed = $saved->getParameter('installed');
53
if ($installed !== null) {
54
$query->withInstalled($installed);
55
}
56
57
$prototypes = $saved->getParameter('prototypes');
58
59
if ($prototypes === null) {
60
// NOTE: This is the old name of the 'prototypes' option, see T6084.
61
$prototypes = $saved->getParameter('beta');
62
$saved->setParameter('prototypes', $prototypes);
63
}
64
65
if ($prototypes !== null) {
66
$query->withPrototypes($prototypes);
67
}
68
69
$first_party = $saved->getParameter('firstParty');
70
if ($first_party !== null) {
71
$query->withFirstParty($first_party);
72
}
73
74
$launchable = $saved->getParameter('launchable');
75
if ($launchable !== null) {
76
$query->withLaunchable($launchable);
77
}
78
79
$appemails = $saved->getParameter('appemails');
80
if ($appemails !== null) {
81
$query->withApplicationEmailSupport($appemails);
82
}
83
84
return $query;
85
}
86
87
public function buildSearchForm(
88
AphrontFormView $form,
89
PhabricatorSavedQuery $saved) {
90
91
$form
92
->appendChild(
93
id(new AphrontFormTextControl())
94
->setLabel(pht('Name Contains'))
95
->setName('name')
96
->setValue($saved->getParameter('name')))
97
->appendChild(
98
id(new AphrontFormSelectControl())
99
->setLabel(pht('Installed'))
100
->setName('installed')
101
->setValue($this->getBoolFromQuery($saved, 'installed'))
102
->setOptions(
103
array(
104
'' => pht('Show All Applications'),
105
'true' => pht('Show Installed Applications'),
106
'false' => pht('Show Uninstalled Applications'),
107
)))
108
->appendChild(
109
id(new AphrontFormSelectControl())
110
->setLabel(pht('Prototypes'))
111
->setName('prototypes')
112
->setValue($this->getBoolFromQuery($saved, 'prototypes'))
113
->setOptions(
114
array(
115
'' => pht('Show All Applications'),
116
'true' => pht('Show Prototype Applications'),
117
'false' => pht('Show Released Applications'),
118
)))
119
->appendChild(
120
id(new AphrontFormSelectControl())
121
->setLabel(pht('Provenance'))
122
->setName('firstParty')
123
->setValue($this->getBoolFromQuery($saved, 'firstParty'))
124
->setOptions(
125
array(
126
'' => pht('Show All Applications'),
127
'true' => pht('Show First-Party Applications'),
128
'false' => pht('Show Third-Party Applications'),
129
)))
130
->appendChild(
131
id(new AphrontFormSelectControl())
132
->setLabel(pht('Launchable'))
133
->setName('launchable')
134
->setValue($this->getBoolFromQuery($saved, 'launchable'))
135
->setOptions(
136
array(
137
'' => pht('Show All Applications'),
138
'true' => pht('Show Launchable Applications'),
139
'false' => pht('Show Non-Launchable Applications'),
140
)))
141
->appendChild(
142
id(new AphrontFormSelectControl())
143
->setLabel(pht('Application Emails'))
144
->setName('appemails')
145
->setValue($this->getBoolFromQuery($saved, 'appemails'))
146
->setOptions(
147
array(
148
'' => pht('Show All Applications'),
149
'true' => pht('Show Applications w/ App Email Support'),
150
'false' => pht('Show Applications w/o App Email Support'),
151
)));
152
}
153
154
protected function getURI($path) {
155
return '/applications/'.$path;
156
}
157
158
protected function getBuiltinQueryNames() {
159
return array(
160
'launcher' => pht('Launcher'),
161
'all' => pht('All Applications'),
162
);
163
}
164
165
public function buildSavedQueryFromBuiltin($query_key) {
166
$query = $this->newSavedQuery();
167
$query->setQueryKey($query_key);
168
169
switch ($query_key) {
170
case 'launcher':
171
return $query
172
->setParameter('installed', true)
173
->setParameter('launchable', true);
174
case 'all':
175
return $query;
176
}
177
178
return parent::buildSavedQueryFromBuiltin($query_key);
179
}
180
181
protected function renderResultList(
182
array $all_applications,
183
PhabricatorSavedQuery $query,
184
array $handle) {
185
assert_instances_of($all_applications, 'PhabricatorApplication');
186
187
$all_applications = msort($all_applications, 'getName');
188
189
if ($query->getQueryKey() == 'launcher') {
190
$groups = mgroup($all_applications, 'getApplicationGroup');
191
} else {
192
$groups = array($all_applications);
193
}
194
195
$group_names = PhabricatorApplication::getApplicationGroups();
196
$groups = array_select_keys($groups, array_keys($group_names)) + $groups;
197
198
$results = array();
199
foreach ($groups as $group => $applications) {
200
if (count($groups) > 1) {
201
$results[] = phutil_tag(
202
'h1',
203
array(
204
'class' => 'phui-oi-list-header',
205
),
206
idx($group_names, $group, $group));
207
}
208
209
$list = new PHUIObjectItemListView();
210
211
foreach ($applications as $application) {
212
$icon = $application->getIcon();
213
if (!$icon) {
214
$icon = 'application';
215
}
216
217
$description = $application->getShortDescription();
218
219
$configure = id(new PHUIButtonView())
220
->setTag('a')
221
->setIcon('fa-gears')
222
->setHref('/applications/view/'.get_class($application).'/')
223
->setText(pht('Configure'))
224
->setColor(PHUIButtonView::GREY);
225
226
$name = $application->getName();
227
228
$item = id(new PHUIObjectItemView())
229
->setHeader($name)
230
->setImageIcon($icon)
231
->setSideColumn($configure);
232
233
if (!$application->isFirstParty()) {
234
$tag = id(new PHUITagView())
235
->setName(pht('Extension'))
236
->setIcon('fa-puzzle-piece')
237
->setColor(PHUITagView::COLOR_BLUE)
238
->setType(PHUITagView::TYPE_SHADE)
239
->setSlimShady(true);
240
$item->addAttribute($tag);
241
}
242
243
if ($application->isPrototype()) {
244
$prototype_tag = id(new PHUITagView())
245
->setName(pht('Prototype'))
246
->setIcon('fa-exclamation-circle')
247
->setColor(PHUITagView::COLOR_ORANGE)
248
->setType(PHUITagView::TYPE_SHADE)
249
->setSlimShady(true);
250
$item->addAttribute($prototype_tag);
251
}
252
253
$item->addAttribute($description);
254
255
if ($application->getBaseURI() && $application->isInstalled()) {
256
$item->setHref($application->getBaseURI());
257
}
258
259
if (!$application->isInstalled()) {
260
$item->addAttribute(pht('Uninstalled'));
261
$item->setDisabled(true);
262
}
263
264
$list->addItem($item);
265
}
266
267
$results[] = $list;
268
}
269
270
$result = new PhabricatorApplicationSearchResultView();
271
$result->setContent($results);
272
273
return $result;
274
}
275
276
}
277
278