Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/query/DifferentialChangesetSearchEngine.php
12256 views
1
<?php
2
3
final class DifferentialChangesetSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
private $diff;
7
8
public function setDiff(DifferentialDiff $diff) {
9
$this->diff = $diff;
10
return $this;
11
}
12
13
public function getDiff() {
14
return $this->diff;
15
}
16
17
public function getResultTypeDescription() {
18
return pht('Differential Changesets');
19
}
20
21
public function getApplicationClassName() {
22
return 'PhabricatorDifferentialApplication';
23
}
24
25
public function canUseInPanelContext() {
26
return false;
27
}
28
29
public function newQuery() {
30
$query = id(new DifferentialChangesetQuery());
31
32
if ($this->diff) {
33
$query->withDiffs(array($this->diff));
34
}
35
36
return $query;
37
}
38
39
protected function buildQueryFromParameters(array $map) {
40
$query = $this->newQuery();
41
42
if ($map['diffPHIDs']) {
43
$query->withDiffPHIDs($map['diffPHIDs']);
44
}
45
46
return $query;
47
}
48
49
protected function buildCustomSearchFields() {
50
return array(
51
id(new PhabricatorPHIDsSearchField())
52
->setLabel(pht('Diffs'))
53
->setKey('diffPHIDs')
54
->setAliases(array('diff', 'diffs', 'diffPHID'))
55
->setDescription(
56
pht('Find changesets attached to a particular diff.')),
57
);
58
}
59
60
protected function getURI($path) {
61
$diff = $this->getDiff();
62
if ($diff) {
63
return '/differential/diff/'.$diff->getID().'/changesets/'.$path;
64
}
65
66
throw new PhutilMethodNotImplementedException();
67
}
68
69
protected function getBuiltinQueryNames() {
70
$names = array();
71
$names['all'] = pht('All Changesets');
72
return $names;
73
}
74
75
public function buildSavedQueryFromBuiltin($query_key) {
76
$query = $this->newSavedQuery();
77
$query->setQueryKey($query_key);
78
79
$viewer = $this->requireViewer();
80
81
switch ($query_key) {
82
case 'all':
83
return $query->setParameter('order', 'oldest');
84
}
85
86
return parent::buildSavedQueryFromBuiltin($query_key);
87
}
88
89
protected function renderResultList(
90
array $changesets,
91
PhabricatorSavedQuery $query,
92
array $handles) {
93
94
assert_instances_of($changesets, 'DifferentialChangeset');
95
$viewer = $this->requireViewer();
96
97
$rows = array();
98
foreach ($changesets as $changeset) {
99
$link = phutil_tag(
100
'a',
101
array(
102
'href' => '/differential/changeset/?ref='.$changeset->getID(),
103
),
104
$changeset->getDisplayFilename());
105
106
$type = $changeset->getChangeType();
107
108
$title = DifferentialChangeType::getFullNameForChangeType($type);
109
110
$add_lines = $changeset->getAddLines();
111
if (!$add_lines) {
112
$add_lines = null;
113
} else {
114
$add_lines = '+'.$add_lines;
115
}
116
117
$rem_lines = $changeset->getDelLines();
118
if (!$rem_lines) {
119
$rem_lines = null;
120
} else {
121
$rem_lines = '-'.$rem_lines;
122
}
123
124
$rows[] = array(
125
$changeset->newFileTreeIcon(),
126
$title,
127
$link,
128
);
129
}
130
131
$table = id(new AphrontTableView($rows))
132
->setHeaders(
133
array(
134
null,
135
pht('Change'),
136
pht('Path'),
137
))
138
->setColumnClasses(
139
array(
140
null,
141
null,
142
'pri wide',
143
));
144
145
return id(new PhabricatorApplicationSearchResultView())
146
->setTable($table);
147
}
148
149
}
150
151