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-08-06 22:43:45 +02:00
|
|
|
->setHeader($rule->getName());
|
|
|
|
|
|
|
|
$actions = $this->buildActionView($rule);
|
|
|
|
$properties = $this->buildPropertyView($rule);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Rule %d', $rule->getID())));
|
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
Provide more structure to PHUIObjectBoxView
Summary:
Three changes here.
- Add `setActionList()`, and use that to set the action list.
- Add `setPropertyList()`, and use that to set the property list.
These will let us add some apropriate CSS so we can fix the border issue, and get rid of a bunch of goofy `.x + .y` selectors.
- Replace `addContent()` with `appendChild()`.
This is just a consistency thing; `AphrontView` already provides `appendChild()`, and `addContent()` did the same thing.
Test Plan:
- Viewed "All Config".
- Viewed a countdown.
- Viewed a revision (add comment, change list, table of contents, comment, local commits, open revisions affecting these files, update history).
- Viewed Diffusion (browse, change, history, repository, lint).
- Viewed Drydock (resource, lease).
- Viewed Files.
- Viewed Herald.
- Viewed Legalpad.
- Viewed macro (edit, edit audio, view).
- Viewed Maniphest.
- Viewed Applications.
- Viewed Paste.
- Viewed People.
- Viewed Phulux.
- Viewed Pholio.
- Viewed Phame (blog, post).
- Viewed Phortune (account, product).
- Viewed Ponder (questions, answers, comments).
- Viewed Releeph.
- Viewed Projects.
- Viewed Slowvote.
NOTE: Images in Files aren't on a black background anymore -- I assume that's on purpose?
NOTE: Some jankiness in Phortune, I'll clean that up when I get back to it. Not related to this diff.
Reviewers: chad
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D7174
2013-09-30 18:36:04 +02:00
|
|
|
->setActionList($actions)
|
|
|
|
->setPropertyList($properties);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
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));
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyView(HeraldRule $rule) {
|
|
|
|
$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
|
|
|
|
|
|
|
$view = id(new PhabricatorPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($rule);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|