Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / dashboard / query / PhabricatorDashboardSearchEngine.php
blobea3f69faab0b42605c05b2d65a66494687c2504b
1 <?php
3 final class PhabricatorDashboardSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Dashboards');
10 public function getApplicationClassName() {
11 return 'PhabricatorDashboardApplication';
14 public function newQuery() {
15 return id(new PhabricatorDashboardQuery());
18 public function canUseInPanelContext() {
19 return false;
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)),
39 protected function getURI($path) {
40 return '/dashboard/'.$path;
43 protected function getBuiltinQueryNames() {
44 $names = array();
46 if ($this->requireViewer()->isLoggedIn()) {
47 $names['authored'] = pht('Authored');
50 $names['open'] = pht('Active Dashboards');
51 $names['all'] = pht('All Dashboards');
53 return $names;
56 public function buildSavedQueryFromBuiltin($query_key) {
57 $query = $this->newSavedQuery();
58 $query->setQueryKey($query_key);
59 $viewer = $this->requireViewer();
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 ));
78 return parent::buildSavedQueryFromBuiltin($query_key);
81 protected function buildQueryFromParameters(array $map) {
82 $query = $this->newQuery();
84 if ($map['statuses']) {
85 $query->withStatuses($map['statuses']);
88 if ($map['authorPHIDs']) {
89 $query->withAuthorPHIDs($map['authorPHIDs']);
92 if ($map['editable'] !== null) {
93 $query->withCanEdit($map['editable']);
96 return $query;
99 protected function renderResultList(
100 array $dashboards,
101 PhabricatorSavedQuery $query,
102 array $handles) {
104 $viewer = $this->requireViewer();
106 $phids = array();
107 foreach ($dashboards as $dashboard) {
108 $author_phid = $dashboard->getAuthorPHID();
109 if ($author_phid) {
110 $phids[] = $author_phid;
114 $handles = $viewer->loadHandles($phids);
116 if ($dashboards) {
117 $edge_query = id(new PhabricatorEdgeQuery())
118 ->withSourcePHIDs(mpull($dashboards, 'getPHID'))
119 ->withEdgeTypes(
120 array(
121 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
124 $edge_query->execute();
127 $list = id(new PHUIObjectItemListView())
128 ->setViewer($viewer);
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);
138 if ($dashboard->isArchived()) {
139 $item->setDisabled(true);
140 $bg_color = 'bg-grey';
141 } else {
142 $bg_color = 'bg-dark';
145 $icon = id(new PHUIIconView())
146 ->setIcon($dashboard->getIcon())
147 ->setBackground($bg_color);
148 $item->setImageIcon($icon);
149 $item->setEpoch($dashboard->getDateModified());
151 $author_phid = $dashboard->getAuthorPHID();
152 $author_name = $handles[$author_phid]->renderLink();
153 $item->addByline(pht('Author: %s', $author_name));
155 $phid = $dashboard->getPHID();
156 $project_phids = $edge_query->getDestinationPHIDs(array($phid));
157 $project_handles = $viewer->loadHandles($project_phids);
159 $item->addAttribute(
160 id(new PHUIHandleTagListView())
161 ->setLimit(4)
162 ->setNoDataString(pht('No Tags'))
163 ->setSlim(true)
164 ->setHandles($project_handles));
166 $list->addItem($item);
169 $result = new PhabricatorApplicationSearchResultView();
170 $result->setObjectList($list);
171 $result->setNoDataString(pht('No dashboards found.'));
173 return $result;