forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHUITimelineView.php
133 lines (111 loc) · 2.8 KB
/
PHUITimelineView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
final class PHUITimelineView extends AphrontView {
private $events = array();
private $id;
private $shouldTerminate = false;
public function setID($id) {
$this->id = $id;
return $this;
}
public function setShouldTerminate($term) {
$this->shouldTerminate = $term;
return $this;
}
public function addEvent(PHUITimelineEventView $event) {
$this->events[] = $event;
return $this;
}
public function render() {
require_celerity_resource('phui-timeline-view-css');
$spacer = self::renderSpacer();
$hide = array();
$show = array();
foreach ($this->events as $event) {
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) {
$events[] = $spacer;
}
if ($show) {
$events[] = phutil_implode_html($spacer, $show);
}
if ($events) {
$events = array($spacer, $events, $spacer);
} else {
$events = array($spacer);
}
if ($this->shouldTerminate) {
$events[] = self::renderEnder(true);
}
return phutil_tag(
'div',
array(
'class' => 'phui-timeline-view',
'id' => $this->id,
),
$events);
}
public static function renderSpacer() {
return phutil_tag(
'div',
array(
'class' => 'phui-timeline-event-view '.
'phui-timeline-spacer',
),
'');
}
public static function renderEnder() {
return phutil_tag(
'div',
array(
'class' => 'phui-timeline-event-view '.
'the-worlds-end',
),
'');
}
}