2013-04-02 18:15:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default one-for-all hovercard. We may derive from this one to create
|
2015-05-22 09:27:56 +02:00
|
|
|
* more specialized ones.
|
2013-04-02 18:15:33 +02:00
|
|
|
*/
|
2016-02-05 05:11:36 +01:00
|
|
|
final class PHUIHovercardView extends AphrontTagView {
|
2013-04-02 18:15:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PhabricatorObjectHandle
|
|
|
|
*/
|
|
|
|
private $handle;
|
2015-06-05 23:20:25 +02:00
|
|
|
private $object;
|
2013-04-02 18:15:33 +02:00
|
|
|
|
|
|
|
private $title = array();
|
|
|
|
private $detail;
|
|
|
|
private $tags = array();
|
|
|
|
private $fields = array();
|
|
|
|
private $actions = array();
|
2015-07-17 02:17:21 +02:00
|
|
|
private $badges = array();
|
2013-04-02 18:15:33 +02:00
|
|
|
|
|
|
|
public function setObjectHandle(PhabricatorObjectHandle $handle) {
|
|
|
|
$this->handle = $handle;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-05 23:20:25 +02:00
|
|
|
public function setObject($object) {
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getObject() {
|
|
|
|
return $this->object;
|
|
|
|
}
|
|
|
|
|
2013-04-02 18:15:33 +02:00
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDetail($detail) {
|
|
|
|
$this->detail = $detail;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addField($label, $value) {
|
|
|
|
$this->fields[] = array(
|
|
|
|
'label' => $label,
|
|
|
|
'value' => $value,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addAction($label, $uri, $workflow = false) {
|
|
|
|
$this->actions[] = array(
|
|
|
|
'label' => $label,
|
|
|
|
'uri' => $uri,
|
|
|
|
'workflow' => $workflow,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-14 23:09:52 +01:00
|
|
|
public function addTag(PHUITagView $tag) {
|
2013-04-02 18:15:33 +02:00
|
|
|
$this->tags[] = $tag;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-07-17 02:17:21 +02:00
|
|
|
public function addBadge(PHUIBadgeMiniView $badge) {
|
|
|
|
$this->badges[] = $badge;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-02-05 05:11:36 +01:00
|
|
|
protected function getTagAttributes() {
|
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'phui-hovercard-wrapper';
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'class' => implode(' ', $classes),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagContent() {
|
2013-04-03 01:51:03 +02:00
|
|
|
if (!$this->handle) {
|
2015-05-13 23:53:52 +02:00
|
|
|
throw new PhutilInvalidStateException('setObjectHandle');
|
2013-04-03 01:51:03 +02:00
|
|
|
}
|
|
|
|
|
2015-06-05 23:20:25 +02:00
|
|
|
$viewer = $this->getUser();
|
2013-04-02 18:15:33 +02:00
|
|
|
$handle = $this->handle;
|
|
|
|
|
2016-02-03 17:26:30 +01:00
|
|
|
require_celerity_resource('phui-hovercard-view-css');
|
2013-04-02 18:15:33 +02:00
|
|
|
|
2016-02-05 05:11:36 +01:00
|
|
|
// If we're a fully custom Hovercard, skip the common UI
|
|
|
|
$children = $this->renderChildren();
|
|
|
|
if ($children) {
|
|
|
|
return $children;
|
|
|
|
}
|
|
|
|
|
2015-06-05 23:20:25 +02:00
|
|
|
$title = array(
|
|
|
|
id(new PHUISpacesNamespaceContextView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($this->getObject()),
|
2016-02-05 05:11:36 +01:00
|
|
|
$this->title ? $this->title : $handle->getName(),
|
2015-06-05 23:20:25 +02:00
|
|
|
);
|
2013-04-02 18:15:33 +02:00
|
|
|
|
2015-05-18 19:00:15 +02:00
|
|
|
$header = new PHUIHeaderView();
|
|
|
|
$header->setHeader($title);
|
2013-04-05 17:21:01 +02:00
|
|
|
if ($this->tags) {
|
|
|
|
foreach ($this->tags as $tag) {
|
2016-03-05 16:25:06 +01:00
|
|
|
$header->addActionItem($tag);
|
2013-04-05 17:21:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 18:15:33 +02:00
|
|
|
$body = array();
|
Hovercard tweaks
Summary: Tightens up spacing, remove some of the borders, add alpha channel, make them all blue (sorry, red green and yellow are for 'status'). If we want to do more colors just for hovercards, I have a brown and a black in the mock, but would like to try just blue for now.
Test Plan: UIExamples, Tasks, People, Diffs, and Pastes.
Reviewers: epriestley, AnhNhan, btrahan
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5609
2013-04-07 06:13:11 +02:00
|
|
|
|
2017-04-26 02:29:47 +02:00
|
|
|
$body_title = null;
|
2013-04-02 18:15:33 +02:00
|
|
|
if ($this->detail) {
|
Hovercard tweaks
Summary: Tightens up spacing, remove some of the borders, add alpha channel, make them all blue (sorry, red green and yellow are for 'status'). If we want to do more colors just for hovercards, I have a brown and a black in the mock, but would like to try just blue for now.
Test Plan: UIExamples, Tasks, People, Diffs, and Pastes.
Reviewers: epriestley, AnhNhan, btrahan
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5609
2013-04-07 06:13:11 +02:00
|
|
|
$body_title = $this->detail;
|
2017-04-26 02:29:47 +02:00
|
|
|
} else if (!$this->fields) {
|
2013-04-02 18:15:33 +02:00
|
|
|
// Fallback for object handles
|
Hovercard tweaks
Summary: Tightens up spacing, remove some of the borders, add alpha channel, make them all blue (sorry, red green and yellow are for 'status'). If we want to do more colors just for hovercards, I have a brown and a black in the mock, but would like to try just blue for now.
Test Plan: UIExamples, Tasks, People, Diffs, and Pastes.
Reviewers: epriestley, AnhNhan, btrahan
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5609
2013-04-07 06:13:11 +02:00
|
|
|
$body_title = $handle->getFullName();
|
2013-04-02 18:15:33 +02:00
|
|
|
}
|
|
|
|
|
2017-04-26 02:29:47 +02:00
|
|
|
if ($body_title) {
|
|
|
|
$body[] = phutil_tag_div('phui-hovercard-body-header', $body_title);
|
|
|
|
}
|
Hovercard tweaks
Summary: Tightens up spacing, remove some of the borders, add alpha channel, make them all blue (sorry, red green and yellow are for 'status'). If we want to do more colors just for hovercards, I have a brown and a black in the mock, but would like to try just blue for now.
Test Plan: UIExamples, Tasks, People, Diffs, and Pastes.
Reviewers: epriestley, AnhNhan, btrahan
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5609
2013-04-07 06:13:11 +02:00
|
|
|
|
2013-04-02 18:15:33 +02:00
|
|
|
foreach ($this->fields as $field) {
|
2013-11-09 19:48:19 +01:00
|
|
|
$item = array(
|
|
|
|
phutil_tag('strong', array(), $field['label']),
|
2015-07-17 02:17:21 +02:00
|
|
|
': ',
|
2013-11-09 19:48:19 +01:00
|
|
|
phutil_tag('span', array(), $field['value']),
|
|
|
|
);
|
2016-02-03 17:26:30 +01:00
|
|
|
$body[] = phutil_tag_div('phui-hovercard-body-item', $item);
|
2013-04-02 18:15:33 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 02:17:21 +02:00
|
|
|
if ($this->badges) {
|
|
|
|
$badges = id(new PHUIBadgeBoxView())
|
|
|
|
->addItems($this->badges)
|
|
|
|
->setCollapsed(true);
|
|
|
|
$body[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2016-02-03 17:26:30 +01:00
|
|
|
'class' => 'phui-hovercard-body-item hovercard-badges',
|
2015-07-17 02:17:21 +02:00
|
|
|
),
|
|
|
|
$badges);
|
|
|
|
}
|
|
|
|
|
2013-04-02 18:15:33 +02:00
|
|
|
if ($handle->getImageURI()) {
|
|
|
|
// Probably a user, we don't need to assume something else
|
|
|
|
// "Prepend" the image by appending $body
|
|
|
|
$body = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2016-02-03 17:26:30 +01:00
|
|
|
'class' => 'phui-hovercard-body-image',
|
2014-10-07 15:01:04 +02:00
|
|
|
),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'profile-header-picture-frame',
|
|
|
|
'style' => 'background-image: url('.$handle->getImageURI().');',
|
|
|
|
),
|
|
|
|
''))
|
|
|
|
->appendHTML(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2016-02-03 17:26:30 +01:00
|
|
|
'class' => 'phui-hovercard-body-details',
|
2014-10-07 15:01:04 +02:00
|
|
|
),
|
|
|
|
$body));
|
2013-04-02 18:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$buttons = array();
|
|
|
|
|
|
|
|
foreach ($this->actions as $action) {
|
|
|
|
$options = array(
|
2017-06-05 22:14:34 +02:00
|
|
|
'class' => 'button button-grey',
|
2013-04-02 18:15:33 +02:00
|
|
|
'href' => $action['uri'],
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($action['workflow']) {
|
|
|
|
$options['sigil'] = 'workflow';
|
|
|
|
$buttons[] = javelin_tag(
|
|
|
|
'a',
|
|
|
|
$options,
|
|
|
|
$action['label']);
|
|
|
|
} else {
|
|
|
|
$buttons[] = phutil_tag(
|
|
|
|
'a',
|
|
|
|
$options,
|
|
|
|
$action['label']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tail = null;
|
|
|
|
if ($buttons) {
|
2016-02-03 17:26:30 +01:00
|
|
|
$tail = phutil_tag_div('phui-hovercard-tail', $buttons);
|
2013-04-02 18:15:33 +02:00
|
|
|
}
|
|
|
|
|
2013-11-09 19:48:19 +01:00
|
|
|
$hovercard = phutil_tag_div(
|
2016-02-05 05:11:36 +01:00
|
|
|
'phui-hovercard-container grouped',
|
2013-04-02 18:15:33 +02:00
|
|
|
array(
|
2016-02-03 17:26:30 +01:00
|
|
|
phutil_tag_div('phui-hovercard-head', $header),
|
|
|
|
phutil_tag_div('phui-hovercard-body grouped', $body),
|
2013-11-09 19:48:19 +01:00
|
|
|
$tail,
|
|
|
|
));
|
2013-04-02 18:15:33 +02:00
|
|
|
|
2016-02-05 05:11:36 +01:00
|
|
|
return $hovercard;
|
2013-04-02 18:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|