Something went wrong. Try again.
@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
Something went wrong. Try again.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299<?php
final class PHUIPropertyListView extends AphrontView {
private $parts = array(); private $object; private $invokedWillRenderEvent; private $actionList = null; private $classes = array(); private $stacked;
const ICON_SUMMARY = 'fa-align-left'; const ICON_TESTPLAN = 'fa-file-text-o';
protected function canAppendChild() { return false; }
public function setObject($object) { $this->object = $object; return $this; }
public function setActionList(PhabricatorActionListView $list) { $this->actionList = $list; return $this; }
public function getActionList() { return $this->actionList; }
public function setStacked($stacked) { $this->stacked = $stacked; return $this; }
public function addClass($class) { $this->classes[] = $class; return $this; }
public function addProperty($key, $value) { $current = array_pop($this->parts);
if (!$current || $current['type'] != 'property') { if ($current) { $this->parts[] = $current; } $current = array( 'type' => 'property', 'list' => array(), ); }
$current['list'][] = array( 'key' => $key, 'value' => $value, );
$this->parts[] = $current; return $this; }
public function addSectionHeader($name, $icon = null) { $this->parts[] = array( 'type' => 'section', 'name' => $name, 'icon' => $icon, ); return $this; }
public function addTextContent($content) { $this->parts[] = array( 'type' => 'text', 'content' => $content, ); return $this; }
public function addRawContent($content) { $this->parts[] = array( 'type' => 'raw', 'content' => $content, ); return $this; }
public function addImageContent($content) { $this->parts[] = array( 'type' => 'image', 'content' => $content, ); return $this; }
public function invokeWillRenderEvent() { if ($this->object && $this->getUser() && !$this->invokedWillRenderEvent) { $event = new PhabricatorEvent( PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES, array( 'object' => $this->object, 'view' => $this, )); $event->setUser($this->getUser()); PhutilEventEngine::dispatchEvent($event); } $this->invokedWillRenderEvent = true; }
/** * Whether there are any properties to display in the list view. * Useful to e.g. display an explanation via PHUIInfoView if false. * * @return bool */ public function hasAnyProperties() { $this->invokeWillRenderEvent();
if ($this->parts) { return true; }
return false; }
public function render() { $this->invokeWillRenderEvent();
require_celerity_resource('phui-property-list-view-css');
$items = array();
$parts = $this->parts;
// If we have an action list, make sure we render a property part, even // if there are no properties. Otherwise, the action list won't render. if ($this->actionList) { $this->classes[] = 'phui-property-list-has-actions'; $have_property_part = false; foreach ($this->parts as $part) { if ($part['type'] == 'property') { $have_property_part = true; break; } } if (!$have_property_part) { $parts[] = array( 'type' => 'property', 'list' => array(), ); } }
foreach ($parts as $part) { $type = $part['type']; switch ($type) { case 'property': $items[] = $this->renderPropertyPart($part); break; case 'section': $items[] = $this->renderSectionPart($part); break; case 'text': case 'image': $items[] = $this->renderTextPart($part); break; case 'raw': $items[] = $this->renderRawPart($part); break; default: throw new Exception(pht("Unknown part type '%s'!", $type)); } } $this->classes[] = 'phui-property-list-section'; $classes = implode(' ', $this->classes);
return phutil_tag( 'div', array( 'class' => $classes, ), array( $items, )); }
private function renderPropertyPart(array $part) { $items = array(); foreach ($part['list'] as $spec) { $key = $spec['key']; $value = $spec['value'];
// NOTE: We append a space to each value to improve the behavior when the // user double-clicks a property value (like a URI) to select it. Without // the space, the label is also selected.
$items[] = phutil_tag( 'dt', array( 'class' => 'phui-property-list-key', ), array($key, ' '));
$items[] = phutil_tag( 'dd', array( 'class' => 'phui-property-list-value', ), array($value, ' ')); }
$stacked = ''; if ($this->stacked) { $stacked = 'phui-property-list-stacked'; }
$list = phutil_tag( 'dl', array( 'class' => 'phui-property-list-properties', ), $items);
$list = phutil_tag( 'div', array( 'class' => 'phui-property-list-properties-wrap '.$stacked, ), array($list));
$action_list = null; if ($this->actionList) { $action_list = phutil_tag( 'div', array( 'class' => 'phui-property-list-actions', ), $this->actionList); $this->actionList = null; }
return phutil_tag( 'div', array( 'class' => 'phui-property-list-container grouped', ), array($action_list, $list)); }
private function renderSectionPart(array $part) { $name = $part['name']; if ($part['icon']) { $icon = id(new PHUIIconView()) ->setIcon($part['icon'].' bluegrey'); $name = phutil_tag( 'span', array( 'class' => 'phui-property-list-section-header-icon', ), array($icon, $name)); }
return phutil_tag( 'div', array( 'class' => 'phui-property-list-section-header', ), $name); }
private function renderTextPart(array $part) { $classes = array(); $classes[] = 'phui-property-list-text-content'; if ($part['type'] == 'image') { $classes[] = 'phui-property-list-image-content'; } return phutil_tag( 'div', array( 'class' => implode(' ', $classes), ), $part['content']); }
private function renderRawPart(array $part) { $classes = array(); $classes[] = 'phui-property-list-raw-content'; return phutil_tag( 'div', array( 'class' => implode(' ', $classes), ), $part['content']); }
}