Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
12242 views
1
<?php
2
3
final class PhabricatorDashboardSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Dashboards');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorDashboardApplication';
12
}
13
14
public function newQuery() {
15
return id(new PhabricatorDashboardQuery());
16
}
17
18
public function canUseInPanelContext() {
19
return false;
20
}
21
22
protected function buildCustomSearchFields() {
23
return array(
24
id(new PhabricatorSearchDatasourceField())
25
->setLabel(pht('Authored By'))
26
->setKey('authorPHIDs')
27
->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
28
id(new PhabricatorSearchCheckboxesField())
29
->setKey('statuses')
30
->setLabel(pht('Status'))
31
->setOptions(PhabricatorDashboard::getStatusNameMap()),
32
id(new PhabricatorSearchCheckboxesField())
33
->setKey('editable')
34
->setLabel(pht('Editable'))
35
->setOptions(array('editable' => null)),
36
);
37
}
38
39
protected function getURI($path) {
40
return '/dashboard/'.$path;
41
}
42
43
protected function getBuiltinQueryNames() {
44
$names = array();
45
46
if ($this->requireViewer()->isLoggedIn()) {
47
$names['authored'] = pht('Authored');
48
}
49
50
$names['open'] = pht('Active Dashboards');
51
$names['all'] = pht('All Dashboards');
52
53
return $names;
54
}
55
56
public function buildSavedQueryFromBuiltin($query_key) {
57
$query = $this->newSavedQuery();
58
$query->setQueryKey($query_key);
59
$viewer = $this->requireViewer();
60
61
switch ($query_key) {
62
case 'all':
63
return $query;
64
case 'authored':
65
return $query->setParameter(
66
'authorPHIDs',
67
array(
68
$viewer->getPHID(),
69
));
70
case 'open':
71
return $query->setParameter(
72
'statuses',
73
array(
74
PhabricatorDashboard::STATUS_ACTIVE,
75
));
76
}
77
78
return parent::buildSavedQueryFromBuiltin($query_key);
79
}
80
81
protected function buildQueryFromParameters(array $map) {
82
$query = $this->newQuery();
83
84
if ($map['statuses']) {
85
$query->withStatuses($map['statuses']);
86
}
87
88
if ($map['authorPHIDs']) {
89
$query->withAuthorPHIDs($map['authorPHIDs']);
90
}
91
92
if ($map['editable'] !== null) {
93
$query->withCanEdit($map['editable']);
94
}
95
96
return $query;
97
}
98
99
protected function renderResultList(
100
array $dashboards,
101
PhabricatorSavedQuery $query,
102
array $handles) {
103
104
$viewer = $this->requireViewer();
105
106
$phids = array();
107
foreach ($dashboards as $dashboard) {
108
$author_phid = $dashboard->getAuthorPHID();
109
if ($author_phid) {
110
$phids[] = $author_phid;
111
}
112
}
113
114
$handles = $viewer->loadHandles($phids);
115
116
if ($dashboards) {
117
$edge_query = id(new PhabricatorEdgeQuery())
118
->withSourcePHIDs(mpull($dashboards, 'getPHID'))
119
->withEdgeTypes(
120
array(
121
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
122
));
123
124
$edge_query->execute();
125
}
126
127
$list = id(new PHUIObjectItemListView())
128
->setViewer($viewer);
129
130
foreach ($dashboards as $dashboard) {
131
$item = id(new PHUIObjectItemView())
132
->setViewer($viewer)
133
->setObjectName($dashboard->getObjectName())
134
->setHeader($dashboard->getName())
135
->setHref($dashboard->getURI())
136
->setObject($dashboard);
137
138
if ($dashboard->isArchived()) {
139
$item->setDisabled(true);
140
$bg_color = 'bg-grey';
141
} else {
142
$bg_color = 'bg-dark';
143
}
144
145
$icon = id(new PHUIIconView())
146
->setIcon($dashboard->getIcon())
147
->setBackground($bg_color);
148
$item->setImageIcon($icon);
149
$item->setEpoch($dashboard->getDateModified());
150
151
$author_phid = $dashboard->getAuthorPHID();
152
$author_name = $handles[$author_phid]->renderLink();
153
$item->addByline(pht('Author: %s', $author_name));
154
155
$phid = $dashboard->getPHID();
156
$project_phids = $edge_query->getDestinationPHIDs(array($phid));
157
$project_handles = $viewer->loadHandles($project_phids);
158
159
$item->addAttribute(
160
id(new PHUIHandleTagListView())
161
->setLimit(4)
162
->setNoDataString(pht('No Tags'))
163
->setSlim(true)
164
->setHandles($project_handles));
165
166
$list->addItem($item);
167
}
168
169
$result = new PhabricatorApplicationSearchResultView();
170
$result->setObjectList($list);
171
$result->setNoDataString(pht('No dashboards found.'));
172
173
return $result;
174
}
175
176
}
177
178