Commit e8bb24fd authored by Chad Little's avatar Chad Little
Browse files

Policy, Status in PHUIHeaderView

Summary: The adds the ability to set 'properties' such as state, privacy, due date to the header of objects.

Test Plan: Implemented in Paste, Pholio. Tested various states.

Reviewers: epriestley, btrahan

Reviewed By: epriestley

CC: Korvin, aran

Differential Revision: https://secure.phabricator.com/D7016
parent 01eedd6e
......@@ -104,7 +104,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$add_comment_header = id(new PhabricatorHeaderView())
$add_comment_header = id(new PHUIHeaderView())
->setHeader(
$is_serious
? pht('Add Comment')
......@@ -142,8 +142,16 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
}
private function buildHeaderView(PhabricatorPaste $paste) {
return id(new PhabricatorHeaderView())
->setHeader($paste->getTitle());
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$this->getRequest()->getUser(),
$paste,
$icon = true);
$header = id(new PHUIHeaderView())
->setHeader($paste->getTitle())
->addProperty(PHUIHeaderView::PROPERTY_POLICY,
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
return $header;
}
private function buildActionView(
......@@ -217,10 +225,6 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
$user,
$paste);
$properties->addProperty(
pht('Visible To'),
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
return $properties;
}
......
......@@ -32,7 +32,7 @@ final class PhabricatorPeopleProfileController
$picture = $user->loadProfileImageURI();
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($user->getUserName().' ('.$user->getRealName().')')
->setSubheader($profile->getTitle())
->setImage($picture);
......
......@@ -33,7 +33,7 @@ final class PhameBlogViewController extends PhameController {
$nav = $this->renderSideNavFilterView(null);
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($blog->getName());
$handle_phids = array_merge(
......
......@@ -43,7 +43,7 @@ final class PhamePostViewController extends PhameController {
$nav->appendChild($crumbs);
$nav->appendChild(
id(new PhabricatorHeaderView())
id(new PHUIHeaderView())
->setHeader($post->getTitle()));
if ($post->isDraft()) {
......
......@@ -30,7 +30,7 @@ final class PhluxViewController extends PhluxController {
->setName($title)
->setHref($request->getRequestURI()));
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
$actions = id(new PhabricatorActionListView())
......
......@@ -52,7 +52,7 @@ final class PholioImageHistoryController extends PholioController {
$latest_image->getName(),
$mock->getName());
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
require_celerity_resource('pholio-css');
......
......@@ -67,8 +67,15 @@ final class PholioMockViewController extends PholioController {
$title = $mock->getName();
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user,
$mock,
$icon = true);
$header = id(new PHUIHeaderView())
->setHeader($title)
->addProperty(PHUIHeaderView::PROPERTY_POLICY,
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
$actions = $this->buildActionView($mock);
$properties = $this->buildPropertyView($mock, $engine);
......@@ -208,14 +215,6 @@ final class PholioMockViewController extends PholioController {
pht('Created'),
phabricator_datetime($mock->getDateCreated(), $user));
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user,
$mock);
$properties->addProperty(
pht('Visible To'),
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
if ($this->getManiphestTaskPHIDs()) {
$properties->addProperty(
pht('Maniphest Tasks'),
......@@ -241,7 +240,7 @@ final class PholioMockViewController extends PholioController {
? pht('Add Comment')
: pht('History Beckons');
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
$button_name = $is_serious
......
......@@ -29,7 +29,7 @@ final class PhortuneAccountViewController extends PhortuneController {
->setName(pht('Account'))
->setHref($request->getRequestURI()));
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
$actions = id(new PhabricatorActionListView())
......@@ -80,7 +80,7 @@ final class PhortuneAccountViewController extends PhortuneController {
$request = $this->getRequest();
$user = $request->getUser();
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Methods'));
$id = $account->getID();
......@@ -141,7 +141,7 @@ final class PhortuneAccountViewController extends PhortuneController {
$request = $this->getRequest();
$user = $request->getUser();
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Purchase History'));
return array(
......@@ -154,7 +154,7 @@ final class PhortuneAccountViewController extends PhortuneController {
$request = $this->getRequest();
$user = $request->getUser();
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Account History'));
$xactions = id(new PhortuneAccountTransactionQuery())
......
......@@ -155,7 +155,7 @@ final class PhortunePaymentMethodEditController
$request = $this->getRequest();
$title = pht('Add Payment Method');
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
$crumbs = $this->buildApplicationCrumbs();
......
......@@ -144,7 +144,7 @@ final class PhortuneProductEditController extends PhabricatorController {
->setName($is_create ? pht('Create') : pht('Edit'))
->setHref($request->getRequestURI()));
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Edit Product'));
return $this->buildApplicationPage(
......
......@@ -27,7 +27,7 @@ final class PhortuneProductListController extends PhabricatorController {
->setHref($this->getApplicationURI('product/edit/'))
->setIcon('create'));
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Product List'));
$product_list = id(new PHUIObjectItemListView())
......
......@@ -23,7 +23,7 @@ final class PhortuneProductViewController extends PhortuneController {
$title = pht('Product: %s', $product->getProductName());
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($product->getProductName());
$account = $this->loadActiveAccount($user);
......
......@@ -115,7 +115,7 @@ final class PhrictionDiffController
$title = "Version $l vs $r";
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
$crumbs->addCrumb(
......
......@@ -159,7 +159,7 @@ final class PhrictionDocumentController
$crumbs->addCrumb($view);
}
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($page_title);
$page_content = id(new PHUIDocumentView())
......
......@@ -144,7 +144,7 @@ final class PhrictionHistoryController
->setHref(
PhrictionDocument::getSlugURI($document->getSlug(), 'history')));
$header = new PhabricatorHeaderView();
$header = new PHUIHeaderView();
$header->setHeader(pht('Document History for %s',
phutil_tag(
'a',
......
......@@ -6,6 +6,7 @@ final class PhabricatorPolicy {
private $name;
private $type;
private $href;
private $icon;
public static function newFromPolicyAndHandle(
$policy_identifier,
......@@ -86,6 +87,29 @@ final class PhabricatorPolicy {
return $this->href;
}
public function getIcon() {
switch ($this->getType()) {
case PhabricatorPolicyType::TYPE_GLOBAL:
static $map = array(
PhabricatorPolicies::POLICY_PUBLIC => 'policy-public',
PhabricatorPolicies::POLICY_USER => 'policy-all',
PhabricatorPolicies::POLICY_ADMIN => 'policy-admin',
PhabricatorPolicies::POLICY_NOONE => 'policy-noone',
);
return idx($map, $this->getPHID(), 'policy-unknown');
break;
case PhabricatorPolicyType::TYPE_PROJECT:
return 'policy-project';
break;
case PhabricatorPolicyType::TYPE_MASKED:
return 'policy-custom';
break;
default:
return 'policy-unknown';
break;
}
}
public function getSortKey() {
return sprintf(
'%02d%s',
......@@ -117,16 +141,27 @@ final class PhabricatorPolicy {
}
}
public function renderDescription() {
public function renderDescription($icon=false) {
$img = null;
if ($icon) {
$img = id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_STATUS)
->setSpriteIcon($this->getIcon());
}
if ($this->getHref()) {
$desc = phutil_tag(
'a',
array(
'href' => $this->getHref(),
'class' => 'policy-link',
),
$this->getName());
array(
$img,
$this->getName(),
));
} else {
$desc = $this->getName();
$desc = array($img, $this->getName());
}
switch ($this->getType()) {
......@@ -140,6 +175,4 @@ final class PhabricatorPolicy {
return $desc;
}
}
}
......@@ -17,7 +17,8 @@ final class PhabricatorPolicyQuery extends PhabricatorQuery {
public static function renderPolicyDescriptions(
PhabricatorUser $viewer,
PhabricatorPolicyInterface $object) {
PhabricatorPolicyInterface $object,
$icon=false) {
$results = array();
$policies = null;
......@@ -31,7 +32,7 @@ final class PhabricatorPolicyQuery extends PhabricatorQuery {
}
if (isset($global[$policy])) {
$results[$capability] = $global[$policy]->renderDescription();
$results[$capability] = $global[$policy]->renderDescription($icon);
continue;
}
......@@ -44,7 +45,7 @@ final class PhabricatorPolicyQuery extends PhabricatorQuery {
->execute();
}
$results[$capability] = $policies[$policy]->renderDescription();
$results[$capability] = $policies[$policy]->renderDescription($icon);
}
return $results;
......
......@@ -44,7 +44,7 @@ final class PonderQuestionViewController extends PonderController {
->setActionURI("/ponder/answer/add/");
}
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($question->getTitle());
$actions = $this->buildActionListView($question);
......@@ -251,7 +251,7 @@ final class PonderQuestionViewController extends PonderController {
$out[] = phutil_tag('br');
$out[] = phutil_tag('br');
$out[] = id(new PhabricatorHeaderView())
$out[] = id(new PHUIHeaderView())
->setHeader($this->getHandle($author_phid)->getFullName())
->setImage($this->getHandle($author_phid)->getImageURI());
......
......@@ -21,7 +21,7 @@ final class PonderAddAnswerView extends AphrontView {
$question = $this->question;
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader(pht('Add Answer'));
$form = new AphrontFormView();
......
......@@ -59,7 +59,7 @@ final class PhabricatorProjectProfileController
$tasks,
$content);
$header = id(new PhabricatorHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($project->getName())
->setSubheader(phutil_utf8_shorten($profile->getBlurb(), 1024))
->setImage($picture);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment