2012-08-15 19:45:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorPropertyListView extends AphrontView {
|
|
|
|
|
2012-11-21 03:01:18 +01:00
|
|
|
private $parts = array();
|
2012-12-11 23:59:27 +01:00
|
|
|
private $hasKeyboardShortcuts;
|
2012-11-21 03:01:18 +01:00
|
|
|
|
|
|
|
protected function canAppendChild() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2012-12-11 23:59:27 +01:00
|
|
|
public function setHasKeyboardShortcuts($has_keyboard_shortcuts) {
|
|
|
|
$this->hasKeyboardShortcuts = $has_keyboard_shortcuts;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function addProperty($key, $value) {
|
2012-11-21 03:01:18 +01:00
|
|
|
$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) {
|
|
|
|
$this->parts[] = array(
|
|
|
|
'type' => 'section',
|
|
|
|
'name' => $name,
|
|
|
|
);
|
2012-08-15 19:45:06 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:53 +02:00
|
|
|
public function addTextContent($content) {
|
2012-11-21 03:01:18 +01:00
|
|
|
$this->parts[] = array(
|
|
|
|
'type' => 'text',
|
|
|
|
'content' => $content,
|
|
|
|
);
|
|
|
|
return $this;
|
2012-10-15 23:50:53 +02:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('phabricator-property-list-view-css');
|
|
|
|
|
|
|
|
$items = array();
|
2012-11-21 03:01:18 +01:00
|
|
|
foreach ($this->parts as $part) {
|
|
|
|
$type = $part['type'];
|
|
|
|
switch ($type) {
|
|
|
|
case 'property':
|
|
|
|
$items[] = $this->renderPropertyPart($part);
|
|
|
|
break;
|
|
|
|
case 'section':
|
|
|
|
$items[] = $this->renderSectionPart($part);
|
|
|
|
break;
|
|
|
|
case 'text':
|
|
|
|
$items[] = $this->renderTextPart($part);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception("Unknown part type '{$type}'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 15:04:54 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-property-list-view',
|
|
|
|
),
|
2013-02-13 23:50:15 +01:00
|
|
|
$this->renderSingleView($items));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderPropertyPart(array $part) {
|
|
|
|
$items = array();
|
|
|
|
foreach ($part['list'] as $spec) {
|
|
|
|
$key = $spec['key'];
|
|
|
|
$value = $spec['value'];
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$items[] = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dt',
|
|
|
|
array(
|
2012-11-21 03:01:18 +01:00
|
|
|
'class' => 'phabricator-property-list-key',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$key);
|
2013-01-29 20:01:47 +01:00
|
|
|
|
|
|
|
$items[] = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dd',
|
|
|
|
array(
|
2012-11-21 03:01:18 +01:00
|
|
|
'class' => 'phabricator-property-list-value',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-02-13 23:50:15 +01:00
|
|
|
$this->renderSingleView($value));
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 20:01:47 +01:00
|
|
|
$list = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dl',
|
|
|
|
array(
|
2012-11-21 03:01:18 +01:00
|
|
|
'class' => 'phabricator-property-list-properties',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-02-13 23:50:15 +01:00
|
|
|
$this->renderSingleView($items));
|
2012-12-11 23:59:27 +01:00
|
|
|
|
|
|
|
$shortcuts = null;
|
|
|
|
if ($this->hasKeyboardShortcuts) {
|
|
|
|
$shortcuts =
|
|
|
|
id(new AphrontKeyboardShortcutsAvailableView())->render();
|
|
|
|
}
|
|
|
|
|
2013-01-29 20:01:47 +01:00
|
|
|
return array(
|
|
|
|
$shortcuts,
|
|
|
|
phutil_tag(
|
2012-12-11 23:59:27 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-property-list-container',
|
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
array(
|
|
|
|
$list,
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array('class' => 'phabriator-property-list-view-end'),
|
|
|
|
''),
|
2013-01-29 20:01:47 +01:00
|
|
|
)));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSectionPart(array $part) {
|
2013-01-18 03:43:35 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-property-list-section-header',
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$part['name']);
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2012-11-21 03:01:18 +01:00
|
|
|
private function renderTextPart(array $part) {
|
2013-01-29 20:01:47 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-property-list-text-content',
|
|
|
|
),
|
|
|
|
$part['content']);
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
}
|