2012-08-15 19:45:06 +02:00
|
|
|
<?php
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
final class PHUIHeaderView extends AphrontView {
|
|
|
|
|
2013-09-24 17:42:04 +02:00
|
|
|
const PROPERTY_STATUS = 1;
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
private $objectName;
|
|
|
|
private $header;
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
private $tags = array();
|
2013-07-10 01:23:22 +02:00
|
|
|
private $image;
|
|
|
|
private $subheader;
|
2013-08-28 19:29:02 +02:00
|
|
|
private $gradient;
|
2013-09-05 21:29:07 +02:00
|
|
|
private $noBackground;
|
|
|
|
private $bleedHeader;
|
2013-09-19 20:56:58 +02:00
|
|
|
private $properties = array();
|
|
|
|
private $policyObject;
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
public function setHeader($header) {
|
|
|
|
$this->header = $header;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setObjectName($object_name) {
|
|
|
|
$this->objectName = $object_name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-05 21:29:07 +02:00
|
|
|
public function setNoBackground($nada) {
|
|
|
|
$this->noBackground = $nada;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
public function addTag(PhabricatorTagView $tag) {
|
|
|
|
$this->tags[] = $tag;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:23:22 +02:00
|
|
|
public function setImage($uri) {
|
|
|
|
$this->image = $uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubheader($subheader) {
|
|
|
|
$this->subheader = $subheader;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-05 21:29:07 +02:00
|
|
|
public function setBleedHeader($bleed) {
|
|
|
|
$this->bleedHeader = $bleed;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-28 19:29:02 +02:00
|
|
|
public function setGradient($gradient) {
|
|
|
|
$this->gradient = $gradient;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:56:58 +02:00
|
|
|
public function setPolicyObject(PhabricatorPolicyInterface $object) {
|
|
|
|
$this->policyObject = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
public function addProperty($property, $value) {
|
|
|
|
$this->properties[$property] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-10-07 02:10:29 +02:00
|
|
|
public function setStatus($icon, $color, $name) {
|
|
|
|
$header_class = 'phui-header-status';
|
|
|
|
|
|
|
|
if ($color) {
|
|
|
|
$icon = $icon.'-'.$color;
|
|
|
|
$header_class = $header_class.'-'.$color;
|
|
|
|
}
|
|
|
|
|
|
|
|
$img = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_STATUS)
|
|
|
|
->setSpriteIcon($icon);
|
|
|
|
|
|
|
|
$tag = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => "{$header_class} plr",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$img,
|
|
|
|
$name,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this->addProperty(self::PROPERTY_STATUS, $tag);
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function render() {
|
2013-09-17 18:12:37 +02:00
|
|
|
require_celerity_resource('phui-header-view-css');
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-07-10 14:11:08 +02:00
|
|
|
$classes = array();
|
2013-09-17 18:12:37 +02:00
|
|
|
$classes[] = 'phui-header-shell';
|
2013-07-10 14:11:08 +02:00
|
|
|
|
2013-09-05 21:29:07 +02:00
|
|
|
if ($this->noBackground) {
|
2013-09-17 18:12:37 +02:00
|
|
|
$classes[] = 'phui-header-no-backgound';
|
2013-09-05 21:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->bleedHeader) {
|
2013-09-18 23:57:34 +02:00
|
|
|
$classes[] = 'phui-bleed-header';
|
2013-09-05 21:29:07 +02:00
|
|
|
}
|
|
|
|
|
2013-08-28 19:29:02 +02:00
|
|
|
if ($this->gradient) {
|
|
|
|
$classes[] = 'sprite-gradient';
|
|
|
|
$classes[] = 'gradient-'.$this->gradient.'-header';
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:56:58 +02:00
|
|
|
if ($this->properties || $this->policyObject || $this->subheader) {
|
2013-09-17 18:12:37 +02:00
|
|
|
$classes[] = 'phui-header-tall';
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:23:22 +02:00
|
|
|
$image = null;
|
|
|
|
if ($this->image) {
|
|
|
|
$image = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
2013-09-17 18:12:37 +02:00
|
|
|
'class' => 'phui-header-image',
|
2013-07-10 01:23:22 +02:00
|
|
|
'style' => 'background-image: url('.$this->image.')',
|
|
|
|
),
|
|
|
|
'');
|
2013-09-17 18:12:37 +02:00
|
|
|
$classes[] = 'phui-header-has-image';
|
2013-07-10 01:23:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$header = array();
|
|
|
|
$header[] = $this->header;
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
if ($this->objectName) {
|
2013-01-18 09:32:58 +01:00
|
|
|
array_unshift(
|
|
|
|
$header,
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/'.$this->objectName,
|
|
|
|
),
|
|
|
|
$this->objectName),
|
|
|
|
' ');
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
if ($this->tags) {
|
2013-03-30 18:10:30 +01:00
|
|
|
$header[] = ' ';
|
2013-01-25 21:57:47 +01:00
|
|
|
$header[] = phutil_tag(
|
2012-12-11 23:01:35 +01:00
|
|
|
'span',
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
array(
|
2013-09-17 18:12:37 +02:00
|
|
|
'class' => 'phui-header-tags',
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
),
|
2013-03-30 18:10:30 +01:00
|
|
|
array_interleave(' ', $this->tags));
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 01:23:22 +02:00
|
|
|
if ($this->subheader) {
|
|
|
|
$header[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2013-09-17 18:12:37 +02:00
|
|
|
'class' => 'phui-header-subheader',
|
2013-07-10 01:23:22 +02:00
|
|
|
),
|
|
|
|
$this->subheader);
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:56:58 +02:00
|
|
|
if ($this->properties || $this->policyObject) {
|
2013-09-17 18:12:37 +02:00
|
|
|
$property_list = array();
|
|
|
|
foreach ($this->properties as $type => $property) {
|
|
|
|
switch ($type) {
|
2013-09-24 17:42:04 +02:00
|
|
|
case self::PROPERTY_STATUS:
|
2013-09-17 18:12:37 +02:00
|
|
|
$property_list[] = $property;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception('Incorrect Property Passed');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:56:58 +02:00
|
|
|
if ($this->policyObject) {
|
2013-09-27 17:43:41 +02:00
|
|
|
$property_list[] = $this->renderPolicyProperty($this->policyObject);
|
2013-09-19 20:56:58 +02:00
|
|
|
}
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-header-subheader',
|
|
|
|
),
|
|
|
|
$property_list);
|
|
|
|
}
|
|
|
|
|
2013-01-18 03:47:13 +01:00
|
|
|
return phutil_tag(
|
2012-12-11 23:01:35 +01:00
|
|
|
'div',
|
2012-08-15 19:45:06 +02:00
|
|
|
array(
|
2013-07-10 14:11:08 +02:00
|
|
|
'class' => implode(' ', $classes),
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-07-10 01:23:22 +02:00
|
|
|
array(
|
|
|
|
$image,
|
|
|
|
phutil_tag(
|
|
|
|
'h1',
|
|
|
|
array(
|
2013-09-17 18:12:37 +02:00
|
|
|
'class' => 'phui-header-view',
|
2013-07-10 01:23:22 +02:00
|
|
|
),
|
|
|
|
$header),
|
|
|
|
));
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
private function renderPolicyProperty(PhabricatorPolicyInterface $object) {
|
|
|
|
$policies = PhabricatorPolicyQuery::loadPolicies(
|
|
|
|
$this->getUser(),
|
|
|
|
$object);
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
$view_capability = PhabricatorPolicyCapability::CAN_VIEW;
|
|
|
|
$policy = idx($policies, $view_capability);
|
|
|
|
if (!$policy) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phid = $object->getPHID();
|
|
|
|
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_STATUS)
|
|
|
|
->setSpriteIcon($policy->getIcon());
|
|
|
|
|
|
|
|
$link = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2013-09-29 00:55:38 +02:00
|
|
|
'class' => 'policy-link',
|
2013-09-27 17:43:41 +02:00
|
|
|
'href' => '/policy/explain/'.$phid.'/'.$view_capability.'/',
|
|
|
|
'sigil' => 'workflow',
|
|
|
|
),
|
2013-10-14 23:17:25 +02:00
|
|
|
$policy->getShortName());
|
2013-09-27 17:43:41 +02:00
|
|
|
|
|
|
|
return array($icon, $link);
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|