Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php
12242 views
1
<?php
2
3
final class PHUIDiffTableOfContentsItemView extends AphrontView {
4
5
private $changeset;
6
private $isVisible = true;
7
private $anchor;
8
private $coverage;
9
private $coverageID;
10
private $context;
11
private $packages;
12
13
public function setChangeset(DifferentialChangeset $changeset) {
14
$this->changeset = $changeset;
15
return $this;
16
}
17
18
public function getChangeset() {
19
return $this->changeset;
20
}
21
22
public function setIsVisible($is_visible) {
23
$this->isVisible = $is_visible;
24
return $this;
25
}
26
27
public function getIsVisible() {
28
return $this->isVisible;
29
}
30
31
public function setAnchor($anchor) {
32
$this->anchor = $anchor;
33
return $this;
34
}
35
36
public function getAnchor() {
37
return $this->anchor;
38
}
39
40
public function setCoverage($coverage) {
41
$this->coverage = $coverage;
42
return $this;
43
}
44
45
public function getCoverage() {
46
return $this->coverage;
47
}
48
49
public function setCoverageID($coverage_id) {
50
$this->coverageID = $coverage_id;
51
return $this;
52
}
53
54
public function getCoverageID() {
55
return $this->coverageID;
56
}
57
58
public function setContext($context) {
59
$this->context = $context;
60
return $this;
61
}
62
63
public function getContext() {
64
return $this->context;
65
}
66
67
public function setPackages(array $packages) {
68
assert_instances_of($packages, 'PhabricatorOwnersPackage');
69
$this->packages = mpull($packages, null, 'getPHID');
70
return $this;
71
}
72
73
public function getPackages() {
74
return $this->packages;
75
}
76
77
public function render() {
78
$changeset = $this->getChangeset();
79
80
$cells = array();
81
82
$cells[] = $this->getContext();
83
84
$cells[] = $changeset->newFileTreeIcon();
85
86
$link = $this->renderChangesetLink();
87
$lines = $this->renderChangesetLines();
88
$meta = $this->renderChangesetMetadata();
89
90
$cells[] = array(
91
$link,
92
$lines,
93
$meta,
94
);
95
96
$cells[] = $this->renderCoverage();
97
$cells[] = $this->renderModifiedCoverage();
98
99
$cells[] = $this->renderPackages();
100
101
return $cells;
102
}
103
104
public function newLink() {
105
$anchor = $this->getAnchor();
106
107
$changeset = $this->getChangeset();
108
$name = $changeset->getDisplayFilename();
109
$name = basename($name);
110
111
return javelin_tag(
112
'a',
113
array(
114
'href' => '#'.$anchor,
115
'sigil' => 'differential-load',
116
'meta' => array(
117
'id' => 'diff-'.$anchor,
118
),
119
),
120
$name);
121
}
122
123
public function renderChangesetLines() {
124
$changeset = $this->getChangeset();
125
126
if ($changeset->getIsLowImportanceChangeset()) {
127
return null;
128
}
129
130
$line_count = $changeset->getAffectedLineCount();
131
if (!$line_count) {
132
return null;
133
}
134
135
return pht('%d line(s)', $line_count);
136
}
137
138
public function renderCoverage() {
139
$not_applicable = '-';
140
141
$coverage = $this->getCoverage();
142
if ($coverage === null || !strlen($coverage)) {
143
return $not_applicable;
144
}
145
146
$covered = substr_count($coverage, 'C');
147
$not_covered = substr_count($coverage, 'U');
148
149
if (!$not_covered && !$covered) {
150
return $not_applicable;
151
}
152
153
return sprintf('%d%%', 100 * ($covered / ($covered + $not_covered)));
154
}
155
156
public function renderModifiedCoverage() {
157
$not_applicable = '-';
158
159
$coverage = $this->getCoverage();
160
if ($coverage === null || !strlen($coverage)) {
161
return $not_applicable;
162
}
163
164
if ($this->getIsVisible()) {
165
$label = pht('Loading...');
166
} else {
167
$label = pht('?');
168
}
169
170
return phutil_tag(
171
'div',
172
array(
173
'id' => $this->getCoverageID(),
174
'class' => 'differential-mcoverage-loading',
175
),
176
$label);
177
}
178
179
private function renderChangesetMetadata() {
180
$changeset = $this->getChangeset();
181
$type = $changeset->getChangeType();
182
183
$meta = array();
184
if (DifferentialChangeType::isOldLocationChangeType($type)) {
185
$away = $changeset->getAwayPaths();
186
if (count($away) > 1) {
187
if ($type == DifferentialChangeType::TYPE_MULTICOPY) {
188
$meta[] = pht('Deleted after being copied to multiple locations:');
189
} else {
190
$meta[] = pht('Copied to multiple locations:');
191
}
192
foreach ($away as $path) {
193
$meta[] = $path;
194
}
195
} else {
196
if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) {
197
// This case is handled when we render the path.
198
} else {
199
$meta[] = pht('Copied to %s', head($away));
200
}
201
}
202
} else if ($type == DifferentialChangeType::TYPE_COPY_HERE) {
203
$meta[] = pht('Copied from %s', $changeset->getOldFile());
204
}
205
206
if (!$meta) {
207
return null;
208
}
209
210
$meta = phutil_implode_html(phutil_tag('br'), $meta);
211
212
return phutil_tag(
213
'div',
214
array(
215
'class' => 'differential-toc-meta',
216
),
217
$meta);
218
}
219
220
public function renderPackages() {
221
$packages = $this->getPackages();
222
223
if (!$packages) {
224
return null;
225
}
226
227
$viewer = $this->getViewer();
228
$package_phids = mpull($packages, 'getPHID');
229
230
return $viewer->renderHandleList($package_phids)
231
->setGlyphLimit(48);
232
}
233
234
}
235
236