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() {
22 protected function buildCustomSearchFields() {
24 id(new PhabricatorSearchDatasourceField())
25 ->setLabel(pht('Authored By'))
26 ->setKey('authorPHIDs')
27 ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
28 id(new PhabricatorSearchCheckboxesField())
30 ->setLabel(pht('Status'))
31 ->setOptions(PhabricatorDashboard
::getStatusNameMap()),
32 id(new PhabricatorSearchCheckboxesField())
34 ->setLabel(pht('Editable'))
35 ->setOptions(array('editable' => null)),
39 protected function getURI($path) {
40 return '/dashboard/'.$path;
43 protected function getBuiltinQueryNames() {
46 if ($this->requireViewer()->isLoggedIn()) {
47 $names['authored'] = pht('Authored');
50 $names['open'] = pht('Active Dashboards');
51 $names['all'] = pht('All Dashboards');
56 public function buildSavedQueryFromBuiltin($query_key) {
57 $query = $this->newSavedQuery();
58 $query->setQueryKey($query_key);
59 $viewer = $this->requireViewer();
65 return $query->setParameter(
71 return $query->setParameter(
74 PhabricatorDashboard
::STATUS_ACTIVE
,
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']);
99 protected function renderResultList(
101 PhabricatorSavedQuery
$query,
104 $viewer = $this->requireViewer();
107 foreach ($dashboards as $dashboard) {
108 $author_phid = $dashboard->getAuthorPHID();
110 $phids[] = $author_phid;
114 $handles = $viewer->loadHandles($phids);
117 $edge_query = id(new PhabricatorEdgeQuery())
118 ->withSourcePHIDs(mpull($dashboards, 'getPHID'))
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())
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';
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);
160 id(new PHUIHandleTagListView())
162 ->setNoDataString(pht('No Tags'))
164 ->setHandles($project_handles));
166 $list->addItem($item);
169 $result = new PhabricatorApplicationSearchResultView();
170 $result->setObjectList($list);
171 $result->setNoDataString(pht('No dashboards found.'));