mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-05 20:31:03 +01:00
UIEvents - add support for "subscribers property"
Summary: Fixes T3487 and reduces a bit of code duplication. Test Plan: viewed legalpad, macro, and pholio and saw proper subscriber properties Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T3487 Differential Revision: https://secure.phabricator.com/D6383
This commit is contained in:
parent
15066e4fa0
commit
0bfbe18c3e
4 changed files with 48 additions and 65 deletions
|
@ -68,7 +68,7 @@ final class LegalpadDocumentViewController extends LegalpadController {
|
||||||
->setHeader($title);
|
->setHeader($title);
|
||||||
|
|
||||||
$actions = $this->buildActionView($document);
|
$actions = $this->buildActionView($document);
|
||||||
$properties = $this->buildPropertyView($document, $engine, $subscribers);
|
$properties = $this->buildPropertyView($document, $engine);
|
||||||
|
|
||||||
$comment_form_id = celerity_generate_unique_node_id();
|
$comment_form_id = celerity_generate_unique_node_id();
|
||||||
|
|
||||||
|
@ -146,8 +146,7 @@ final class LegalpadDocumentViewController extends LegalpadController {
|
||||||
|
|
||||||
private function buildPropertyView(
|
private function buildPropertyView(
|
||||||
LegalpadDocument $document,
|
LegalpadDocument $document,
|
||||||
PhabricatorMarkupEngine $engine,
|
PhabricatorMarkupEngine $engine) {
|
||||||
array $subscribers) {
|
|
||||||
|
|
||||||
$user = $this->getRequest()->getUser();
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
@ -185,20 +184,6 @@ final class LegalpadDocumentViewController extends LegalpadController {
|
||||||
pht('Visible To'),
|
pht('Visible To'),
|
||||||
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
||||||
|
|
||||||
if ($subscribers) {
|
|
||||||
$sub_view = array();
|
|
||||||
foreach ($subscribers as $subscriber) {
|
|
||||||
$sub_view[] = $this->getHandle($subscriber)->renderLink();
|
|
||||||
}
|
|
||||||
$sub_view = phutil_implode_html(', ', $sub_view);
|
|
||||||
} else {
|
|
||||||
$sub_view = phutil_tag('em', array(), pht('None'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$properties->addProperty(
|
|
||||||
pht('Subscribers'),
|
|
||||||
$sub_view);
|
|
||||||
|
|
||||||
$properties->invokeWillRenderEvent();
|
$properties->invokeWillRenderEvent();
|
||||||
|
|
||||||
return $properties;
|
return $properties;
|
||||||
|
|
|
@ -26,10 +26,6 @@ final class PhabricatorMacroViewController
|
||||||
$title_short = pht('Macro "%s"', $macro->getName());
|
$title_short = pht('Macro "%s"', $macro->getName());
|
||||||
$title_long = pht('Image Macro "%s"', $macro->getName());
|
$title_long = pht('Image Macro "%s"', $macro->getName());
|
||||||
|
|
||||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
|
||||||
$macro->getPHID());
|
|
||||||
|
|
||||||
$this->loadHandles($subscribers);
|
|
||||||
$actions = $this->buildActionView($macro);
|
$actions = $this->buildActionView($macro);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
@ -39,7 +35,7 @@ final class PhabricatorMacroViewController
|
||||||
->setHref($this->getApplicationURI('/view/'.$macro->getID().'/'))
|
->setHref($this->getApplicationURI('/view/'.$macro->getID().'/'))
|
||||||
->setName($title_short));
|
->setName($title_short));
|
||||||
|
|
||||||
$properties = $this->buildPropertyView($macro, $file, $subscribers);
|
$properties = $this->buildPropertyView($macro, $file);
|
||||||
|
|
||||||
$xactions = id(new PhabricatorMacroTransactionQuery())
|
$xactions = id(new PhabricatorMacroTransactionQuery())
|
||||||
->setViewer($request->getUser())
|
->setViewer($request->getUser())
|
||||||
|
@ -140,24 +136,13 @@ final class PhabricatorMacroViewController
|
||||||
|
|
||||||
private function buildPropertyView(
|
private function buildPropertyView(
|
||||||
PhabricatorFileImageMacro $macro,
|
PhabricatorFileImageMacro $macro,
|
||||||
PhabricatorFile $file = null,
|
PhabricatorFile $file = null) {
|
||||||
array $subscribers) {
|
|
||||||
|
|
||||||
$view = new PhabricatorPropertyListView();
|
$view = id(new PhabricatorPropertyListView())
|
||||||
|
->setUser($this->getRequest()->getUser())
|
||||||
|
->setObject($macro);
|
||||||
|
|
||||||
if ($subscribers) {
|
$view->invokeWillRenderEvent();
|
||||||
$sub_view = array();
|
|
||||||
foreach ($subscribers as $subscriber) {
|
|
||||||
$sub_view[] = $this->getHandle($subscriber)->renderLink();
|
|
||||||
}
|
|
||||||
$sub_view = phutil_implode_html(', ', $sub_view);
|
|
||||||
} else {
|
|
||||||
$sub_view = phutil_tag('em', array(), pht('None'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$view->addProperty(
|
|
||||||
pht('Subscribers'),
|
|
||||||
$sub_view);
|
|
||||||
|
|
||||||
if ($file) {
|
if ($file) {
|
||||||
$view->addImageContent(
|
$view->addImageContent(
|
||||||
|
|
|
@ -37,17 +37,9 @@ final class PholioMockViewController extends PholioController {
|
||||||
->withObjectPHIDs(array($mock->getPHID()))
|
->withObjectPHIDs(array($mock->getPHID()))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
$phids = array($mock->getAuthorPHID());
|
||||||
$mock->getPHID());
|
|
||||||
|
|
||||||
$phids = array();
|
|
||||||
$phids[] = $mock->getAuthorPHID();
|
|
||||||
foreach ($subscribers as $subscriber) {
|
|
||||||
$phids[] = $subscriber;
|
|
||||||
}
|
|
||||||
$this->loadHandles($phids);
|
$this->loadHandles($phids);
|
||||||
|
|
||||||
|
|
||||||
$engine = id(new PhabricatorMarkupEngine())
|
$engine = id(new PhabricatorMarkupEngine())
|
||||||
->setViewer($user);
|
->setViewer($user);
|
||||||
$engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION);
|
$engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION);
|
||||||
|
@ -66,7 +58,7 @@ final class PholioMockViewController extends PholioController {
|
||||||
->setHeader($title);
|
->setHeader($title);
|
||||||
|
|
||||||
$actions = $this->buildActionView($mock);
|
$actions = $this->buildActionView($mock);
|
||||||
$properties = $this->buildPropertyView($mock, $engine, $subscribers);
|
$properties = $this->buildPropertyView($mock, $engine);
|
||||||
|
|
||||||
require_celerity_resource('pholio-css');
|
require_celerity_resource('pholio-css');
|
||||||
require_celerity_resource('pholio-inline-comments-css');
|
require_celerity_resource('pholio-inline-comments-css');
|
||||||
|
@ -137,8 +129,7 @@ final class PholioMockViewController extends PholioController {
|
||||||
|
|
||||||
private function buildPropertyView(
|
private function buildPropertyView(
|
||||||
PholioMock $mock,
|
PholioMock $mock,
|
||||||
PhabricatorMarkupEngine $engine,
|
PhabricatorMarkupEngine $engine) {
|
||||||
array $subscribers) {
|
|
||||||
|
|
||||||
$user = $this->getRequest()->getUser();
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
@ -162,20 +153,6 @@ final class PholioMockViewController extends PholioController {
|
||||||
pht('Visible To'),
|
pht('Visible To'),
|
||||||
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
||||||
|
|
||||||
if ($subscribers) {
|
|
||||||
$sub_view = array();
|
|
||||||
foreach ($subscribers as $subscriber) {
|
|
||||||
$sub_view[] = $this->getHandle($subscriber)->renderLink();
|
|
||||||
}
|
|
||||||
$sub_view = phutil_implode_html(', ', $sub_view);
|
|
||||||
} else {
|
|
||||||
$sub_view = phutil_tag('em', array(), pht('None'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$properties->addProperty(
|
|
||||||
pht('Subscribers'),
|
|
||||||
$sub_view);
|
|
||||||
|
|
||||||
$properties->invokeWillRenderEvent();
|
$properties->invokeWillRenderEvent();
|
||||||
|
|
||||||
$properties->addImageContent(
|
$properties->addImageContent(
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorSubscriptionsUIEventListener
|
||||||
|
|
||||||
public function register() {
|
public function register() {
|
||||||
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
|
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
|
||||||
|
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleEvent(PhutilEvent $event) {
|
public function handleEvent(PhutilEvent $event) {
|
||||||
|
@ -12,6 +13,9 @@ final class PhabricatorSubscriptionsUIEventListener
|
||||||
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
|
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
|
||||||
$this->handleActionEvent($event);
|
$this->handleActionEvent($event);
|
||||||
break;
|
break;
|
||||||
|
case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES:
|
||||||
|
$this->handlePropertyEvent($event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,4 +85,36 @@ final class PhabricatorSubscriptionsUIEventListener
|
||||||
$event->setValue('actions', $actions);
|
$event->setValue('actions', $actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function handlePropertyEvent($event) {
|
||||||
|
$user = $event->getUser();
|
||||||
|
$object = $event->getValue('object');
|
||||||
|
|
||||||
|
if (!$object || !$object->getPHID()) {
|
||||||
|
// No object, or the object has no PHID yet..
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($object instanceof PhabricatorSubscribableInterface)) {
|
||||||
|
// This object isn't subscribable.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||||
|
$object->getPHID());
|
||||||
|
if ($subscribers) {
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($subscribers))
|
||||||
|
->setViewer($user)
|
||||||
|
->loadHandles();
|
||||||
|
$sub_view = array();
|
||||||
|
foreach ($subscribers as $subscriber) {
|
||||||
|
$sub_view[] = $handles[$subscriber]->renderLink();
|
||||||
|
}
|
||||||
|
$sub_view = phutil_implode_html(', ', $sub_view);
|
||||||
|
} else {
|
||||||
|
$sub_view = phutil_tag('em', array(), pht('None'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = $event->getValue('view');
|
||||||
|
$view->addProperty(pht('Subscribers'), $sub_view);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue