Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/formation/PHUIFormationView.php
12249 views
1
<?php
2
3
final class PHUIFormationView
4
extends AphrontAutoIDView {
5
6
private $items = array();
7
8
public function newFlankColumn() {
9
$item = $this->newItem(new PHUIFormationFlankView());
10
return $item->getColumn();
11
}
12
13
public function newContentColumn() {
14
$item = $this->newItem(new PHUIFormationContentView());
15
return $item->getColumn();
16
}
17
18
private function newItem(PHUIFormationColumnView $column) {
19
$item = id(new PHUIFormationColumnItem())
20
->setColumn($column);
21
22
$column->setColumnItem($item);
23
24
$this->items[] = $item;
25
26
return $item;
27
}
28
29
public function render() {
30
require_celerity_resource('phui-formation-view-css');
31
32
$items = $this->items;
33
34
$items = $this->generateControlBindings($items);
35
$items = $this->generateExpanders($items);
36
$items = $this->generateResizers($items);
37
38
$cells = array();
39
foreach ($items as $item) {
40
$style = array();
41
42
$column = $item->getColumn();
43
44
$width = $column->getWidth();
45
if ($width !== null) {
46
$style[] = sprintf('width: %dpx;', $width);
47
}
48
49
if (!$column->getIsVisible()) {
50
$style[] = 'display: none;';
51
}
52
53
$classes = array();
54
if ($column->getIsDesktopOnly()) {
55
$classes[] = 'phui-formation-desktop-only';
56
}
57
58
$cells[] = phutil_tag(
59
'td',
60
array(
61
'id' => $item->getID(),
62
'style' => implode(' ', $style),
63
'class' => implode(' ', $classes),
64
),
65
array(
66
$column,
67
$item->getExpanders(),
68
));
69
}
70
71
$phuix_items = array();
72
foreach ($items as $item) {
73
$phuix_items[] = $item->newClientProperties();
74
}
75
76
$table_row = phutil_tag('tr', array(), $cells);
77
$table_body = phutil_tag('tbody', array(), $table_row);
78
$table = javelin_tag(
79
'table',
80
array(
81
'id' => $this->getID(),
82
'class' => 'phui-formation-view',
83
'sigil' => 'phuix-formation-view',
84
'meta' => array(
85
'items' => $phuix_items,
86
),
87
),
88
$table_body);
89
90
return $table;
91
}
92
93
private function newColumnExpanderView() {
94
return new PHUIFormationExpanderView();
95
}
96
97
private function newResizerItem() {
98
return $this->newItem(new PHUIFormationResizerView());
99
}
100
101
private function generateControlBindings(array $items) {
102
$count = count($items);
103
104
if (!$count) {
105
return $items;
106
}
107
108
$last_control = null;
109
110
for ($ii = 0; $ii < $count; $ii++) {
111
$item = $items[$ii];
112
$column = $item->getColumn();
113
114
$is_control = $column->getIsControlColumn();
115
if ($is_control) {
116
$last_control = $ii;
117
}
118
}
119
120
if ($last_control === null) {
121
return $items;
122
}
123
124
for ($ii = ($count - 1); $ii >= 0; $ii--) {
125
$item = $items[$ii];
126
$column = $item->getColumn();
127
128
$is_control = $column->getIsControlColumn();
129
if ($is_control) {
130
$last_control = $ii;
131
continue;
132
}
133
134
$is_right = ($last_control < $ii);
135
136
$item
137
->setControlItem($items[$last_control])
138
->setIsRightAligned($is_right);
139
}
140
141
return $items;
142
}
143
144
private function generateResizers(array $items) {
145
$result = array();
146
foreach ($items as $item) {
147
$column = $item->getColumn();
148
149
$resizer_item = null;
150
if ($column->getIsResizable()) {
151
$resizer_item = $this->newResizerItem();
152
$item->setResizerItem($resizer_item);
153
154
$resizer_item->getColumn()
155
->setIsDesktopOnly($column->getIsDesktopOnly())
156
->setIsVisible($column->getIsVisible());
157
}
158
159
if (!$resizer_item) {
160
$result[] = $item;
161
} else if ($item->getIsRightAligned()) {
162
$result[] = $resizer_item;
163
$result[] = $item;
164
} else {
165
$result[] = $item;
166
$result[] = $resizer_item;
167
}
168
}
169
170
return $result;
171
}
172
173
private function generateExpanders(array $items) {
174
foreach ($items as $item) {
175
$control_item = $item->getControlItem();
176
if (!$control_item) {
177
continue;
178
}
179
180
$expander = $this->newColumnExpanderView();
181
182
$tip = $item->getColumn()->getExpanderTooltip();
183
$expander->setTooltip($tip);
184
185
$expander->setColumnItem($item);
186
$item->setExpander($expander);
187
188
$control_item->appendExpander($expander);
189
}
190
191
return $items;
192
}
193
194
public function setFooter($footer) {
195
foreach ($this->items as $item) {
196
if ($item->getColumn() instanceof PHUIFormationContentView) {
197
$item->getColumn()->appendChild($footer);
198
return $this;
199
}
200
}
201
202
throw new Exception(
203
pht('Unable to find a content column to place the footer inside.'));
204
}
205
206
}
207
208