2012-11-22 02:24:56 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
final class PHUITimelineView extends AphrontView {
|
2012-11-22 02:24:56 +01:00
|
|
|
|
|
|
|
private $events = array();
|
2012-12-11 23:02:12 +01:00
|
|
|
private $id;
|
2014-03-14 16:51:50 +01:00
|
|
|
private $shouldTerminate = false;
|
2012-12-11 23:02:12 +01:00
|
|
|
|
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-03-14 16:51:50 +01:00
|
|
|
public function setShouldTerminate($term) {
|
|
|
|
$this->shouldTerminate = $term;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
public function addEvent(PHUITimelineEventView $event) {
|
2012-11-22 02:24:56 +01:00
|
|
|
$this->events[] = $event;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
2014-02-12 18:02:05 +01:00
|
|
|
require_celerity_resource('phui-timeline-view-css');
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2012-12-11 23:02:29 +01:00
|
|
|
$spacer = self::renderSpacer();
|
2012-12-11 23:01:35 +01:00
|
|
|
|
2014-02-14 19:23:07 +01:00
|
|
|
$hide = array();
|
|
|
|
$show = array();
|
|
|
|
|
2012-11-22 02:24:56 +01:00
|
|
|
foreach ($this->events as $event) {
|
2014-02-14 19:23:07 +01:00
|
|
|
if ($event->getHideByDefault()) {
|
|
|
|
$hide[] = $event;
|
|
|
|
} else {
|
|
|
|
$show[] = $event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$events = array();
|
|
|
|
if ($hide) {
|
|
|
|
$hidden = phutil_implode_html($spacer, $hide);
|
|
|
|
$count = count($hide);
|
|
|
|
|
|
|
|
$show_id = celerity_generate_unique_node_id();
|
|
|
|
$hide_id = celerity_generate_unique_node_id();
|
|
|
|
$link_id = celerity_generate_unique_node_id();
|
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'phabricator-show-all-transactions',
|
|
|
|
array(
|
|
|
|
'anchors' => array_filter(mpull($hide, 'getAnchor')),
|
|
|
|
'linkID' => $link_id,
|
|
|
|
'hideID' => $hide_id,
|
|
|
|
'showID' => $show_id,
|
|
|
|
));
|
|
|
|
|
|
|
|
$events[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $hide_id,
|
|
|
|
'class' => 'phui-timeline-older-transactions-are-hidden',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
pht('%s older changes(s) are hidden.', new PhutilNumber($count)),
|
|
|
|
' ',
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'id' => $link_id,
|
|
|
|
),
|
|
|
|
pht('Show all changes.')),
|
|
|
|
));
|
|
|
|
|
|
|
|
$events[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $show_id,
|
|
|
|
'style' => 'display: none',
|
|
|
|
),
|
|
|
|
$hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($hide && $show) {
|
2012-12-11 23:01:35 +01:00
|
|
|
$events[] = $spacer;
|
2012-11-22 02:24:56 +01:00
|
|
|
}
|
2014-02-14 19:23:07 +01:00
|
|
|
|
|
|
|
if ($show) {
|
|
|
|
$events[] = phutil_implode_html($spacer, $show);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($events) {
|
|
|
|
$events = array($spacer, $events, $spacer);
|
2014-02-14 23:43:17 +01:00
|
|
|
} else {
|
|
|
|
$events = array($spacer);
|
2014-02-14 19:23:07 +01:00
|
|
|
}
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-03-14 16:51:50 +01:00
|
|
|
if ($this->shouldTerminate) {
|
|
|
|
$events[] = self::renderEnder(true);
|
|
|
|
}
|
|
|
|
|
2013-02-04 20:38:04 +01:00
|
|
|
return phutil_tag(
|
2012-11-22 02:24:56 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2014-02-12 18:02:05 +01:00
|
|
|
'class' => 'phui-timeline-view',
|
2012-12-11 23:02:12 +01:00
|
|
|
'id' => $this->id,
|
2012-11-22 02:24:56 +01:00
|
|
|
),
|
2013-02-04 20:38:04 +01:00
|
|
|
$events);
|
2012-11-22 02:24:56 +01:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:02:29 +01:00
|
|
|
public static function renderSpacer() {
|
2013-01-18 03:57:09 +01:00
|
|
|
return phutil_tag(
|
2012-12-11 23:02:29 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2014-02-12 18:02:05 +01:00
|
|
|
'class' => 'phui-timeline-event-view '.
|
|
|
|
'phui-timeline-spacer',
|
2012-12-11 23:02:29 +01:00
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
2014-03-14 16:51:50 +01:00
|
|
|
|
|
|
|
public static function renderEnder() {
|
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-timeline-event-view '.
|
|
|
|
'the-worlds-end',
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
2012-11-22 02:24:56 +01:00
|
|
|
}
|