Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/PHUITimelineView.php
<?php | <?php | ||||
final class PHUITimelineView extends AphrontView { | final class PHUITimelineView extends AphrontView { | ||||
private $events = array(); | private $events = array(); | ||||
private $id; | private $id; | ||||
private $shouldTerminate = false; | private $shouldTerminate = false; | ||||
private $shouldAddSpacers = true; | |||||
private $pager; | |||||
public function setID($id) { | public function setID($id) { | ||||
$this->id = $id; | $this->id = $id; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setShouldTerminate($term) { | public function setShouldTerminate($term) { | ||||
$this->shouldTerminate = $term; | $this->shouldTerminate = $term; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setShouldAddSpacers($bool) { | |||||
$this->shouldAddSpacers = $bool; | |||||
return $this; | |||||
} | |||||
public function setPager(AphrontCursorPagerView $pager) { | |||||
$this->pager = $pager; | |||||
return $this; | |||||
} | |||||
public function getPager() { | |||||
return $this->pager; | |||||
} | |||||
public function addEvent(PHUITimelineEventView $event) { | public function addEvent(PHUITimelineEventView $event) { | ||||
$this->events[] = $event; | $this->events[] = $event; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function render() { | public function render() { | ||||
if ($this->getPager()) { | |||||
if ($this->id === null) { | |||||
$this->id = celerity_generate_unique_node_id(); | |||||
} | |||||
Javelin::initBehavior( | |||||
'phabricator-show-older-transactions', | |||||
array( | |||||
'timelineID' => $this->id, | |||||
)); | |||||
} | |||||
$events = $this->buildEvents(); | |||||
return phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'phui-timeline-view', | |||||
'id' => $this->id, | |||||
), | |||||
$events); | |||||
} | |||||
public function buildEvents() { | |||||
require_celerity_resource('phui-timeline-view-css'); | require_celerity_resource('phui-timeline-view-css'); | ||||
$spacer = self::renderSpacer(); | $spacer = self::renderSpacer(); | ||||
$hide = array(); | $hide = array(); | ||||
$show = array(); | $show = array(); | ||||
foreach ($this->events as $event) { | foreach ($this->events as $event) { | ||||
if ($event->getHideByDefault()) { | if ($event->getHideByDefault()) { | ||||
$hide[] = $event; | $hide[] = $event; | ||||
} else { | } else { | ||||
$show[] = $event; | $show[] = $event; | ||||
} | } | ||||
} | } | ||||
$events = array(); | $events = array(); | ||||
if ($hide) { | if ($hide) { | ||||
if ($this->getPager()) { | |||||
$events[] = javelin_tag( | |||||
'div', | |||||
array( | |||||
'sigil' => 'show-older-block', | |||||
'class' => 'phui-timeline-older-transactions-are-hidden', | |||||
), | |||||
array( | |||||
pht('Older changes are hidden. '), | |||||
' ', | |||||
javelin_tag( | |||||
'a', | |||||
array( | |||||
'href' => (string) $this->getPager()->getNextPageURI(), | |||||
'mustcapture' => true, | |||||
'sigil' => 'show-older-link', | |||||
), | |||||
pht('Show older changes.')), | |||||
)); | |||||
} else { | |||||
$hidden = phutil_implode_html($spacer, $hide); | $hidden = phutil_implode_html($spacer, $hide); | ||||
$count = count($hide); | $count = count($hide); | ||||
$show_id = celerity_generate_unique_node_id(); | $show_id = celerity_generate_unique_node_id(); | ||||
$hide_id = celerity_generate_unique_node_id(); | $hide_id = celerity_generate_unique_node_id(); | ||||
$link_id = celerity_generate_unique_node_id(); | $link_id = celerity_generate_unique_node_id(); | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'phabricator-show-all-transactions', | 'phabricator-show-all-transactions', | ||||
array( | array( | ||||
'anchors' => array_filter(mpull($hide, 'getAnchor')), | 'anchors' => array_filter(mpull($hide, 'getAnchor')), | ||||
'linkID' => $link_id, | 'linkID' => $link_id, | ||||
'hideID' => $hide_id, | 'hideID' => $hide_id, | ||||
'showID' => $show_id, | 'showID' => $show_id, | ||||
)); | )); | ||||
$events[] = phutil_tag( | $events[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $hide_id, | 'id' => $hide_id, | ||||
'class' => 'phui-timeline-older-transactions-are-hidden', | 'class' => 'phui-timeline-older-transactions-are-hidden', | ||||
), | ), | ||||
array( | array( | ||||
pht('%s older changes(s) are hidden.', new PhutilNumber($count)), | pht('%s older changes(s) are hidden.', new PhutilNumber($count)), | ||||
' ', | ' ', | ||||
javelin_tag( | javelin_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '#', | 'href' => '#', | ||||
'mustcapture' => true, | 'mustcapture' => true, | ||||
'id' => $link_id, | 'id' => $link_id, | ||||
), | ), | ||||
pht('Show all changes.')), | pht('Show all changes.')), | ||||
)); | )); | ||||
$events[] = phutil_tag( | $events[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $show_id, | 'id' => $show_id, | ||||
'style' => 'display: none', | 'style' => 'display: none', | ||||
), | ), | ||||
$hidden); | $hidden); | ||||
} | } | ||||
} | |||||
if ($hide && $show) { | if ($hide && $show) { | ||||
$events[] = $spacer; | $events[] = $spacer; | ||||
} | } | ||||
if ($show) { | if ($show) { | ||||
$events[] = phutil_implode_html($spacer, $show); | $events[] = phutil_implode_html($spacer, $show); | ||||
} | } | ||||
if ($events) { | if ($events) { | ||||
if ($this->shouldAddSpacers) { | |||||
$events = array($spacer, $events, $spacer); | $events = array($spacer, $events, $spacer); | ||||
} | |||||
} else { | } else { | ||||
$events = array($spacer); | $events = array($spacer); | ||||
} | } | ||||
if ($this->shouldTerminate) { | if ($this->shouldTerminate) { | ||||
$events[] = self::renderEnder(true); | $events[] = self::renderEnder(true); | ||||
} | } | ||||
return phutil_tag( | return $events; | ||||
'div', | |||||
array( | |||||
'class' => 'phui-timeline-view', | |||||
'id' => $this->id, | |||||
), | |||||
$events); | |||||
} | } | ||||
public static function renderSpacer() { | public static function renderSpacer() { | ||||
return phutil_tag( | return phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'phui-timeline-event-view '. | 'class' => 'phui-timeline-event-view '. | ||||
'phui-timeline-spacer', | 'phui-timeline-spacer', | ||||
Show All 15 Lines |