2013-08-06 22:43:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HeraldRuleViewController extends HeraldController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$rule = id(new HeraldRuleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->needConditionsAndActions(true)
|
|
|
|
->executeOne();
|
|
|
|
if (!$rule) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-10-07 02:10:29 +02:00
|
|
|
->setUser($viewer)
|
|
|
|
->setHeader($rule->getName())
|
|
|
|
->setPolicyObject($rule);
|
|
|
|
|
|
|
|
if ($rule->getIsDisabled()) {
|
|
|
|
$header->setStatus(
|
|
|
|
'oh-open',
|
|
|
|
'red',
|
|
|
|
pht('Disabled'));
|
|
|
|
} else {
|
|
|
|
$header->setStatus(
|
|
|
|
'oh-open',
|
|
|
|
null,
|
|
|
|
pht('Active'));
|
|
|
|
}
|
2013-08-06 22:43:45 +02:00
|
|
|
|
|
|
|
$actions = $this->buildActionView($rule);
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyView($rule, $actions);
|
2013-08-06 22:43:45 +02:00
|
|
|
|
2013-12-18 21:00:18 +01:00
|
|
|
$id = $rule->getID();
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
2013-12-18 21:00:18 +01:00
|
|
|
->setName("H{$id}"));
|
2013-08-06 22:43:45 +02:00
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2013-10-07 02:10:29 +02:00
|
|
|
$timeline = $this->buildTimeline($rule);
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2013-10-07 02:10:29 +02:00
|
|
|
$timeline,
|
2013-08-06 22:43:45 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $rule->getName(),
|
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionView(HeraldRule $rule) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$id = $rule->getID();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($rule)
|
|
|
|
->setObjectURI($this->getApplicationURI("rule/{$id}/"));
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$rule,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Rule'))
|
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2013-10-07 02:10:29 +02:00
|
|
|
if ($rule->getIsDisabled()) {
|
|
|
|
$disable_uri = "disable/{$id}/enable/";
|
|
|
|
$disable_icon = 'enable';
|
|
|
|
$disable_name = pht('Enable Rule');
|
|
|
|
} else {
|
|
|
|
$disable_uri = "disable/{$id}/disable/";
|
|
|
|
$disable_icon = 'disable';
|
|
|
|
$disable_name = pht('Disable Rule');
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Disable Rule'))
|
|
|
|
->setHref($this->getApplicationURI($disable_uri))
|
|
|
|
->setIcon($disable_icon)
|
|
|
|
->setName($disable_name)
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
private function buildPropertyView(
|
|
|
|
HeraldRule $rule,
|
|
|
|
PhabricatorActionListView $actions) {
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-09-27 21:05:58 +02:00
|
|
|
$this->loadHandles(HeraldAdapter::getHandlePHIDs($rule));
|
2013-08-06 22:43:45 +02:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = id(new PHUIPropertyListView())
|
2013-08-06 22:43:45 +02:00
|
|
|
->setUser($viewer)
|
2013-10-11 16:53:56 +02:00
|
|
|
->setObject($rule)
|
|
|
|
->setActionList($actions);
|
2013-08-06 22:43:45 +02:00
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Rule Type'),
|
|
|
|
idx(HeraldRuleTypeConfig::getRuleTypeMap(), $rule->getRuleType()));
|
|
|
|
|
|
|
|
if ($rule->isPersonalRule()) {
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Author'),
|
|
|
|
$this->getHandle($rule->getAuthorPHID())->renderLink());
|
|
|
|
}
|
|
|
|
|
|
|
|
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
|
|
|
|
if ($adapter) {
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Applies To'),
|
2013-10-05 00:15:48 +02:00
|
|
|
idx(
|
|
|
|
HeraldAdapter::getEnabledAdapterMap($viewer),
|
|
|
|
$rule->getContentType()));
|
2013-08-06 22:43:45 +02:00
|
|
|
|
|
|
|
$view->invokeWillRenderEvent();
|
|
|
|
|
|
|
|
$view->addSectionHeader(pht('Rule Description'));
|
|
|
|
$view->addTextContent(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'style' => 'white-space: pre-wrap;',
|
|
|
|
),
|
2013-09-27 21:05:58 +02:00
|
|
|
$adapter->renderRuleAsText($rule, $this->getLoadedHandles())));
|
2013-08-06 22:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-07 02:10:29 +02:00
|
|
|
private function buildTimeline(HeraldRule $rule) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$xactions = id(new HeraldTransactionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withObjectPHIDs(array($rule->getPHID()))
|
|
|
|
->needComments(true)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($viewer);
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
if ($xaction->getComment()) {
|
|
|
|
$engine->addObject(
|
|
|
|
$xaction->getComment(),
|
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$engine->process();
|
|
|
|
|
|
|
|
return id(new PhabricatorApplicationTransactionView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObjectPHID($rule->getPHID())
|
|
|
|
->setTransactions($xactions)
|
|
|
|
->setMarkupEngine($engine);
|
|
|
|
}
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
}
|