[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialInlineCommentView extends AphrontView { 4 5 private $inlineComment; 6 private $onRight; 7 private $buildScaffolding; 8 private $handles; 9 private $markupEngine; 10 private $editable; 11 private $preview; 12 private $allowReply; 13 14 public function setInlineComment(PhabricatorInlineCommentInterface $comment) { 15 $this->inlineComment = $comment; 16 return $this; 17 } 18 19 public function setOnRight($on_right) { 20 $this->onRight = $on_right; 21 return $this; 22 } 23 24 public function setBuildScaffolding($scaffold) { 25 $this->buildScaffolding = $scaffold; 26 return $this; 27 } 28 29 public function setHandles(array $handles) { 30 assert_instances_of($handles, 'PhabricatorObjectHandle'); 31 $this->handles = $handles; 32 return $this; 33 } 34 35 public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 36 $this->markupEngine = $engine; 37 return $this; 38 } 39 40 public function setEditable($editable) { 41 $this->editable = $editable; 42 return $this; 43 } 44 45 public function setPreview($preview) { 46 $this->preview = $preview; 47 return $this; 48 } 49 50 public function setAllowReply($allow_reply) { 51 $this->allowReply = $allow_reply; 52 return $this; 53 } 54 55 public function render() { 56 57 $inline = $this->inlineComment; 58 59 $start = $inline->getLineNumber(); 60 $length = $inline->getLineLength(); 61 if ($length) { 62 $end = $start + $length; 63 $line = 'Lines '.number_format($start).'-'.number_format($end); 64 } else { 65 $line = 'Line '.number_format($start); 66 } 67 68 $metadata = array( 69 'id' => $inline->getID(), 70 'number' => $inline->getLineNumber(), 71 'length' => $inline->getLineLength(), 72 'on_right' => $this->onRight, 73 'original' => $inline->getContent(), 74 ); 75 76 $sigil = 'differential-inline-comment'; 77 if ($this->preview) { 78 $sigil = $sigil.' differential-inline-comment-preview'; 79 } 80 81 $content = $inline->getContent(); 82 $handles = $this->handles; 83 84 $links = array(); 85 86 $is_synthetic = false; 87 if ($inline->getSyntheticAuthor()) { 88 $is_synthetic = true; 89 } 90 91 $is_draft = false; 92 if ($inline->isDraft() && !$is_synthetic) { 93 $links[] = pht('Not Submitted Yet'); 94 $is_draft = true; 95 } 96 97 if (!$this->preview) { 98 $links[] = javelin_tag( 99 'a', 100 array( 101 'href' => '#', 102 'mustcapture' => true, 103 'sigil' => 'differential-inline-prev', 104 ), 105 pht('Previous')); 106 107 $links[] = javelin_tag( 108 'a', 109 array( 110 'href' => '#', 111 'mustcapture' => true, 112 'sigil' => 'differential-inline-next', 113 ), 114 pht('Next')); 115 116 if ($this->allowReply) { 117 118 if (!$is_synthetic) { 119 120 // NOTE: No product reason why you can't reply to these, but the reply 121 // mechanism currently sends the inline comment ID to the server, not 122 // file/line information, and synthetic comments don't have an inline 123 // comment ID. 124 125 $links[] = javelin_tag( 126 'a', 127 array( 128 'href' => '#', 129 'mustcapture' => true, 130 'sigil' => 'differential-inline-reply', 131 ), 132 pht('Reply')); 133 } 134 135 } 136 } 137 138 $anchor_name = 'inline-'.$inline->getID(); 139 140 if ($this->editable && !$this->preview) { 141 $links[] = javelin_tag( 142 'a', 143 array( 144 'href' => '#', 145 'mustcapture' => true, 146 'sigil' => 'differential-inline-edit', 147 ), 148 pht('Edit')); 149 $links[] = javelin_tag( 150 'a', 151 array( 152 'href' => '#', 153 'mustcapture' => true, 154 'sigil' => 'differential-inline-delete', 155 ), 156 pht('Delete')); 157 } else if ($this->preview) { 158 $links[] = javelin_tag( 159 'a', 160 array( 161 'meta' => array( 162 'anchor' => $anchor_name, 163 ), 164 'sigil' => 'differential-inline-preview-jump', 165 ), 166 pht('Not Visible')); 167 $links[] = javelin_tag( 168 'a', 169 array( 170 'href' => '#', 171 'mustcapture' => true, 172 'sigil' => 'differential-inline-delete', 173 ), 174 pht('Delete')); 175 } 176 177 if ($links) { 178 $links = phutil_tag( 179 'span', 180 array('class' => 'differential-inline-comment-links'), 181 phutil_implode_html(" \xC2\xB7 ", $links)); 182 } else { 183 $links = null; 184 } 185 186 $content = $this->markupEngine->getOutput( 187 $inline, 188 PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 189 190 if ($this->preview) { 191 $anchor = null; 192 } else { 193 $anchor = phutil_tag( 194 'a', 195 array( 196 'name' => $anchor_name, 197 'id' => $anchor_name, 198 'class' => 'differential-inline-comment-anchor', 199 ), 200 ''); 201 } 202 203 $classes = array( 204 'differential-inline-comment', 205 ); 206 if ($is_draft) { 207 $classes[] = 'differential-inline-comment-unsaved-draft'; 208 } 209 if ($is_synthetic) { 210 $classes[] = 'differential-inline-comment-synthetic'; 211 } 212 $classes = implode(' ', $classes); 213 214 if ($is_synthetic) { 215 $author = $inline->getSyntheticAuthor(); 216 } else { 217 $author = $handles[$inline->getAuthorPHID()]->getName(); 218 } 219 220 $line = phutil_tag( 221 'span', 222 array('class' => 'differential-inline-comment-line'), 223 $line); 224 225 $markup = javelin_tag( 226 'div', 227 array( 228 'class' => $classes, 229 'sigil' => $sigil, 230 'meta' => $metadata, 231 ), 232 array( 233 phutil_tag_div('differential-inline-comment-head', array( 234 $anchor, 235 $links, 236 ' ', 237 $line, 238 ' ', 239 $author, 240 )), 241 phutil_tag_div( 242 'differential-inline-comment-content', 243 phutil_tag_div('phabricator-remarkup', $content)), 244 )); 245 246 return $this->scaffoldMarkup($markup); 247 } 248 249 private function scaffoldMarkup($markup) { 250 if (!$this->buildScaffolding) { 251 return $markup; 252 } 253 254 $left_markup = !$this->onRight ? $markup : ''; 255 $right_markup = $this->onRight ? $markup : ''; 256 257 return phutil_tag('table', array(), 258 phutil_tag('tr', array(), array( 259 phutil_tag('th', array()), 260 phutil_tag('td', array('class' => 'left'), $left_markup), 261 phutil_tag('th', array()), 262 phutil_tag( 263 'td', 264 array('colspan' => 3, 'class' => 'right3'), 265 $right_markup), 266 ))); 267 } 268 269 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |