1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 18:32:41 +01:00
phorge-phorge/src/applications/differential/view/DifferentialInlineCommentView.php

262 lines
6.3 KiB
PHP
Raw Normal View History

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;
private $preview;
private $allowReply;
2011-02-02 01:42:36 +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) {
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
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;
}
public function setPreview($preview) {
$this->preview = $preview;
return $this;
}
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,
'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';
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();
$is_synthetic = false;
if ($inline->getSyntheticAuthor()) {
$is_synthetic = true;
}
$is_draft = false;
if ($inline->isDraft() && !$is_synthetic) {
$links[] = pht('Not Submitted Yet');
$is_draft = true;
}
if (!$this->preview) {
$links[] = javelin_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-prev',
),
pht('Previous'));
$links[] = javelin_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-next',
),
pht('Next'));
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.
$links[] = javelin_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-reply',
),
pht('Reply'));
}
}
}
$anchor_name = 'inline-'.$inline->getID();
if ($this->editable && !$this->preview) {
$links[] = javelin_tag(
2011-02-02 19:10:25 +01:00
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-edit',
),
pht('Edit'));
$links[] = javelin_tag(
2011-02-02 19:10:25 +01:00
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-delete',
),
pht('Delete'));
} else if ($this->preview) {
$links[] = javelin_tag(
'a',
array(
'meta' => array(
'anchor' => $anchor_name,
),
'sigil' => 'differential-inline-preview-jump',
),
pht('Not Visible'));
$links[] = javelin_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-inline-delete',
),
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(' &middot; ', $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
$content = $this->markupEngine->getOutput(
$inline,
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
2011-02-02 22:48:52 +01:00
if ($this->preview) {
$anchor = null;
} else {
$anchor = phutil_tag(
'a',
array(
'name' => $anchor_name,
'id' => $anchor_name,
'class' => 'differential-inline-comment-anchor',
),
'');
}
$classes = array(
'differential-inline-comment',
);
if ($is_draft) {
$classes[] = 'differential-inline-comment-unsaved-draft';
}
if ($is_synthetic) {
$classes[] = 'differential-inline-comment-synthetic';
}
$classes = implode(' ', $classes);
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(
'class' => $classes,
2011-02-02 01:42:36 +01:00
'sigil' => $sigil,
'meta' => $metadata,
),
'<div class="differential-inline-comment-head">'.
$anchor.
2011-02-02 01:42:36 +01:00
$links.
' <span class="differential-inline-comment-line">'.$line.'</span> '.
phutil_escape_html($author).
2011-02-02 01:42:36 +01:00
'</div>'.
'<div class="differential-inline-comment-content">'.
'<div class="phabricator-remarkup">'.
$content.
'</div>'.
'</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
$left_markup = !$this->onRight ? $markup : '';
$right_markup = $this->onRight ? $markup : '';
return
'<table>'.
'<tr class="inline">'.
'<th></th>'.
'<td class="left">'.$left_markup.'</td>'.
'<th></th>'.
'<td class="right3" colspan="3">'.$right_markup.'</td>'.
'</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
}