Differential D17326 Diff 41682 src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | final class PhabricatorDashboardSearchEngine | ||||
protected function renderResultList( | protected function renderResultList( | ||||
array $dashboards, | array $dashboards, | ||||
PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
array $handles) { | array $handles) { | ||||
$dashboards = mpull($dashboards, null, 'getPHID'); | $dashboards = mpull($dashboards, null, 'getPHID'); | ||||
$viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
if ($dashboards) { | |||||
$installs = id(new PhabricatorDashboardInstall()) | |||||
->loadAllWhere( | |||||
'objectPHID IN (%Ls) AND dashboardPHID IN (%Ls)', | |||||
array( | |||||
PhabricatorHomeApplication::DASHBOARD_DEFAULT, | |||||
$viewer->getPHID(), | |||||
), | |||||
array_keys($dashboards)); | |||||
$installs = mpull($installs, null, 'getDashboardPHID'); | |||||
} else { | |||||
$installs = array(); | |||||
} | |||||
$proj_phids = array(); | $proj_phids = array(); | ||||
foreach ($dashboards as $dashboard) { | foreach ($dashboards as $dashboard) { | ||||
foreach ($dashboard->getProjectPHIDs() as $project_phid) { | foreach ($dashboard->getProjectPHIDs() as $project_phid) { | ||||
$proj_phids[] = $project_phid; | $proj_phids[] = $project_phid; | ||||
} | } | ||||
} | } | ||||
$proj_handles = id(new PhabricatorHandleQuery()) | $proj_handles = id(new PhabricatorHandleQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs($proj_phids) | ->withPHIDs($proj_phids) | ||||
->execute(); | ->execute(); | ||||
$list = new PHUIObjectItemListView(); | $list = id(new PHUIObjectItemListView()) | ||||
$list->setUser($viewer); | ->setUser($viewer); | ||||
$list->initBehavior('phabricator-tooltips', array()); | |||||
$list->requireResource('aphront-tooltip-css'); | |||||
foreach ($dashboards as $dashboard_phid => $dashboard) { | foreach ($dashboards as $dashboard_phid => $dashboard) { | ||||
$id = $dashboard->getID(); | $id = $dashboard->getID(); | ||||
$item = id(new PHUIObjectItemView()) | $item = id(new PHUIObjectItemView()) | ||||
->setObjectName(pht('Dashboard %d', $id)) | ->setUser($viewer) | ||||
->setHeader($dashboard->getName()) | ->setHeader($dashboard->getName()) | ||||
->setHref($this->getApplicationURI("view/{$id}/")) | ->setHref($this->getApplicationURI("view/{$id}/")) | ||||
->setObject($dashboard); | ->setObject($dashboard); | ||||
if (isset($installs[$dashboard_phid])) { | |||||
$install = $installs[$dashboard_phid]; | |||||
if ($install->getObjectPHID() == $viewer->getPHID()) { | |||||
$attrs = array( | |||||
'tip' => pht( | |||||
'This dashboard is installed to your personal homepage.'), | |||||
); | |||||
$item->addIcon('fa-user', pht('Installed'), $attrs); | |||||
} else { | |||||
$attrs = array( | |||||
'tip' => pht( | |||||
'This dashboard is the default homepage for all users.'), | |||||
); | |||||
$item->addIcon('fa-globe', pht('Installed'), $attrs); | |||||
} | |||||
} | |||||
$project_handles = array_select_keys( | $project_handles = array_select_keys( | ||||
$proj_handles, | $proj_handles, | ||||
$dashboard->getProjectPHIDs()); | $dashboard->getProjectPHIDs()); | ||||
$item->addAttribute( | $item->addAttribute( | ||||
id(new PHUIHandleTagListView()) | id(new PHUIHandleTagListView()) | ||||
->setLimit(4) | ->setLimit(4) | ||||
->setNoDataString(pht('No Projects')) | ->setNoDataString(pht('No Projects')) | ||||
->setSlim(true) | ->setSlim(true) | ||||
->setHandles($project_handles)); | ->setHandles($project_handles)); | ||||
if ($dashboard->isArchived()) { | if ($dashboard->isArchived()) { | ||||
$item->setDisabled(true); | $item->setDisabled(true); | ||||
} | } | ||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $icon = id(new PHUIIconView()) | ||||
$viewer, | ->setIcon($dashboard->getIcon()) | ||||
$dashboard, | ->setBackground('bg-dark'); | ||||
PhabricatorPolicyCapability::CAN_EDIT); | $item->setImageIcon($icon); | ||||
$item->setEpoch($dashboard->getDateModified()); | |||||
$href_view = $this->getApplicationURI("manage/{$id}/"); | |||||
$item->addAction( | |||||
id(new PHUIListItemView()) | |||||
->setName(pht('Manage')) | |||||
->setIcon('fa-th') | |||||
->setHref($href_view)); | |||||
$href_edit = $this->getApplicationURI("edit/{$id}/"); | |||||
$item->addAction( | |||||
id(new PHUIListItemView()) | |||||
->setName(pht('Edit')) | |||||
->setIcon('fa-pencil') | |||||
->setHref($href_edit) | |||||
->setDisabled(!$can_edit)); | |||||
epriestley: I'm slightly concerned that this may be difficult for users to find. Analogous actions, like… | |||||
$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 |
I'm slightly concerned that this may be difficult for users to find. Analogous actions, like "Preview" in Phame, are available from the object page, not from the search result list.