2011-02-02 01:42:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialInlineCommentView extends AphrontView {
|
|
|
|
|
|
|
|
private $inlineComment;
|
|
|
|
private $onRight;
|
|
|
|
private $buildScaffolding;
|
|
|
|
private $handles;
|
|
|
|
private $markupEngine;
|
2011-02-02 19:10:25 +01:00
|
|
|
private $editable;
|
2011-06-09 20:09:54 +02:00
|
|
|
private $preview;
|
2012-04-18 06:18:30 +02:00
|
|
|
private $allowReply;
|
2011-02-02 01:42:36 +01:00
|
|
|
|
Add inline comments to Diffusion/Audit
Summary:
- Add inline comments to Audits, like Differential.
- Creates new storage for the comments in the Audits database.
- Creates a new PhabricatorAuditInlineComment class, similar to DifferentialInlineComment.
- Defines an Interface which Differential and Audit comments conform to.
- Makes consumers of DifferentialInlineComments consume objects which implement that interface instead.
- Adds save
NOTE: Some features are still missing! Wanted to cut this off before it got crazy:
- Inline comments aren't shown in the main comment list.
- Inline comments aren't shown in the emails.
- Inline comments aren't previewed.
I'll followup with those but this was getting pretty big.
@vrana, does the SQL change look correct?
Test Plan:
- Created, edited, deleted, replied to, reloaded and saved inline comments in Diffusion, on the left and right side of diffs.
- Created, edited, deleted, replied to, reloaded and saved inline comments in Differentila, on the left and right side of primary and diff-versus-diff diffs.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran, epriestley
Maniphest Tasks: T904
Differential Revision: https://secure.phabricator.com/D1898
2012-03-14 20:56:01 +01:00
|
|
|
public function setInlineComment(PhabricatorInlineCommentInterface $comment) {
|
2011-02-02 01:42:36 +01:00
|
|
|
$this->inlineComment = $comment;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOnRight($on_right) {
|
|
|
|
$this->onRight = $on_right;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBuildScaffolding($scaffold) {
|
|
|
|
$this->buildScaffolding = $scaffold;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
public function setHandles(array $handles) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2011-02-02 01:42:36 +01:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2012-10-24 02:33:58 +02:00
|
|
|
public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
|
2011-02-02 01:42:36 +01:00
|
|
|
$this->markupEngine = $engine;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
public function setEditable($editable) {
|
|
|
|
$this->editable = $editable;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-06-09 20:09:54 +02:00
|
|
|
public function setPreview($preview) {
|
|
|
|
$this->preview = $preview;
|
2012-04-03 03:35:09 +02:00
|
|
|
return $this;
|
2011-06-09 20:09:54 +02:00
|
|
|
}
|
|
|
|
|
2012-04-18 06:18:30 +02:00
|
|
|
public function setAllowReply($allow_reply) {
|
|
|
|
$this->allowReply = $allow_reply;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
public function render() {
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$inline = $this->inlineComment;
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$start = $inline->getLineNumber();
|
|
|
|
$length = $inline->getLineLength();
|
|
|
|
if ($length) {
|
|
|
|
$end = $start + $length;
|
|
|
|
$line = 'Lines '.number_format($start).'-'.number_format($end);
|
|
|
|
} else {
|
|
|
|
$line = 'Line '.number_format($start);
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$metadata = array(
|
2011-02-02 19:10:25 +01:00
|
|
|
'id' => $inline->getID(),
|
2011-02-02 01:42:36 +01:00
|
|
|
'number' => $inline->getLineNumber(),
|
|
|
|
'length' => $inline->getLineLength(),
|
2011-02-02 19:10:25 +01:00
|
|
|
'on_right' => $this->onRight,
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
'original' => $inline->getContent(),
|
2011-02-02 01:42:36 +01:00
|
|
|
);
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$sigil = 'differential-inline-comment';
|
2012-08-02 21:24:23 +02:00
|
|
|
if ($this->preview) {
|
|
|
|
$sigil = $sigil . ' differential-inline-comment-preview';
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$content = $inline->getContent();
|
|
|
|
$handles = $this->handles;
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$links = array();
|
2011-04-15 03:08:10 +02:00
|
|
|
|
2012-01-04 18:10:37 +01:00
|
|
|
$is_synthetic = false;
|
|
|
|
if ($inline->getSyntheticAuthor()) {
|
|
|
|
$is_synthetic = true;
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:42:27 +02:00
|
|
|
$is_draft = false;
|
Add inline comments to Diffusion/Audit
Summary:
- Add inline comments to Audits, like Differential.
- Creates new storage for the comments in the Audits database.
- Creates a new PhabricatorAuditInlineComment class, similar to DifferentialInlineComment.
- Defines an Interface which Differential and Audit comments conform to.
- Makes consumers of DifferentialInlineComments consume objects which implement that interface instead.
- Adds save
NOTE: Some features are still missing! Wanted to cut this off before it got crazy:
- Inline comments aren't shown in the main comment list.
- Inline comments aren't shown in the emails.
- Inline comments aren't previewed.
I'll followup with those but this was getting pretty big.
@vrana, does the SQL change look correct?
Test Plan:
- Created, edited, deleted, replied to, reloaded and saved inline comments in Diffusion, on the left and right side of diffs.
- Created, edited, deleted, replied to, reloaded and saved inline comments in Differentila, on the left and right side of primary and diff-versus-diff diffs.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran, epriestley
Maniphest Tasks: T904
Differential Revision: https://secure.phabricator.com/D1898
2012-03-14 20:56:01 +01:00
|
|
|
if ($inline->isDraft() && !$is_synthetic) {
|
2013-01-24 22:18:44 +01:00
|
|
|
$links[] = pht('Not Submitted Yet');
|
2011-06-14 21:42:27 +02:00
|
|
|
$is_draft = true;
|
|
|
|
}
|
|
|
|
|
2011-06-09 20:09:54 +02:00
|
|
|
if (!$this->preview) {
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2011-06-09 20:09:54 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-prev',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Previous'));
|
2011-05-11 21:25:29 +02:00
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2011-06-09 20:09:54 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-next',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Next'));
|
2011-05-11 21:25:29 +02:00
|
|
|
|
2012-04-18 06:18:30 +02:00
|
|
|
if ($this->allowReply) {
|
|
|
|
|
|
|
|
if (!$is_synthetic) {
|
|
|
|
|
|
|
|
// NOTE: No product reason why you can't reply to these, but the reply
|
|
|
|
// mechanism currently sends the inline comment ID to the server, not
|
|
|
|
// file/line information, and synthetic comments don't have an inline
|
|
|
|
// comment ID.
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2012-04-18 06:18:30 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-reply',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Reply'));
|
2012-04-18 06:18:30 +02:00
|
|
|
}
|
|
|
|
|
2012-01-04 18:10:37 +01:00
|
|
|
}
|
2011-06-09 20:09:54 +02:00
|
|
|
}
|
2011-04-15 03:08:10 +02:00
|
|
|
|
2012-03-28 19:11:41 +02:00
|
|
|
$anchor_name = 'inline-'.$inline->getID();
|
|
|
|
|
2011-06-09 20:09:54 +02:00
|
|
|
if ($this->editable && !$this->preview) {
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2011-02-02 19:10:25 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-edit',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Edit'));
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2011-02-02 19:10:25 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-delete',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Delete'));
|
2012-03-28 19:11:41 +02:00
|
|
|
} else if ($this->preview) {
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2012-03-28 19:11:41 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'meta' => array(
|
|
|
|
'anchor' => $anchor_name,
|
|
|
|
),
|
|
|
|
'sigil' => 'differential-inline-preview-jump',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Not Visible'));
|
2013-01-25 21:57:17 +01:00
|
|
|
$links[] = javelin_tag(
|
2012-08-02 21:24:23 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-delete',
|
|
|
|
),
|
2013-01-24 22:18:44 +01:00
|
|
|
pht('Delete'));
|
2011-02-02 19:10:25 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
if ($links) {
|
2011-02-02 22:48:52 +01:00
|
|
|
$links =
|
2011-02-02 01:42:36 +01:00
|
|
|
'<span class="differential-inline-comment-links">'.
|
2011-02-02 19:10:25 +01:00
|
|
|
implode(' · ', $links).
|
2011-02-02 01:42:36 +01:00
|
|
|
'</span>';
|
2011-02-02 19:10:25 +01:00
|
|
|
} else {
|
|
|
|
$links = null;
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2012-10-24 02:33:58 +02:00
|
|
|
$content = $this->markupEngine->getOutput(
|
|
|
|
$inline,
|
|
|
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2012-03-28 19:11:41 +02:00
|
|
|
if ($this->preview) {
|
|
|
|
$anchor = null;
|
|
|
|
} else {
|
2013-01-18 03:57:09 +01:00
|
|
|
$anchor = phutil_tag(
|
2012-03-28 19:11:41 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'name' => $anchor_name,
|
|
|
|
'id' => $anchor_name,
|
|
|
|
'class' => 'differential-inline-comment-anchor',
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
2011-02-14 01:00:21 +01:00
|
|
|
|
2011-06-14 21:42:27 +02:00
|
|
|
$classes = array(
|
|
|
|
'differential-inline-comment',
|
|
|
|
);
|
|
|
|
if ($is_draft) {
|
|
|
|
$classes[] = 'differential-inline-comment-unsaved-draft';
|
|
|
|
}
|
2012-01-04 18:10:37 +01:00
|
|
|
if ($is_synthetic) {
|
|
|
|
$classes[] = 'differential-inline-comment-synthetic';
|
|
|
|
}
|
2011-06-14 21:42:27 +02:00
|
|
|
$classes = implode(' ', $classes);
|
|
|
|
|
2012-01-04 18:10:37 +01:00
|
|
|
if ($is_synthetic) {
|
|
|
|
$author = $inline->getSyntheticAuthor();
|
|
|
|
} else {
|
|
|
|
$author = $handles[$inline->getAuthorPHID()]->getName();
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$markup = javelin_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2011-06-14 21:42:27 +02:00
|
|
|
'class' => $classes,
|
2011-02-02 01:42:36 +01:00
|
|
|
'sigil' => $sigil,
|
|
|
|
'meta' => $metadata,
|
|
|
|
),
|
|
|
|
'<div class="differential-inline-comment-head">'.
|
2011-02-14 01:00:21 +01:00
|
|
|
$anchor.
|
2011-02-02 01:42:36 +01:00
|
|
|
$links.
|
2012-03-15 13:40:23 +01:00
|
|
|
' <span class="differential-inline-comment-line">'.$line.'</span> '.
|
2012-01-04 18:10:37 +01:00
|
|
|
phutil_escape_html($author).
|
2011-02-02 01:42:36 +01:00
|
|
|
'</div>'.
|
2012-02-19 18:07:35 +01:00
|
|
|
'<div class="differential-inline-comment-content">'.
|
|
|
|
'<div class="phabricator-remarkup">'.
|
|
|
|
$content.
|
|
|
|
'</div>'.
|
2011-03-30 06:38:05 +02:00
|
|
|
'</div>');
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
return $this->scaffoldMarkup($markup);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function scaffoldMarkup($markup) {
|
|
|
|
if (!$this->buildScaffolding) {
|
|
|
|
return $markup;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-04-15 03:08:10 +02:00
|
|
|
$left_markup = !$this->onRight ? $markup : '';
|
|
|
|
$right_markup = $this->onRight ? $markup : '';
|
|
|
|
|
|
|
|
return
|
|
|
|
'<table>'.
|
|
|
|
'<tr class="inline">'.
|
|
|
|
'<th></th>'.
|
2012-12-12 02:16:11 +01:00
|
|
|
'<td class="left">'.$left_markup.'</td>'.
|
2011-04-15 03:08:10 +02:00
|
|
|
'<th></th>'.
|
2012-12-12 02:16:11 +01:00
|
|
|
'<td class="right3" colspan="3">'.$right_markup.'</td>'.
|
2011-04-15 03:08:10 +02:00
|
|
|
'</tr>'.
|
|
|
|
'</table>';
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|