1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 11:22:40 +01:00
phorge-phorge/src/view/phui/PHUIHeaderView.php
epriestley 2e5ac128b3 Explain policy exception rules to users
Summary:
Ref T603. Adds clarifying text which expands on policies and explains exceptions and rules. The goal is to provide an easy way for users to learn about special policy rules, like "task owners can always see a task".

This presentation might be a little aggressive. That's probably OK as we introduce policies, but something a little more tempered might be better down the road.

Test Plan: See screenshot.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7150
2013-09-27 08:43:41 -07:00

205 lines
4.4 KiB
PHP

<?php
final class PHUIHeaderView extends AphrontView {
const PROPERTY_STATUS = 1;
private $objectName;
private $header;
private $tags = array();
private $image;
private $subheader;
private $gradient;
private $noBackground;
private $bleedHeader;
private $properties = array();
private $policyObject;
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setObjectName($object_name) {
$this->objectName = $object_name;
return $this;
}
public function setNoBackground($nada) {
$this->noBackground = $nada;
return $this;
}
public function addTag(PhabricatorTagView $tag) {
$this->tags[] = $tag;
return $this;
}
public function setImage($uri) {
$this->image = $uri;
return $this;
}
public function setSubheader($subheader) {
$this->subheader = $subheader;
return $this;
}
public function setBleedHeader($bleed) {
$this->bleedHeader = $bleed;
return $this;
}
public function setGradient($gradient) {
$this->gradient = $gradient;
return $this;
}
public function setPolicyObject(PhabricatorPolicyInterface $object) {
$this->policyObject = $object;
return $this;
}
public function addProperty($property, $value) {
$this->properties[$property] = $value;
return $this;
}
public function render() {
require_celerity_resource('phui-header-view-css');
$classes = array();
$classes[] = 'phui-header-shell';
if ($this->noBackground) {
$classes[] = 'phui-header-no-backgound';
}
if ($this->bleedHeader) {
$classes[] = 'phui-bleed-header';
}
if ($this->gradient) {
$classes[] = 'sprite-gradient';
$classes[] = 'gradient-'.$this->gradient.'-header';
}
if ($this->properties || $this->policyObject || $this->subheader) {
$classes[] = 'phui-header-tall';
}
$image = null;
if ($this->image) {
$image = phutil_tag(
'span',
array(
'class' => 'phui-header-image',
'style' => 'background-image: url('.$this->image.')',
),
'');
$classes[] = 'phui-header-has-image';
}
$header = array();
$header[] = $this->header;
if ($this->objectName) {
array_unshift(
$header,
phutil_tag(
'a',
array(
'href' => '/'.$this->objectName,
),
$this->objectName),
' ');
}
if ($this->tags) {
$header[] = ' ';
$header[] = phutil_tag(
'span',
array(
'class' => 'phui-header-tags',
),
array_interleave(' ', $this->tags));
}
if ($this->subheader) {
$header[] = phutil_tag(
'div',
array(
'class' => 'phui-header-subheader',
),
$this->subheader);
}
if ($this->properties || $this->policyObject) {
$property_list = array();
foreach ($this->properties as $type => $property) {
switch ($type) {
case self::PROPERTY_STATUS:
$property_list[] = $property;
break;
default:
throw new Exception('Incorrect Property Passed');
break;
}
}
if ($this->policyObject) {
$property_list[] = $this->renderPolicyProperty($this->policyObject);
}
$header[] = phutil_tag(
'div',
array(
'class' => 'phui-header-subheader',
),
$property_list);
}
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
array(
$image,
phutil_tag(
'h1',
array(
'class' => 'phui-header-view',
),
$header),
));
}
private function renderPolicyProperty(PhabricatorPolicyInterface $object) {
$policies = PhabricatorPolicyQuery::loadPolicies(
$this->getUser(),
$object);
$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(
'href' => '/policy/explain/'.$phid.'/'.$view_capability.'/',
'sigil' => 'workflow',
),
$policy->getName());
return array($icon, $link);
}
}