Differential D17340 Diff 41707 src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
<?php | <?php | ||||
final class PhabricatorDashboardSearchEngine | final class PhabricatorDashboardSearchEngine | ||||
extends PhabricatorApplicationSearchEngine { | extends PhabricatorApplicationSearchEngine { | ||||
public function getResultTypeDescription() { | public function getResultTypeDescription() { | ||||
return pht('Dashboards'); | return pht('Dashboards'); | ||||
} | } | ||||
public function getApplicationClassName() { | public function getApplicationClassName() { | ||||
return 'PhabricatorDashboardApplication'; | return 'PhabricatorDashboardApplication'; | ||||
} | } | ||||
public function newQuery() { | public function newQuery() { | ||||
return id(new PhabricatorDashboardQuery()) | return id(new PhabricatorDashboardQuery()) | ||||
->needProjects(true); | ->needPanels(true); | ||||
} | } | ||||
protected function buildCustomSearchFields() { | protected function buildCustomSearchFields() { | ||||
return array( | return array( | ||||
id(new PhabricatorSearchTextField()) | id(new PhabricatorSearchTextField()) | ||||
->setLabel(pht('Name Contains')) | ->setLabel(pht('Name Contains')) | ||||
->setKey('name') | ->setKey('name') | ||||
->setDescription(pht('Search for dashboards by name substring.')), | ->setDescription(pht('Search for dashboards by name substring.')), | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | protected function buildQueryFromParameters(array $map) { | ||||
return $query; | return $query; | ||||
} | } | ||||
protected function renderResultList( | protected function renderResultList( | ||||
array $dashboards, | array $dashboards, | ||||
PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
array $handles) { | array $handles) { | ||||
$dashboards = mpull($dashboards, null, 'getPHID'); | |||||
$viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
$proj_phids = array(); | $phids = array(); | ||||
foreach ($dashboards as $dashboard) { | foreach ($dashboards as $dashboard) { | ||||
foreach ($dashboard->getProjectPHIDs() as $project_phid) { | $author_phid = $dashboard->getAuthorPHID(); | ||||
$proj_phids[] = $project_phid; | if ($author_phid) { | ||||
$phids[] = $author_phid; | |||||
} | } | ||||
} | } | ||||
$proj_handles = id(new PhabricatorHandleQuery()) | $handles = $viewer->loadHandles($phids); | ||||
->setViewer($viewer) | |||||
->withPHIDs($proj_phids) | |||||
->execute(); | |||||
$list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
->setUser($viewer); | ->setUser($viewer); | ||||
foreach ($dashboards as $dashboard_phid => $dashboard) { | foreach ($dashboards as $dashboard) { | ||||
$id = $dashboard->getID(); | $id = $dashboard->getID(); | ||||
$item = id(new PHUIObjectItemView()) | $item = id(new PHUIObjectItemView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setHeader($dashboard->getName()) | ->setHeader($dashboard->getName()) | ||||
->setHref($this->getApplicationURI("view/{$id}/")) | ->setHref($this->getApplicationURI("view/{$id}/")) | ||||
->setObject($dashboard); | ->setObject($dashboard); | ||||
$project_handles = array_select_keys( | |||||
$proj_handles, | |||||
$dashboard->getProjectPHIDs()); | |||||
$item->addAttribute( | |||||
id(new PHUIHandleTagListView()) | |||||
->setLimit(4) | |||||
->setNoDataString(pht('No Projects')) | |||||
->setSlim(true) | |||||
->setHandles($project_handles)); | |||||
if ($dashboard->isArchived()) { | if ($dashboard->isArchived()) { | ||||
$item->setDisabled(true); | $item->setDisabled(true); | ||||
} | } | ||||
$panels = $dashboard->getPanels(); | |||||
foreach ($panels as $panel) { | |||||
$item->addAttribute($panel->getName()); | |||||
} | |||||
if (empty($panels)) { | |||||
$empty = phutil_tag('em', array(), pht('No panels.')); | |||||
$item->addAttribute($empty); | |||||
} | |||||
$icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
->setIcon($dashboard->getIcon()) | ->setIcon($dashboard->getIcon()) | ||||
->setBackground('bg-dark'); | ->setBackground('bg-dark'); | ||||
$item->setImageIcon($icon); | $item->setImageIcon($icon); | ||||
$item->setEpoch($dashboard->getDateModified()); | $item->setEpoch($dashboard->getDateModified()); | ||||
$author_phid = $dashboard->getAuthorPHID(); | |||||
$author_name = $handles[$author_phid]->renderLink(); | |||||
$item->addByline(pht('Author: %s', $author_name)); | |||||
$list->addItem($item); | $list->addItem($item); | ||||
} | } | ||||
$result = new PhabricatorApplicationSearchResultView(); | $result = new PhabricatorApplicationSearchResultView(); | ||||
$result->setObjectList($list); | $result->setObjectList($list); | ||||
$result->setNoDataString(pht('No dashboards found.')); | $result->setNoDataString(pht('No dashboards found.')); | ||||
return $result; | return $result; | ||||
Show All 23 Lines |