mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-31 18:01:00 +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);
|
||||
|
||||
$actions = $this->buildActionView($document);
|
||||
$properties = $this->buildPropertyView($document, $engine, $subscribers);
|
||||
$properties = $this->buildPropertyView($document, $engine);
|
||||
|
||||
$comment_form_id = celerity_generate_unique_node_id();
|
||||
|
||||
|
@ -146,8 +146,7 @@ final class LegalpadDocumentViewController extends LegalpadController {
|
|||
|
||||
private function buildPropertyView(
|
||||
LegalpadDocument $document,
|
||||
PhabricatorMarkupEngine $engine,
|
||||
array $subscribers) {
|
||||
PhabricatorMarkupEngine $engine) {
|
||||
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
|
@ -185,20 +184,6 @@ final class LegalpadDocumentViewController extends LegalpadController {
|
|||
pht('Visible To'),
|
||||
$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();
|
||||
|
||||
return $properties;
|
||||
|
|
|
@ -26,10 +26,6 @@ final class PhabricatorMacroViewController
|
|||
$title_short = pht('Macro "%s"', $macro->getName());
|
||||
$title_long = pht('Image Macro "%s"', $macro->getName());
|
||||
|
||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$macro->getPHID());
|
||||
|
||||
$this->loadHandles($subscribers);
|
||||
$actions = $this->buildActionView($macro);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
|
@ -39,7 +35,7 @@ final class PhabricatorMacroViewController
|
|||
->setHref($this->getApplicationURI('/view/'.$macro->getID().'/'))
|
||||
->setName($title_short));
|
||||
|
||||
$properties = $this->buildPropertyView($macro, $file, $subscribers);
|
||||
$properties = $this->buildPropertyView($macro, $file);
|
||||
|
||||
$xactions = id(new PhabricatorMacroTransactionQuery())
|
||||
->setViewer($request->getUser())
|
||||
|
@ -140,24 +136,13 @@ final class PhabricatorMacroViewController
|
|||
|
||||
private function buildPropertyView(
|
||||
PhabricatorFileImageMacro $macro,
|
||||
PhabricatorFile $file = null,
|
||||
array $subscribers) {
|
||||
PhabricatorFile $file = null) {
|
||||
|
||||
$view = new PhabricatorPropertyListView();
|
||||
$view = id(new PhabricatorPropertyListView())
|
||||
->setUser($this->getRequest()->getUser())
|
||||
->setObject($macro);
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
$view->addProperty(
|
||||
pht('Subscribers'),
|
||||
$sub_view);
|
||||
$view->invokeWillRenderEvent();
|
||||
|
||||
if ($file) {
|
||||
$view->addImageContent(
|
||||
|
|
|
@ -37,17 +37,9 @@ final class PholioMockViewController extends PholioController {
|
|||
->withObjectPHIDs(array($mock->getPHID()))
|
||||
->execute();
|
||||
|
||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$mock->getPHID());
|
||||
|
||||
$phids = array();
|
||||
$phids[] = $mock->getAuthorPHID();
|
||||
foreach ($subscribers as $subscriber) {
|
||||
$phids[] = $subscriber;
|
||||
}
|
||||
$phids = array($mock->getAuthorPHID());
|
||||
$this->loadHandles($phids);
|
||||
|
||||
|
||||
$engine = id(new PhabricatorMarkupEngine())
|
||||
->setViewer($user);
|
||||
$engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION);
|
||||
|
@ -66,7 +58,7 @@ final class PholioMockViewController extends PholioController {
|
|||
->setHeader($title);
|
||||
|
||||
$actions = $this->buildActionView($mock);
|
||||
$properties = $this->buildPropertyView($mock, $engine, $subscribers);
|
||||
$properties = $this->buildPropertyView($mock, $engine);
|
||||
|
||||
require_celerity_resource('pholio-css');
|
||||
require_celerity_resource('pholio-inline-comments-css');
|
||||
|
@ -137,8 +129,7 @@ final class PholioMockViewController extends PholioController {
|
|||
|
||||
private function buildPropertyView(
|
||||
PholioMock $mock,
|
||||
PhabricatorMarkupEngine $engine,
|
||||
array $subscribers) {
|
||||
PhabricatorMarkupEngine $engine) {
|
||||
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
|
@ -162,20 +153,6 @@ final class PholioMockViewController extends PholioController {
|
|||
pht('Visible To'),
|
||||
$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->addImageContent(
|
||||
|
|
|
@ -5,13 +5,17 @@ final class PhabricatorSubscriptionsUIEventListener
|
|||
|
||||
public function register() {
|
||||
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
|
||||
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES);
|
||||
}
|
||||
|
||||
public function handleEvent(PhutilEvent $event) {
|
||||
switch ($event->getType()) {
|
||||
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
|
||||
$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);
|
||||
}
|
||||
|
||||
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