Differential D20411 Diff 48718 src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
| Show All 15 Lines | final class PhabricatorDashboardSearchEngine | ||||
| } | } | ||||
| public function canUseInPanelContext() { | public function canUseInPanelContext() { | ||||
| return false; | return false; | ||||
| } | } | ||||
| protected function buildCustomSearchFields() { | protected function buildCustomSearchFields() { | ||||
| return array( | return array( | ||||
| id(new PhabricatorSearchTextField()) | |||||
| ->setLabel(pht('Name Contains')) | |||||
| ->setKey('name') | |||||
| ->setDescription(pht('Search for dashboards by name substring.')), | |||||
| id(new PhabricatorSearchDatasourceField()) | id(new PhabricatorSearchDatasourceField()) | ||||
| ->setLabel(pht('Authored By')) | ->setLabel(pht('Authored By')) | ||||
| ->setKey('authorPHIDs') | ->setKey('authorPHIDs') | ||||
| ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()), | ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()), | ||||
| id(new PhabricatorSearchCheckboxesField()) | id(new PhabricatorSearchCheckboxesField()) | ||||
| ->setKey('statuses') | ->setKey('statuses') | ||||
| ->setLabel(pht('Status')) | ->setLabel(pht('Status')) | ||||
| ->setOptions(PhabricatorDashboard::getStatusNameMap()), | ->setOptions(PhabricatorDashboard::getStatusNameMap()), | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | protected function buildQueryFromParameters(array $map) { | ||||
| if ($map['statuses']) { | if ($map['statuses']) { | ||||
| $query->withStatuses($map['statuses']); | $query->withStatuses($map['statuses']); | ||||
| } | } | ||||
| if ($map['authorPHIDs']) { | if ($map['authorPHIDs']) { | ||||
| $query->withAuthorPHIDs($map['authorPHIDs']); | $query->withAuthorPHIDs($map['authorPHIDs']); | ||||
| } | } | ||||
| if ($map['name'] !== null) { | |||||
| $query->withNameNgrams($map['name']); | |||||
| } | |||||
| if ($map['editable'] !== null) { | if ($map['editable'] !== null) { | ||||
| $query->withCanEdit($map['editable']); | $query->withCanEdit($map['editable']); | ||||
| } | } | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| protected function renderResultList( | protected function renderResultList( | ||||
| array $dashboards, | array $dashboards, | ||||
| PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
| array $handles) { | array $handles) { | ||||
| $viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
| $phids = array(); | $phids = array(); | ||||
| foreach ($dashboards as $dashboard) { | foreach ($dashboards as $dashboard) { | ||||
| $author_phid = $dashboard->getAuthorPHID(); | $author_phid = $dashboard->getAuthorPHID(); | ||||
| if ($author_phid) { | if ($author_phid) { | ||||
| $phids[] = $author_phid; | $phids[] = $author_phid; | ||||
| } | } | ||||
| } | } | ||||
| $handles = $viewer->loadHandles($phids); | $handles = $viewer->loadHandles($phids); | ||||
| if ($dashboards) { | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs(mpull($dashboards, 'getPHID')) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | |||||
| } | |||||
| $list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
| ->setViewer($viewer); | ->setViewer($viewer); | ||||
| foreach ($dashboards as $dashboard) { | foreach ($dashboards as $dashboard) { | ||||
| $item = id(new PHUIObjectItemView()) | $item = id(new PHUIObjectItemView()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setObjectName($dashboard->getObjectName()) | ->setObjectName($dashboard->getObjectName()) | ||||
| ->setHeader($dashboard->getName()) | ->setHeader($dashboard->getName()) | ||||
| ->setHref($dashboard->getURI()) | ->setHref($dashboard->getURI()) | ||||
| ->setObject($dashboard); | ->setObject($dashboard); | ||||
| $bg_color = 'bg-dark'; | |||||
| if ($dashboard->isArchived()) { | if ($dashboard->isArchived()) { | ||||
| $item->setDisabled(true); | $item->setDisabled(true); | ||||
| $bg_color = 'bg-grey'; | $bg_color = 'bg-grey'; | ||||
| } else { | |||||
| $bg_color = 'bg-dark'; | |||||
| } | } | ||||
| $icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
| ->setIcon($dashboard->getIcon()) | ->setIcon($dashboard->getIcon()) | ||||
| ->setBackground($bg_color); | ->setBackground($bg_color); | ||||
| $item->setImageIcon($icon); | $item->setImageIcon($icon); | ||||
| $item->setEpoch($dashboard->getDateModified()); | $item->setEpoch($dashboard->getDateModified()); | ||||
| $author_phid = $dashboard->getAuthorPHID(); | $author_phid = $dashboard->getAuthorPHID(); | ||||
| $author_name = $handles[$author_phid]->renderLink(); | $author_name = $handles[$author_phid]->renderLink(); | ||||
| $item->addByline(pht('Author: %s', $author_name)); | $item->addByline(pht('Author: %s', $author_name)); | ||||
| $phid = $dashboard->getPHID(); | |||||
| $project_phids = $edge_query->getDestinationPHIDs(array($phid)); | |||||
| $project_handles = $viewer->loadHandles($project_phids); | |||||
| $item->addAttribute( | |||||
| id(new PHUIHandleTagListView()) | |||||
| ->setLimit(4) | |||||
| ->setNoDataString(pht('No Tags')) | |||||
| ->setSlim(true) | |||||
| ->setHandles($project_handles)); | |||||
| $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; | ||||
| } | } | ||||
| protected function getNewUserBody() { | |||||
| $create_button = id(new PHUIButtonView()) | |||||
| ->setTag('a') | |||||
| ->setText(pht('Create a Dashboard')) | |||||
| ->setHref('/dashboard/create/') | |||||
| ->setColor(PHUIButtonView::GREEN); | |||||
| $icon = $this->getApplication()->getIcon(); | |||||
| $app_name = $this->getApplication()->getName(); | |||||
| $view = id(new PHUIBigInfoView()) | |||||
| ->setIcon($icon) | |||||
| ->setTitle(pht('Welcome to %s', $app_name)) | |||||
| ->setDescription( | |||||
| pht('Customize your homepage with different panels and '. | |||||
| 'search queries.')) | |||||
| ->addAction($create_button); | |||||
| return $view; | |||||
| } | |||||
| } | } | ||||