@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DrydockRepositoryOperationSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('Drydock Repository Operations');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorDrydockApplication::class;
12 }
13
14 public function newQuery() {
15 return id(new DrydockRepositoryOperationQuery());
16 }
17
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
20
21 if ($map['repositoryPHIDs']) {
22 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
23 }
24
25 if ($map['authorPHIDs']) {
26 $query->withAuthorPHIDs($map['authorPHIDs']);
27 }
28
29 if ($map['states']) {
30 $query->withOperationStates($map['states']);
31 }
32
33 return $query;
34 }
35
36 protected function buildCustomSearchFields() {
37 return array(
38 id(new PhabricatorSearchDatasourceField())
39 ->setLabel(pht('Repositories'))
40 ->setKey('repositoryPHIDs')
41 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
42 ->setDatasource(new DiffusionRepositoryFunctionDatasource()),
43
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'))
53 ->setKey('states')
54 ->setAliases(array('state'))
55 ->setOptions(DrydockRepositoryOperation::getOperationStateNameMap()),
56 );
57 }
58
59 protected function getURI($path) {
60 return '/drydock/operation/'.$path;
61 }
62
63 protected function getBuiltinQueryNames() {
64 return array(
65 'all' => pht('All Operations'),
66 );
67 }
68
69 public function buildSavedQueryFromBuiltin($query_key) {
70 $query = $this->newSavedQuery();
71 $query->setQueryKey($query_key);
72
73 switch ($query_key) {
74 case 'all':
75 return $query;
76 }
77
78 return parent::buildSavedQueryFromBuiltin($query_key);
79 }
80
81 /**
82 * @param array<DrydockRepositoryOperation> $operations
83 * @param PhabricatorSavedQuery $query
84 * @param array<PhabricatorObjectHandle> $handles
85 */
86 protected function renderResultList(
87 array $operations,
88 PhabricatorSavedQuery $query,
89 array $handles) {
90 assert_instances_of($operations, DrydockRepositoryOperation::class);
91
92 $viewer = $this->requireViewer();
93
94 $view = new PHUIObjectItemListView();
95 foreach ($operations as $operation) {
96 $id = $operation->getID();
97
98 $item = id(new PHUIObjectItemView())
99 ->setHeader($operation->getOperationDescription($viewer))
100 ->setHref($this->getApplicationURI("operation/{$id}/"))
101 ->setObjectName(pht('Repository Operation %d', $id));
102
103 $state = $operation->getOperationState();
104
105 $icon = DrydockRepositoryOperation::getOperationStateIcon($state);
106 $name = DrydockRepositoryOperation::getOperationStateName($state);
107
108 $item->setStatusIcon($icon, $name);
109
110
111 $created = phabricator_datetime($operation->getDateCreated(), $viewer);
112 $item->addIcon(null, $created);
113
114 $item->addByline(
115 array(
116 pht('Via:'),
117 ' ',
118 $viewer->renderHandle($operation->getAuthorPHID()),
119 ));
120
121 $object_phid = $operation->getObjectPHID();
122 $repository_phid = $operation->getRepositoryPHID();
123
124 $item->addAttribute($viewer->renderHandle($object_phid));
125
126 if ($repository_phid !== $object_phid) {
127 $item->addAttribute($viewer->renderHandle($repository_phid));
128 }
129
130 $view->addItem($item);
131 }
132
133 $result = id(new PhabricatorApplicationSearchResultView())
134 ->setObjectList($view)
135 ->setNoDataString(pht('No matching operations.'));
136
137 return $result;
138 }
139
140}