3 final class AlmanacDeviceSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Almanac Devices');
10 public function getApplicationClassName() {
11 return 'PhabricatorAlmanacApplication';
14 public function newQuery() {
15 return new AlmanacDeviceQuery();
18 protected function buildCustomSearchFields() {
19 $status_options = AlmanacDeviceStatus
::getStatusMap();
20 $status_options = mpull($status_options, 'getName');
23 id(new PhabricatorSearchTextField())
24 ->setLabel(pht('Name Contains'))
26 ->setDescription(pht('Search for devices by name substring.')),
27 id(new PhabricatorSearchStringListField())
28 ->setLabel(pht('Exact Names'))
30 ->setDescription(pht('Search for devices with specific names.')),
31 id(new PhabricatorSearchCheckboxesField())
32 ->setLabel(pht('Statuses'))
34 ->setDescription(pht('Search for devices with given statuses.'))
35 ->setOptions($status_options),
36 id(new PhabricatorSearchThreeStateField())
37 ->setLabel(pht('Cluster Device'))
38 ->setKey('isClusterDevice')
40 pht('Both Cluster and Non-cluster Devices'),
41 pht('Cluster Devices Only'),
42 pht('Non-cluster Devices Only')),
46 protected function buildQueryFromParameters(array $map) {
47 $query = $this->newQuery();
49 if ($map['match'] !== null) {
50 $query->withNameNgrams($map['match']);
54 $query->withNames($map['names']);
57 if ($map['isClusterDevice'] !== null) {
58 $query->withIsClusterDevice($map['isClusterDevice']);
61 if ($map['statuses']) {
62 $query->withStatuses($map['statuses']);
68 protected function getURI($path) {
69 return '/almanac/device/'.$path;
72 protected function getBuiltinQueryNames() {
74 'active' => pht('Active Devices'),
75 'all' => pht('All Devices'),
81 public function buildSavedQueryFromBuiltin($query_key) {
82 $query = $this->newSavedQuery();
83 $query->setQueryKey($query_key);
87 $active_statuses = AlmanacDeviceStatus
::getActiveStatusList();
88 return $query->setParameter('statuses', $active_statuses);
93 return parent
::buildSavedQueryFromBuiltin($query_key);
96 protected function renderResultList(
98 PhabricatorSavedQuery
$query,
100 assert_instances_of($devices, 'AlmanacDevice');
102 $viewer = $this->requireViewer();
104 $list = new PHUIObjectItemListView();
105 $list->setUser($viewer);
106 foreach ($devices as $device) {
107 $item = id(new PHUIObjectItemView())
108 ->setObjectName(pht('Device %d', $device->getID()))
109 ->setHeader($device->getName())
110 ->setHref($device->getURI())
111 ->setObject($device);
113 if ($device->isClusterDevice()) {
114 $item->addIcon('fa-sitemap', pht('Cluster Device'));
117 if ($device->isDisabled()) {
118 $item->setDisabled(true);
121 $status = $device->getStatusObject();
122 $icon_icon = $status->getIconIcon();
123 $icon_color = $status->getIconColor();
124 $icon_label = $status->getName();
126 $item->setStatusIcon(
127 "{$icon_icon} {$icon_color}",
130 $list->addItem($item);
133 $result = new PhabricatorApplicationSearchResultView();
134 $result->setObjectList($list);
135 $result->setNoDataString(pht('No Almanac Devices found.'));