2012-02-24 22:02:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorTransactionView extends AphrontView {
|
|
|
|
|
|
|
|
private $imageURI;
|
|
|
|
private $actions = array();
|
|
|
|
private $epoch;
|
|
|
|
private $contentSource;
|
|
|
|
private $anchorName;
|
|
|
|
private $anchorText;
|
|
|
|
private $isPreview;
|
|
|
|
private $classes = array();
|
|
|
|
|
|
|
|
public function setImageURI($uri) {
|
|
|
|
$this->imageURI = $uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setActions(array $actions) {
|
|
|
|
$this->actions = $actions;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEpoch($epoch) {
|
|
|
|
$this->epoch = $epoch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setContentSource(PhabricatorContentSource $source) {
|
|
|
|
$this->contentSource = $source;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAnchor($anchor_name, $anchor_text) {
|
|
|
|
$this->anchorName = $anchor_name;
|
|
|
|
$this->anchorText = $anchor_text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addClass($class) {
|
|
|
|
$this->classes[] = $class;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsPreview($preview) {
|
|
|
|
$this->isPreview = $preview;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
if (!$this->user) {
|
2013-03-02 00:37:32 +01:00
|
|
|
throw new Exception(pht("Call setUser() before render()!"));
|
2012-02-24 22:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
require_celerity_resource('phabricator-transaction-view-css');
|
|
|
|
|
|
|
|
$info = $this->renderTransactionInfo();
|
|
|
|
$actions = $this->renderTransactionActions();
|
|
|
|
$style = $this->renderTransactionStyle();
|
|
|
|
$content = $this->renderTransactionContent();
|
2013-02-13 23:50:15 +01:00
|
|
|
$classes = implode(' ', $this->classes);
|
2012-02-24 22:02:35 +01:00
|
|
|
|
|
|
|
$transaction_id = $this->anchorName ? 'anchor-'.$this->anchorName : null;
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return phutil_tag(
|
2012-02-24 22:02:35 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-transaction-view',
|
|
|
|
'id' => $transaction_id,
|
|
|
|
'style' => $style,
|
|
|
|
),
|
2013-02-13 23:50:15 +01:00
|
|
|
hsprintf(
|
|
|
|
'<div class="phabricator-transaction-detail %s">'.
|
|
|
|
'<div class="phabricator-transaction-header">%s%s</div>'.
|
|
|
|
'%s'.
|
|
|
|
'</div>',
|
|
|
|
$classes,
|
|
|
|
$info,
|
|
|
|
$actions,
|
|
|
|
$content));
|
2012-02-24 22:02:35 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTransactionInfo() {
|
|
|
|
$info = array();
|
|
|
|
|
|
|
|
if ($this->contentSource) {
|
|
|
|
$content_source = new PhabricatorContentSourceView();
|
|
|
|
$content_source->setContentSource($this->contentSource);
|
|
|
|
$content_source->setUser($this->user);
|
|
|
|
$source = $content_source->render();
|
|
|
|
if ($source) {
|
|
|
|
$info[] = $source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isPreview) {
|
|
|
|
$info[] = 'PREVIEW';
|
|
|
|
} else if ($this->epoch) {
|
|
|
|
$info[] = phabricator_datetime($this->epoch, $this->user);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->anchorName) {
|
|
|
|
Javelin::initBehavior('phabricator-watch-anchor');
|
2012-08-22 00:01:20 +02:00
|
|
|
|
|
|
|
$anchor = id(new PhabricatorAnchorView())
|
|
|
|
->setAnchorName($this->anchorName)
|
|
|
|
->render();
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$info[] = hsprintf(
|
|
|
|
'%s%s',
|
|
|
|
$anchor,
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array('href' => '#'.$this->anchorName),
|
|
|
|
$this->anchorText));
|
2012-02-24 22:02:35 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$info = phutil_implode_html(" \xC2\xB7 ", $info);
|
2012-02-24 22:02:35 +01:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return hsprintf(
|
|
|
|
'<span class="phabricator-transaction-info">%s</span>',
|
|
|
|
$info);
|
2012-02-24 22:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTransactionActions() {
|
2013-03-09 22:52:41 +01:00
|
|
|
return $this->actions;
|
2012-02-24 22:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTransactionStyle() {
|
|
|
|
if ($this->imageURI) {
|
|
|
|
return 'background-image: url('.$this->imageURI.');';
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTransactionContent() {
|
Provide hasChildren() to replace isEmptyContent()
Summary:
Fixes T3698. Sometimes views need to render differently depending on whether they contain content or not. The existing approach for this is `isEmptyContent()`, which doesn't work well and is sort of hacky (it implies double-rendering content, which is not always free or side-effect free).
Instead, provide a test for an element without children. This test is powerful enough to catch the easy cases of `null`, etc., and just do the expected thing, but will not catch a View which is reduced upon rendering. Since this is rare and we have no actual need for it today, just accept that as a limitation.
Test Plan:
Viewed Timeline and Feed UI examples. Viewed Feed (feed), Pholio (timelineview), and Differential (old transactionview).
{F53915}
Reviewers: chad, btrahan
Reviewed By: chad
CC: aran
Maniphest Tasks: T3698
Differential Revision: https://secure.phabricator.com/D6718
2013-08-12 16:51:01 +02:00
|
|
|
if (!$this->hasChildren()) {
|
2012-02-24 22:02:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
2013-02-13 23:50:15 +01:00
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array('class' => 'phabricator-transaction-content'),
|
Provide hasChildren() to replace isEmptyContent()
Summary:
Fixes T3698. Sometimes views need to render differently depending on whether they contain content or not. The existing approach for this is `isEmptyContent()`, which doesn't work well and is sort of hacky (it implies double-rendering content, which is not always free or side-effect free).
Instead, provide a test for an element without children. This test is powerful enough to catch the easy cases of `null`, etc., and just do the expected thing, but will not catch a View which is reduced upon rendering. Since this is rare and we have no actual need for it today, just accept that as a limitation.
Test Plan:
Viewed Timeline and Feed UI examples. Viewed Feed (feed), Pholio (timelineview), and Differential (old transactionview).
{F53915}
Reviewers: chad, btrahan
Reviewed By: chad
CC: aran
Maniphest Tasks: T3698
Differential Revision: https://secure.phabricator.com/D6718
2013-08-12 16:51:01 +02:00
|
|
|
$this->renderChildren());
|
2012-02-24 22:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|