Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php
<?php | <?php | ||||
final class AlmanacInterfaceDatasource | final class AlmanacInterfaceDatasource | ||||
extends PhabricatorTypeaheadDatasource { | extends PhabricatorTypeaheadDatasource { | ||||
public function isBrowsable() { | |||||
// TODO: We should make this browsable, but need to make the result set | |||||
// orderable by device name. | |||||
return false; | |||||
} | |||||
public function getBrowseTitle() { | public function getBrowseTitle() { | ||||
return pht('Browse Interfaces'); | return pht('Browse Interfaces'); | ||||
} | } | ||||
public function getPlaceholderText() { | public function getPlaceholderText() { | ||||
return pht('Type an interface name...'); | return pht('Type an interface name...'); | ||||
} | } | ||||
public function getDatasourceApplicationClass() { | public function getDatasourceApplicationClass() { | ||||
return 'PhabricatorAlmanacApplication'; | return 'PhabricatorAlmanacApplication'; | ||||
} | } | ||||
public function loadResults() { | public function loadResults() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$raw_query = $this->getRawQuery(); | $raw_query = $this->getRawQuery(); | ||||
$devices = id(new AlmanacDeviceQuery()) | $devices = id(new AlmanacDeviceQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withNamePrefix($raw_query) | ->withNamePrefix($raw_query) | ||||
->execute(); | ->execute(); | ||||
if ($devices) { | if ($devices) { | ||||
$interfaces = id(new AlmanacInterfaceQuery()) | $interface_query = id(new AlmanacInterfaceQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withDevicePHIDs(mpull($devices, 'getPHID')) | ->withDevicePHIDs(mpull($devices, 'getPHID')) | ||||
->execute(); | ->setOrder('name'); | ||||
$interfaces = $this->executeQuery($interface_query); | |||||
} else { | } else { | ||||
$interfaces = array(); | $interfaces = array(); | ||||
} | } | ||||
if ($interfaces) { | if ($interfaces) { | ||||
$handles = id(new PhabricatorHandleQuery()) | $handles = id(new PhabricatorHandleQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(mpull($interfaces, 'getPHID')) | ->withPHIDs(mpull($interfaces, 'getPHID')) | ||||
Show All 16 Lines |