3 final class DrydockRepositoryOperationSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Drydock Repository Operations');
10 public function getApplicationClassName() {
11 return 'PhabricatorDrydockApplication';
14 public function newQuery() {
15 return id(new DrydockRepositoryOperationQuery());
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['repositoryPHIDs']) {
22 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
25 if ($map['authorPHIDs']) {
26 $query->withAuthorPHIDs($map['authorPHIDs']);
30 $query->withOperationStates($map['states']);
36 protected function buildCustomSearchFields() {
38 id(new PhabricatorSearchDatasourceField())
39 ->setLabel(pht('Repositories'))
40 ->setKey('repositoryPHIDs')
41 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
42 ->setDatasource(new DiffusionRepositoryFunctionDatasource()),
44 // NOTE: Repository operations aren't necessarily created by a real
45 // user, but for now they normally are. Just use a user typeahead until
46 // more use cases arise.
47 id(new PhabricatorUsersSearchField())
48 ->setLabel(pht('Authors'))
49 ->setKey('authorPHIDs')
50 ->setAliases(array('author', 'authors', 'authorPHID')),
51 id(new PhabricatorSearchCheckboxesField())
52 ->setLabel(pht('States'))
54 ->setAliases(array('state'))
55 ->setOptions(DrydockRepositoryOperation
::getOperationStateNameMap()),
59 protected function getURI($path) {
60 return '/drydock/operation/'.$path;
63 protected function getBuiltinQueryNames() {
65 'all' => pht('All Operations'),
69 public function buildSavedQueryFromBuiltin($query_key) {
70 $query = $this->newSavedQuery();
71 $query->setQueryKey($query_key);
78 return parent
::buildSavedQueryFromBuiltin($query_key);
81 protected function renderResultList(
83 PhabricatorSavedQuery
$query,
85 assert_instances_of($operations, 'DrydockRepositoryOperation');
87 $viewer = $this->requireViewer();
89 $view = new PHUIObjectItemListView();
90 foreach ($operations as $operation) {
91 $id = $operation->getID();
93 $item = id(new PHUIObjectItemView())
94 ->setHeader($operation->getOperationDescription($viewer))
95 ->setHref($this->getApplicationURI("operation/{$id}/"))
96 ->setObjectName(pht('Repository Operation %d', $id));
98 $state = $operation->getOperationState();
100 $icon = DrydockRepositoryOperation
::getOperationStateIcon($state);
101 $name = DrydockRepositoryOperation
::getOperationStateName($state);
103 $item->setStatusIcon($icon, $name);
106 $created = phabricator_datetime($operation->getDateCreated(), $viewer);
107 $item->addIcon(null, $created);
113 $viewer->renderHandle($operation->getAuthorPHID()),
116 $object_phid = $operation->getObjectPHID();
117 $repository_phid = $operation->getRepositoryPHID();
119 $item->addAttribute($viewer->renderHandle($object_phid));
121 if ($repository_phid !== $object_phid) {
122 $item->addAttribute($viewer->renderHandle($repository_phid));
125 $view->addItem($item);
128 $result = id(new PhabricatorApplicationSearchResultView())
129 ->setObjectList($view)
130 ->setNoDataString(pht('No matching operations.'));