2011-07-05 17:35:18 +02:00
|
|
|
<?php
|
|
|
|
|
2013-04-15 04:32:26 +02:00
|
|
|
final class PHUIFeedStoryView extends AphrontView {
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2011-07-09 22:28:09 +02:00
|
|
|
private $title;
|
|
|
|
private $image;
|
2013-04-13 18:09:42 +02:00
|
|
|
private $imageHref;
|
|
|
|
private $appIcon;
|
2011-07-09 22:28:09 +02:00
|
|
|
private $phid;
|
|
|
|
private $epoch;
|
2012-12-08 01:25:23 +01:00
|
|
|
private $viewed;
|
2012-12-08 01:26:43 +01:00
|
|
|
private $href;
|
2013-04-25 00:18:58 +02:00
|
|
|
private $pontification = null;
|
|
|
|
private $tokenBar = array();
|
|
|
|
private $projects = array();
|
|
|
|
private $actions = array();
|
2013-07-13 02:04:02 +02:00
|
|
|
private $chronologicalKey;
|
|
|
|
|
|
|
|
public function setChronologicalKey($chronological_key) {
|
|
|
|
$this->chronologicalKey = $chronological_key;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChronologicalKey() {
|
|
|
|
return $this->chronologicalKey;
|
|
|
|
}
|
2011-07-09 22:28:09 +02:00
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEpoch($epoch) {
|
|
|
|
$this->epoch = $epoch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setImage($image) {
|
|
|
|
$this->image = $image;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-13 18:09:42 +02:00
|
|
|
public function setImageHref($image_href) {
|
|
|
|
$this->imageHref = $image_href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAppIcon($icon) {
|
|
|
|
$this->appIcon = $icon;
|
2011-07-10 00:44:49 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:25:23 +01:00
|
|
|
public function setViewed($viewed) {
|
|
|
|
$this->viewed = $viewed;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewed() {
|
|
|
|
return $this->viewed;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
public function setHref($href) {
|
|
|
|
$this->href = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
public function setTokenBar(array $tokens) {
|
|
|
|
$this->tokenBar = $tokens;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addProject($project) {
|
|
|
|
$this->projects[] = $project;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addAction(PHUIIconView $action) {
|
|
|
|
$this->actions[] = $action;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPontification($text, $title = null) {
|
|
|
|
if ($title) {
|
|
|
|
$title = phutil_tag('h3', array(), $title);
|
|
|
|
}
|
|
|
|
$copy = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-bigtext-post',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$title,
|
|
|
|
$text));
|
|
|
|
$this->appendChild($copy);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
public function getHref() {
|
|
|
|
return $this->href;
|
|
|
|
}
|
|
|
|
|
2014-01-23 05:09:32 +01:00
|
|
|
public function renderNotification($user) {
|
2012-12-08 01:25:23 +01:00
|
|
|
$classes = array(
|
|
|
|
'phabricator-notification',
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$this->viewed) {
|
|
|
|
$classes[] = 'phabricator-notification-unread';
|
|
|
|
}
|
2014-01-23 05:09:32 +01:00
|
|
|
if ($this->epoch) {
|
|
|
|
if ($user) {
|
|
|
|
$foot = phabricator_datetime($this->epoch, $user);
|
|
|
|
$foot = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-notification-date'),
|
|
|
|
$foot);
|
|
|
|
} else {
|
|
|
|
$foot = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$foot = pht('No time specified.');
|
|
|
|
}
|
2012-12-08 01:25:23 +01:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return javelin_tag(
|
2012-12-08 01:25:23 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
2012-12-08 01:26:43 +01:00
|
|
|
'sigil' => 'notification',
|
|
|
|
'meta' => array(
|
|
|
|
'href' => $this->getHref(),
|
|
|
|
),
|
2012-12-08 01:25:23 +01:00
|
|
|
),
|
2014-01-23 05:09:32 +01:00
|
|
|
array($this->title, $foot));
|
2012-12-08 01:25:23 +01:00
|
|
|
}
|
|
|
|
|
2011-07-05 17:35:18 +02:00
|
|
|
public function render() {
|
2011-07-09 22:28:09 +02:00
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
require_celerity_resource('phui-feed-story-css');
|
2013-08-06 18:20:04 +02:00
|
|
|
Javelin::initBehavior('phabricator-hovercards');
|
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
|
|
|
$oneline = !$this->hasChildren();
|
2013-04-13 18:09:42 +02:00
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
$body = null;
|
|
|
|
$foot = null;
|
|
|
|
$image_style = null;
|
2013-04-13 18:09:42 +02:00
|
|
|
$actor = '';
|
2013-08-02 00:23:07 +02:00
|
|
|
|
2013-04-13 18:09:42 +02:00
|
|
|
if ($this->image) {
|
2013-04-20 02:44:20 +02:00
|
|
|
$actor = new PHUIIconView();
|
2013-04-13 18:09:42 +02:00
|
|
|
$actor->setImage($this->image);
|
2013-04-25 00:18:58 +02:00
|
|
|
$actor->addClass('phui-feed-story-actor-image');
|
2013-04-13 18:09:42 +02:00
|
|
|
if ($this->imageHref) {
|
|
|
|
$actor->setHref($this->imageHref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
if ($this->epoch) {
|
|
|
|
// TODO: This is really bad; when rendering through Conduit and via
|
|
|
|
// renderText() we don't have a user.
|
|
|
|
if ($this->user) {
|
|
|
|
$foot = phabricator_datetime($this->epoch, $this->user);
|
|
|
|
} else {
|
|
|
|
$foot = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$foot = pht('No time specified.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->chronologicalKey) {
|
|
|
|
$foot = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/feed/'.$this->chronologicalKey.'/',
|
|
|
|
),
|
|
|
|
$foot);
|
|
|
|
}
|
|
|
|
|
|
|
|
$icon = null;
|
|
|
|
if ($this->appIcon) {
|
|
|
|
$icon = new PHUIIconView();
|
|
|
|
$icon->setSpriteIcon($this->appIcon);
|
|
|
|
$icon->setSpriteSheet(PHUIIconView::SPRITE_APPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ol_foot = null;
|
2013-08-05 19:10:33 +02:00
|
|
|
if ($oneline) {
|
2013-08-02 00:23:07 +02:00
|
|
|
$ol_foot = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-oneline-foot'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$icon,
|
|
|
|
$foot));
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
$action_list = array();
|
|
|
|
$icons = null;
|
|
|
|
foreach ($this->actions as $action) {
|
|
|
|
$action_list[] = phutil_tag(
|
|
|
|
'li',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-action-item'
|
|
|
|
),
|
|
|
|
$action);
|
|
|
|
}
|
|
|
|
if (!empty($action_list)) {
|
|
|
|
$icons = phutil_tag(
|
|
|
|
'ul',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-action-list'
|
|
|
|
),
|
|
|
|
$action_list);
|
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$head = phutil_tag(
|
2011-07-09 22:28:09 +02:00
|
|
|
'div',
|
|
|
|
array(
|
2013-04-15 04:32:26 +02:00
|
|
|
'class' => 'phui-feed-story-head',
|
2011-07-09 22:28:09 +02:00
|
|
|
),
|
2013-04-13 18:09:42 +02:00
|
|
|
array(
|
2013-08-06 18:20:04 +02:00
|
|
|
(!$oneline ? $actor : null),
|
2013-04-13 18:09:42 +02:00
|
|
|
nonempty($this->title, pht('Untitled Story')),
|
2013-08-02 00:23:07 +02:00
|
|
|
$icons,
|
|
|
|
$ol_foot
|
2013-04-13 18:09:42 +02:00
|
|
|
));
|
2011-07-09 22:28:09 +02:00
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
if (!empty($this->tokenBar)) {
|
|
|
|
$tokenview = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-token-bar'
|
|
|
|
),
|
|
|
|
$this->tokenBar);
|
|
|
|
$this->appendChild($tokenview);
|
|
|
|
}
|
|
|
|
|
2013-04-15 22:07:54 +02:00
|
|
|
$body_content = $this->renderChildren();
|
|
|
|
if ($body_content) {
|
|
|
|
$body = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-feed-story-body',
|
|
|
|
),
|
|
|
|
$body_content);
|
|
|
|
}
|
2011-07-10 00:44:49 +02:00
|
|
|
|
2013-08-05 19:10:33 +02:00
|
|
|
if ($oneline) {
|
2013-08-02 00:23:07 +02:00
|
|
|
$foot = null;
|
2013-04-13 18:09:42 +02:00
|
|
|
} else {
|
2013-07-13 02:04:02 +02:00
|
|
|
$foot = phutil_tag(
|
2013-08-02 00:23:07 +02:00
|
|
|
'div',
|
2013-07-13 02:04:02 +02:00
|
|
|
array(
|
2013-08-02 00:23:07 +02:00
|
|
|
'class' => 'phui-feed-story-foot',
|
2013-07-13 02:04:02 +02:00
|
|
|
),
|
2013-08-02 00:23:07 +02:00
|
|
|
array(
|
|
|
|
$icon,
|
|
|
|
$foot));
|
2013-07-13 02:04:02 +02:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:23:07 +02:00
|
|
|
$classes = array('phui-feed-story');
|
2013-08-05 19:10:33 +02:00
|
|
|
if ($oneline) {
|
2013-08-02 00:23:07 +02:00
|
|
|
$classes[] = 'phui-feed-story-oneline';
|
2011-07-09 22:28:09 +02:00
|
|
|
}
|
|
|
|
|
2013-04-25 00:18:58 +02:00
|
|
|
return id(new PHUIBoxView())
|
2013-08-02 00:23:07 +02:00
|
|
|
->addClass(implode(' ', $classes))
|
2014-02-11 01:04:42 +01:00
|
|
|
->setBorder(true)
|
2013-04-25 00:18:58 +02:00
|
|
|
->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)
|
|
|
|
->appendChild(array($head, $body, $foot));
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|
2013-05-26 16:54:29 +02:00
|
|
|
|
|
|
|
public function setAppIconFromPHID($phid) {
|
2013-06-05 00:28:24 +02:00
|
|
|
switch (phid_get_type($phid)) {
|
2013-07-21 21:40:51 +02:00
|
|
|
case PholioPHIDTypeMock::TYPECONST:
|
2013-05-26 16:54:29 +02:00
|
|
|
$this->setAppIcon("pholio-dark");
|
|
|
|
break;
|
2013-07-24 23:06:10 +02:00
|
|
|
case PhabricatorMacroPHIDTypeMacro::TYPECONST:
|
2013-05-26 16:54:29 +02:00
|
|
|
$this->setAppIcon("macro-dark");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|