Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/view/ConpherenceDurableColumnView.php
12256 views
1
<?php
2
3
final class ConpherenceDurableColumnView extends AphrontTagView {
4
5
private $conpherences = array();
6
private $draft;
7
private $selectedConpherence;
8
private $transactions;
9
private $visible;
10
private $minimize;
11
private $initialLoad = false;
12
private $policyObjects;
13
private $quicksandConfig = array();
14
15
public function setConpherences(array $conpherences) {
16
assert_instances_of($conpherences, 'ConpherenceThread');
17
$this->conpherences = $conpherences;
18
return $this;
19
}
20
21
public function getConpherences() {
22
return $this->conpherences;
23
}
24
25
public function setDraft(PhabricatorDraft $draft) {
26
$this->draft = $draft;
27
return $this;
28
}
29
30
public function getDraft() {
31
return $this->draft;
32
}
33
34
public function setSelectedConpherence(
35
ConpherenceThread $conpherence = null) {
36
$this->selectedConpherence = $conpherence;
37
return $this;
38
}
39
40
public function getSelectedConpherence() {
41
return $this->selectedConpherence;
42
}
43
44
public function setTransactions(array $transactions) {
45
assert_instances_of($transactions, 'ConpherenceTransaction');
46
$this->transactions = $transactions;
47
return $this;
48
}
49
50
public function getTransactions() {
51
return $this->transactions;
52
}
53
54
public function setVisible($visible) {
55
$this->visible = $visible;
56
return $this;
57
}
58
59
public function getVisible() {
60
return $this->visible;
61
}
62
63
public function setMinimize($minimize) {
64
$this->minimize = $minimize;
65
return $this;
66
}
67
68
public function getMinimize() {
69
return $this->minimize;
70
}
71
72
public function setInitialLoad($bool) {
73
$this->initialLoad = $bool;
74
return $this;
75
}
76
77
public function getInitialLoad() {
78
return $this->initialLoad;
79
}
80
81
public function setPolicyObjects(array $objects) {
82
assert_instances_of($objects, 'PhabricatorPolicy');
83
84
$this->policyObjects = $objects;
85
return $this;
86
}
87
88
public function getPolicyObjects() {
89
return $this->policyObjects;
90
}
91
92
public function setQuicksandConfig(array $config) {
93
$this->quicksandConfig = $config;
94
return $this;
95
}
96
97
public function getQuicksandConfig() {
98
return $this->quicksandConfig;
99
}
100
101
protected function getTagAttributes() {
102
if ($this->getVisible()) {
103
$style = null;
104
} else {
105
$style = 'display: none;';
106
}
107
$classes = array('conpherence-durable-column');
108
if ($this->getInitialLoad()) {
109
$classes[] = 'loading';
110
}
111
112
return array(
113
'id' => 'conpherence-durable-column',
114
'class' => implode(' ', $classes),
115
'style' => $style,
116
'sigil' => 'conpherence-durable-column',
117
);
118
}
119
120
protected function getTagContent() {
121
$column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY;
122
$minimize_key = PhabricatorConpherenceColumnMinimizeSetting::SETTINGKEY;
123
124
Javelin::initBehavior(
125
'durable-column',
126
array(
127
'visible' => $this->getVisible(),
128
'minimize' => $this->getMinimize(),
129
'visibleURI' => '/settings/adjust/?key='.$column_key,
130
'minimizeURI' => '/settings/adjust/?key='.$minimize_key,
131
'quicksandConfig' => $this->getQuicksandConfig(),
132
));
133
134
$policy_objects = ConpherenceThread::loadViewPolicyObjects(
135
$this->getUser(),
136
$this->getConpherences());
137
$this->setPolicyObjects($policy_objects);
138
139
$classes = array();
140
$classes[] = 'conpherence-durable-column-header';
141
$classes[] = 'grouped';
142
143
$header = phutil_tag(
144
'div',
145
array(
146
'class' => implode(' ', $classes),
147
'data-sigil' => 'conpherence-minimize-window',
148
),
149
$this->buildHeader());
150
151
$icon_bar = null;
152
if ($this->conpherences) {
153
$icon_bar = $this->buildIconBar();
154
}
155
$icon_bar = phutil_tag(
156
'div',
157
array(
158
'class' => 'conpherence-durable-column-icon-bar',
159
),
160
$icon_bar);
161
162
$transactions = $this->buildTransactions();
163
164
$content = javelin_tag(
165
'div',
166
array(
167
'class' => 'conpherence-durable-column-main',
168
'sigil' => 'conpherence-durable-column-main',
169
),
170
phutil_tag(
171
'div',
172
array(
173
'id' => 'conpherence-durable-column-content',
174
'class' => 'conpherence-durable-column-frame',
175
),
176
javelin_tag(
177
'div',
178
array(
179
'class' => 'conpherence-durable-column-transactions',
180
'sigil' => 'conpherence-durable-column-transactions',
181
),
182
$transactions)));
183
184
$input = $this->buildTextInput();
185
186
return array(
187
$header,
188
javelin_tag(
189
'div',
190
array(
191
'class' => 'conpherence-durable-column-body',
192
'sigil' => 'conpherence-durable-column-body',
193
),
194
array(
195
$icon_bar,
196
$content,
197
$input,
198
)),
199
);
200
}
201
202
private function buildIconBar() {
203
$icons = array();
204
$selected_conpherence = $this->getSelectedConpherence();
205
$conpherences = $this->getConpherences();
206
207
foreach ($conpherences as $conpherence) {
208
$classes = array('conpherence-durable-column-thread-icon');
209
if ($selected_conpherence->getID() == $conpherence->getID()) {
210
$classes[] = 'selected';
211
}
212
$data = $conpherence->getDisplayData($this->getUser());
213
$thread_title = phutil_tag(
214
'span',
215
array(),
216
array(
217
$data['title'],
218
));
219
$image = $data['image'];
220
Javelin::initBehavior('phabricator-tooltips');
221
$icons[] =
222
javelin_tag(
223
'a',
224
array(
225
'href' => '/conpherence/columnview/',
226
'class' => implode(' ', $classes),
227
'sigil' => 'conpherence-durable-column-thread-icon has-tooltip',
228
'meta' => array(
229
'threadID' => $conpherence->getID(),
230
'threadTitle' => hsprintf('%s', $thread_title),
231
'tip' => $data['title'],
232
'align' => 'W',
233
),
234
),
235
phutil_tag(
236
'span',
237
array(
238
'style' => 'background-image: url('.$image.')',
239
),
240
''));
241
}
242
243
return $icons;
244
}
245
246
private function buildHeader() {
247
$conpherence = $this->getSelectedConpherence();
248
249
$bubble_id = celerity_generate_unique_node_id();
250
$dropdown_id = celerity_generate_unique_node_id();
251
252
$settings_list = new PHUIListView();
253
$header_actions = $this->getHeaderActionsConfig($conpherence);
254
foreach ($header_actions as $action) {
255
$settings_list->addMenuItem(
256
id(new PHUIListItemView())
257
->setHref($action['href'])
258
->setName($action['name'])
259
->setIcon($action['icon'])
260
->setDisabled($action['disabled'])
261
->addSigil('conpherence-durable-column-header-action')
262
->setMetadata(array(
263
'action' => $action['key'],
264
)));
265
}
266
267
$settings_menu = phutil_tag(
268
'div',
269
array(
270
'id' => $dropdown_id,
271
'class' => 'phabricator-main-menu-dropdown phui-list-sidenav '.
272
'conpherence-settings-dropdown',
273
'sigil' => 'phabricator-notification-menu',
274
'style' => 'display: none',
275
),
276
$settings_list);
277
278
Javelin::initBehavior(
279
'aphlict-dropdown',
280
array(
281
'bubbleID' => $bubble_id,
282
'dropdownID' => $dropdown_id,
283
'local' => true,
284
'containerDivID' => 'conpherence-durable-column',
285
));
286
287
$bars = id(new PHUIListItemView())
288
->setName(pht('Room Actions'))
289
->setIcon('fa-gear')
290
->addClass('core-menu-item')
291
->addClass('conpherence-settings-icon')
292
->addSigil('conpherence-settings-menu')
293
->setID($bubble_id)
294
->setHref('#')
295
->setAural(pht('Room Actions'))
296
->setOrder(400);
297
298
$minimize = id(new PHUIListItemView())
299
->setName(pht('Minimize Window'))
300
->setIcon('fa-toggle-down')
301
->addClass('core-menu-item')
302
->addClass('conpherence-minimize-icon')
303
->addSigil('conpherence-minimize-window')
304
->setHref('#')
305
->setAural(pht('Minimize Window'))
306
->setOrder(300);
307
308
$settings_button = id(new PHUIListView())
309
->addMenuItem($bars)
310
->addMenuItem($minimize)
311
->addClass('phabricator-application-menu');
312
313
if ($conpherence) {
314
$data = $conpherence->getDisplayData($this->getUser());
315
$header = phutil_tag(
316
'span',
317
array(),
318
$data['title']);
319
} else {
320
$header = phutil_tag(
321
'span',
322
array(),
323
pht('Conpherence'));
324
}
325
326
$status = new PhabricatorNotificationStatusView();
327
328
return
329
phutil_tag(
330
'div',
331
array(
332
'class' => 'conpherence-durable-column-header-inner',
333
),
334
array(
335
$status,
336
javelin_tag(
337
'div',
338
array(
339
'sigil' => 'conpherence-durable-column-header-text',
340
'class' => 'conpherence-durable-column-header-text',
341
),
342
$header),
343
$settings_button,
344
$settings_menu,
345
));
346
}
347
348
private function getHeaderActionsConfig($conpherence) {
349
350
$actions = array();
351
if ($conpherence) {
352
$can_edit = PhabricatorPolicyFilter::hasCapability(
353
$this->getUser(),
354
$conpherence,
355
PhabricatorPolicyCapability::CAN_EDIT);
356
$actions[] = array(
357
'name' => pht('Add Participants'),
358
'disabled' => !$can_edit,
359
'href' => '/conpherence/update/'.$conpherence->getID().'/',
360
'icon' => 'fa-plus',
361
'key' => ConpherenceUpdateActions::ADD_PERSON,
362
);
363
$actions[] = array(
364
'name' => pht('Edit Room'),
365
'disabled' => !$can_edit,
366
'href' => '/conpherence/edit/'.$conpherence->getID().'/',
367
'icon' => 'fa-pencil',
368
'key' => 'go_edit',
369
);
370
$actions[] = array(
371
'name' => pht('View in Conpherence'),
372
'disabled' => false,
373
'href' => '/'.$conpherence->getMonogram(),
374
'icon' => 'fa-comments',
375
'key' => 'go_conpherence',
376
);
377
}
378
379
$actions[] = array(
380
'name' => pht('Hide Window'),
381
'disabled' => false,
382
'href' => '#',
383
'icon' => 'fa-times',
384
'key' => 'hide_column',
385
);
386
387
return $actions;
388
}
389
390
private function buildTransactions() {
391
$conpherence = $this->getSelectedConpherence();
392
if (!$conpherence) {
393
if (!$this->getVisible() || $this->getInitialLoad()) {
394
return pht('Loading...');
395
}
396
$view = array(
397
phutil_tag(
398
'div',
399
array(
400
'class' => 'column-no-rooms-text',
401
),
402
pht('You have not joined any rooms yet.')),
403
javelin_tag(
404
'a',
405
array(
406
'href' => '/conpherence/search/',
407
'class' => 'button button-grey',
408
),
409
pht('Find Rooms')),
410
);
411
return phutil_tag_div('column-no-rooms', $view);
412
}
413
414
$data = ConpherenceTransactionRenderer::renderTransactions(
415
$this->getUser(),
416
$conpherence);
417
$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(
418
$data['transactions'],
419
$data['oldest_transaction_id'],
420
$data['newest_transaction_id']);
421
422
return $messages;
423
}
424
425
private function buildTextInput() {
426
$conpherence = $this->getSelectedConpherence();
427
if (!$conpherence) {
428
return null;
429
}
430
431
$draft = $this->getDraft();
432
$draft_value = null;
433
if ($draft) {
434
$draft_value = $draft->getDraft();
435
}
436
437
$textarea_id = celerity_generate_unique_node_id();
438
$textarea = javelin_tag(
439
'textarea',
440
array(
441
'id' => $textarea_id,
442
'name' => 'text',
443
'class' => 'conpherence-durable-column-textarea',
444
'sigil' => 'conpherence-durable-column-textarea',
445
'placeholder' => pht('Send a message...'),
446
),
447
$draft_value);
448
Javelin::initBehavior(
449
'aphront-drag-and-drop-textarea',
450
array(
451
'target' => $textarea_id,
452
'activatedClass' => 'aphront-textarea-drag-and-drop',
453
'uri' => '/file/dropupload/',
454
));
455
$id = $conpherence->getID();
456
return phabricator_form(
457
$this->getUser(),
458
array(
459
'method' => 'POST',
460
'action' => '/conpherence/update/'.$id.'/',
461
'sigil' => 'conpherence-message-form',
462
),
463
array(
464
$textarea,
465
phutil_tag(
466
'input',
467
array(
468
'type' => 'hidden',
469
'name' => 'action',
470
'value' => ConpherenceUpdateActions::MESSAGE,
471
)),
472
));
473
}
474
475
private function buildStatusText() {
476
return null;
477
}
478
479
private function buildSendButton() {
480
$conpherence = $this->getSelectedConpherence();
481
if (!$conpherence) {
482
return null;
483
}
484
485
return javelin_tag(
486
'button',
487
array(
488
'class' => 'grey',
489
'sigil' => 'conpherence-send-message',
490
),
491
pht('Send'));
492
}
493
494
}
495
496