Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/controller/DifferentialRevisionInlinesController.php
12256 views
1
<?php
2
3
final class DifferentialRevisionInlinesController
4
extends DifferentialController {
5
6
public function shouldAllowPublic() {
7
return true;
8
}
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $this->getViewer();
12
$id = $request->getURIData('id');
13
14
$revision = id(new DifferentialRevisionQuery())
15
->withIDs(array($id))
16
->setViewer($viewer)
17
->needDiffIDs(true)
18
->executeOne();
19
if (!$revision) {
20
return new Aphront404Response();
21
}
22
23
$revision_monogram = $revision->getMonogram();
24
$revision_uri = $revision->getURI();
25
$revision_title = $revision->getTitle();
26
27
$inlines = id(new DifferentialDiffInlineCommentQuery())
28
->setViewer($viewer)
29
->withRevisionPHIDs(array($revision->getPHID()))
30
->withPublishedComments(true)
31
->execute();
32
$inlines = mpull($inlines, 'newInlineCommentObject');
33
34
$crumbs = $this->buildApplicationCrumbs();
35
$crumbs->addTextCrumb($revision_monogram, $revision_uri);
36
$crumbs->addTextCrumb(pht('Inline Comments'));
37
$crumbs->setBorder(true);
38
39
$content = $this->renderInlineTable($revision, $inlines);
40
$header = $this->buildHeader($revision);
41
42
$view = id(new PHUITwoColumnView())
43
->setHeader($header)
44
->setFooter($content);
45
46
return $this->newPage()
47
->setTitle(
48
array(
49
"{$revision_monogram} {$revision_title}",
50
pht('Inlines'),
51
))
52
->setCrumbs($crumbs)
53
->appendChild($view);
54
}
55
56
private function buildHeader(DifferentialRevision $revision) {
57
$viewer = $this->getViewer();
58
59
$button = id(new PHUIButtonView())
60
->setTag('a')
61
->setIcon('fa-chevron-left')
62
->setHref($revision->getURI())
63
->setText(pht('Back to Revision'));
64
65
return id(new PHUIHeaderView())
66
->setHeader($revision->getTitle())
67
->setUser($viewer)
68
->setHeaderIcon('fa-cog')
69
->addActionLink($button);
70
}
71
72
private function renderInlineTable(
73
DifferentialRevision $revision,
74
array $inlines) {
75
76
$viewer = $this->getViewer();
77
$inlines = id(new PHUIDiffInlineThreader())
78
->reorderAndThreadCommments($inlines);
79
80
$handle_phids = array();
81
$changeset_ids = array();
82
foreach ($inlines as $inline) {
83
$handle_phids[] = $inline->getAuthorPHID();
84
$changeset_ids[] = $inline->getChangesetID();
85
}
86
$handles = $viewer->loadHandles($handle_phids);
87
$handles = iterator_to_array($handles);
88
89
if ($changeset_ids) {
90
$changesets = id(new DifferentialChangesetQuery())
91
->setViewer($viewer)
92
->withIDs($changeset_ids)
93
->execute();
94
$changesets = mpull($changesets, null, 'getID');
95
} else {
96
$changesets = array();
97
}
98
99
$current_changeset = head($revision->getDiffIDs());
100
101
$rows = array();
102
foreach ($inlines as $inline) {
103
$status_icons = array();
104
105
$c_id = $inline->getChangesetID();
106
$d_id = $changesets[$c_id]->getDiffID();
107
108
if ($d_id == $current_changeset) {
109
$diff_id = phutil_tag('strong', array(), pht('Current'));
110
} else {
111
$diff_id = pht('Diff %d', $d_id);
112
}
113
114
$reviewer = $handles[$inline->getAuthorPHID()]->renderLink();
115
$now = PhabricatorTime::getNow();
116
$then = $inline->getDateModified();
117
$datetime = phutil_format_relative_time($now - $then);
118
119
$comment_href = $revision->getURI().'#inline-'.$inline->getID();
120
$comment = phutil_tag(
121
'a',
122
array(
123
'href' => $comment_href,
124
),
125
$inline->getContent());
126
127
$state = $inline->getFixedState();
128
if ($state == PhabricatorInlineComment::STATE_DONE) {
129
$status_icons[] = id(new PHUIIconView())
130
->setIcon('fa-check green')
131
->addClass('mmr');
132
} else if ($inline->getReplyToCommentPHID() &&
133
$inline->getAuthorPHID() == $revision->getAuthorPHID()) {
134
$status_icons[] = id(new PHUIIconView())
135
->setIcon('fa-commenting-o blue')
136
->addClass('mmr');
137
} else {
138
$status_icons[] = id(new PHUIIconView())
139
->setIcon('fa-circle-o grey')
140
->addClass('mmr');
141
}
142
143
144
if ($inline->getReplyToCommentPHID()) {
145
$reply_icon = id(new PHUIIconView())
146
->setIcon('fa-reply mmr darkgrey');
147
$comment = array($reply_icon, $comment);
148
}
149
150
$rows[] = array(
151
$diff_id,
152
$status_icons,
153
$reviewer,
154
AphrontTableView::renderSingleDisplayLine($comment),
155
$datetime,
156
);
157
}
158
159
$table = new AphrontTableView($rows);
160
$table->setHeaders(
161
array(
162
pht('Diff'),
163
pht('Status'),
164
pht('Reviewer'),
165
pht('Comment'),
166
pht('Created'),
167
));
168
$table->setColumnClasses(
169
array(
170
'',
171
'',
172
'',
173
'wide',
174
'right',
175
));
176
$table->setColumnVisibility(
177
array(
178
true,
179
true,
180
true,
181
true,
182
true,
183
));
184
185
return id(new PHUIObjectBoxView())
186
->setHeaderText(pht('Inline Comments'))
187
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
188
->setTable($table);
189
}
190
191
}
192
193