Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacDeviceSearchEngine.php
Show All 10 Lines | public function getApplicationClassName() { | ||||
return 'PhabricatorAlmanacApplication'; | return 'PhabricatorAlmanacApplication'; | ||||
} | } | ||||
public function newQuery() { | public function newQuery() { | ||||
return new AlmanacDeviceQuery(); | return new AlmanacDeviceQuery(); | ||||
} | } | ||||
protected function buildCustomSearchFields() { | protected function buildCustomSearchFields() { | ||||
$status_options = AlmanacDeviceStatus::getStatusMap(); | |||||
$status_options = mpull($status_options, 'getName'); | |||||
return array( | return array( | ||||
id(new PhabricatorSearchTextField()) | id(new PhabricatorSearchTextField()) | ||||
->setLabel(pht('Name Contains')) | ->setLabel(pht('Name Contains')) | ||||
->setKey('match') | ->setKey('match') | ||||
->setDescription(pht('Search for devices by name substring.')), | ->setDescription(pht('Search for devices by name substring.')), | ||||
id(new PhabricatorSearchStringListField()) | id(new PhabricatorSearchStringListField()) | ||||
->setLabel(pht('Exact Names')) | ->setLabel(pht('Exact Names')) | ||||
->setKey('names') | ->setKey('names') | ||||
->setDescription(pht('Search for devices with specific names.')), | ->setDescription(pht('Search for devices with specific names.')), | ||||
id(new PhabricatorSearchCheckboxesField()) | |||||
->setLabel(pht('Statuses')) | |||||
->setKey('statuses') | |||||
->setDescription(pht('Search for devices with given statuses.')) | |||||
->setOptions($status_options), | |||||
id(new PhabricatorSearchThreeStateField()) | id(new PhabricatorSearchThreeStateField()) | ||||
->setLabel(pht('Cluster Device')) | ->setLabel(pht('Cluster Device')) | ||||
->setKey('isClusterDevice') | ->setKey('isClusterDevice') | ||||
->setOptions( | ->setOptions( | ||||
pht('Both Cluster and Non-cluster Devices'), | pht('Both Cluster and Non-cluster Devices'), | ||||
pht('Cluster Devices Only'), | pht('Cluster Devices Only'), | ||||
pht('Non-cluster Devices Only')), | pht('Non-cluster Devices Only')), | ||||
); | ); | ||||
Show All 9 Lines | protected function buildQueryFromParameters(array $map) { | ||||
if ($map['names']) { | if ($map['names']) { | ||||
$query->withNames($map['names']); | $query->withNames($map['names']); | ||||
} | } | ||||
if ($map['isClusterDevice'] !== null) { | if ($map['isClusterDevice'] !== null) { | ||||
$query->withIsClusterDevice($map['isClusterDevice']); | $query->withIsClusterDevice($map['isClusterDevice']); | ||||
} | } | ||||
if ($map['statuses']) { | |||||
$query->withStatuses($map['statuses']); | |||||
} | |||||
return $query; | return $query; | ||||
} | } | ||||
protected function getURI($path) { | protected function getURI($path) { | ||||
return '/almanac/device/'.$path; | return '/almanac/device/'.$path; | ||||
} | } | ||||
protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
Show All 33 Lines | foreach ($devices as $device) { | ||||
->setHeader($device->getName()) | ->setHeader($device->getName()) | ||||
->setHref($device->getURI()) | ->setHref($device->getURI()) | ||||
->setObject($device); | ->setObject($device); | ||||
if ($device->isClusterDevice()) { | if ($device->isClusterDevice()) { | ||||
$item->addIcon('fa-sitemap', pht('Cluster Device')); | $item->addIcon('fa-sitemap', pht('Cluster Device')); | ||||
} | } | ||||
if ($device->isDisabled()) { | |||||
$item->setDisabled(true); | |||||
} | |||||
$status = $device->getStatusObject(); | |||||
$icon_icon = $status->getIconIcon(); | |||||
$icon_color = $status->getIconColor(); | |||||
$icon_label = $status->getName(); | |||||
$item->setStatusIcon( | |||||
"{$icon_icon} {$icon_color}", | |||||
$icon_label); | |||||
$list->addItem($item); | $list->addItem($item); | ||||
} | } | ||||
$result = new PhabricatorApplicationSearchResultView(); | $result = new PhabricatorApplicationSearchResultView(); | ||||
$result->setObjectList($list); | $result->setObjectList($list); | ||||
$result->setNoDataString(pht('No Almanac Devices found.')); | $result->setNoDataString(pht('No Almanac Devices found.')); | ||||
return $result; | return $result; | ||||
} | } | ||||
} | } |