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