mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 10:42:41 +01:00
Add a normal "view" page for Herald rules
Summary: Ref T2769. This will house the transaction list and replace the "edit log" stuff. The UI is a little bit rough and can probably share more code with the transaction history, but seems mostly-reasonable. Test Plan: {F53253} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2769 Differential Revision: https://secure.phabricator.com/D6690
This commit is contained in:
parent
b767bd3f2d
commit
ce163536ca
6 changed files with 199 additions and 11 deletions
|
@ -628,6 +628,7 @@ phutil_register_library_map(array(
|
|||
'HeraldRuleTransactionComment' => 'applications/herald/storage/HeraldRuleTransactionComment.php',
|
||||
'HeraldRuleTranscript' => 'applications/herald/storage/transcript/HeraldRuleTranscript.php',
|
||||
'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php',
|
||||
'HeraldRuleViewController' => 'applications/herald/controller/HeraldRuleViewController.php',
|
||||
'HeraldTestConsoleController' => 'applications/herald/controller/HeraldTestConsoleController.php',
|
||||
'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php',
|
||||
'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php',
|
||||
|
@ -2640,6 +2641,7 @@ phutil_register_library_map(array(
|
|||
'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'HeraldRuleTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'HeraldRuleTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'HeraldRuleViewController' => 'HeraldController',
|
||||
'HeraldTestConsoleController' => 'HeraldController',
|
||||
'HeraldTranscript' => 'HeraldDAO',
|
||||
'HeraldTranscriptController' => 'HeraldController',
|
||||
|
|
|
@ -663,6 +663,76 @@ abstract class HeraldAdapter {
|
|||
}
|
||||
|
||||
|
||||
public function renderRuleAsText(HeraldRule $rule) {
|
||||
$out = array();
|
||||
|
||||
if ($rule->getMustMatchAll()) {
|
||||
$out[] = pht('When all of these conditions are met:');
|
||||
} else {
|
||||
$out[] = pht('When any of these conditions are met:');
|
||||
}
|
||||
|
||||
$out[] = null;
|
||||
foreach ($rule->getConditions() as $condition) {
|
||||
$out[] = " ".$this->renderConditionAsText($condition);
|
||||
}
|
||||
$out[] = null;
|
||||
|
||||
if ($rule->getRepetitionPolicy() == HeraldRepetitionPolicyConfig::EVERY) {
|
||||
$out[] = pht('Take these actions every time this rule matches:');
|
||||
} else {
|
||||
$out[] = pht('Take these actions the first time this rule matches:');
|
||||
}
|
||||
|
||||
$out[] = null;
|
||||
foreach ($rule->getActions() as $action) {
|
||||
$out[] = " ".$this->renderActionAsText($action);
|
||||
}
|
||||
|
||||
return implode("\n", $out);
|
||||
}
|
||||
|
||||
private function renderConditionAsText(HeraldCondition $condition) {
|
||||
$field_type = $condition->getFieldName();
|
||||
$field_name = idx($this->getFieldNameMap(), $field_type);
|
||||
|
||||
$condition_type = $condition->getFieldCondition();
|
||||
$condition_name = idx($this->getConditionNameMap(), $condition_type);
|
||||
|
||||
$value = $this->renderConditionValueAsText($condition);
|
||||
|
||||
return "{$field_name} {$condition_name} {$value}";
|
||||
}
|
||||
|
||||
private function renderActionAsText(HeraldAction $action) {
|
||||
$rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
|
||||
|
||||
$action_type = $action->getAction();
|
||||
$action_name = idx($this->getActionNameMap($rule_global), $action_type);
|
||||
|
||||
$target = $this->renderActionTargetAsText($action);
|
||||
|
||||
return "{$action_name} {$target}";
|
||||
}
|
||||
|
||||
private function renderConditionValueAsText(HeraldCondition $condition) {
|
||||
// TODO: This produces sketchy results for many conditions.
|
||||
$value = $condition->getValue();
|
||||
if (is_array($value)) {
|
||||
$value = implode(', ', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function renderActionTargetAsText(HeraldAction $action) {
|
||||
// TODO: This produces sketchy results for Flags and PHIDs.
|
||||
$target = $action->getTarget();
|
||||
if (is_array($target)) {
|
||||
$target = implode(', ', $target);
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ final class PhabricatorApplicationHerald extends PhabricatorApplication {
|
|||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'HeraldRuleListController',
|
||||
'new/(?:(?P<type>[^/]+)/(?:(?P<rule_type>[^/]+)/)?)?'
|
||||
=> 'HeraldNewController',
|
||||
'rule/(?:(?P<id>[1-9]\d*)/)?' => 'HeraldRuleController',
|
||||
'rule/(?P<id>[1-9]\d*)/' => 'HeraldRuleViewController',
|
||||
'edit/(?:(?P<id>[1-9]\d*)/)?' => 'HeraldRuleController',
|
||||
'history/(?:(?P<id>[1-9]\d*)/)?' => 'HeraldRuleEditHistoryController',
|
||||
'delete/(?P<id>[1-9]\d*)/' => 'HeraldDeleteController',
|
||||
'test/' => 'HeraldTestConsoleController',
|
||||
|
|
|
@ -56,7 +56,7 @@ final class HeraldNewController extends HeraldController {
|
|||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setAction('/herald/rule/')
|
||||
->setAction('/herald/edit/')
|
||||
->setFlexible(true)
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
|
@ -68,15 +68,13 @@ final class HeraldNewController extends HeraldController {
|
|||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Create Rule'))
|
||||
->addCancelButton('/herald/view/'.$this->contentType.'/'));
|
||||
->addCancelButton($this->getApplicationURI()));
|
||||
|
||||
$crumbs = $this
|
||||
->buildApplicationCrumbs()
|
||||
->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName(pht('Create Herald Rule'))
|
||||
->setHref($this->getApplicationURI(
|
||||
'view/'.$this->contentType.'/'.$this->ruleType)));
|
||||
->setName(pht('Create Rule')));
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
|
|
|
@ -18,9 +18,10 @@ final class HeraldRuleController extends HeraldController {
|
|||
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
|
||||
|
||||
if ($this->id) {
|
||||
$id = $this->id;
|
||||
$rule = id(new HeraldRuleQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
|
@ -30,6 +31,7 @@ final class HeraldRuleController extends HeraldController {
|
|||
if (!$rule) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
$cancel_uri = $this->getApplicationURI("rule/{$id}/");
|
||||
} else {
|
||||
$rule = new HeraldRule();
|
||||
$rule->setAuthorPHID($user->getPHID());
|
||||
|
@ -43,6 +45,8 @@ final class HeraldRuleController extends HeraldController {
|
|||
$rule_type = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
|
||||
}
|
||||
$rule->setRuleType($rule_type);
|
||||
|
||||
$cancel_uri = $this->getApplicationURI();
|
||||
}
|
||||
|
||||
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
|
||||
|
@ -70,9 +74,8 @@ final class HeraldRuleController extends HeraldController {
|
|||
if ($request->isFormPost() && $request->getStr('save')) {
|
||||
list($e_name, $errors) = $this->saveRule($adapter, $rule, $request);
|
||||
if (!$errors) {
|
||||
$uri = '/herald/view/'.
|
||||
$rule->getContentType().'/'.
|
||||
$rule->getRuleType().'/';
|
||||
$id = $rule->getID();
|
||||
$uri = $this->getApplicationURI("rule/{$id}/");
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +174,7 @@ final class HeraldRuleController extends HeraldController {
|
|||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Save Rule'))
|
||||
->addCancelButton('/herald/view/'.$rule->getContentType().'/'));
|
||||
->addCancelButton($cancel_uri));
|
||||
|
||||
$this->setupEditorBehavior($rule, $handles, $adapter);
|
||||
|
||||
|
|
114
src/applications/herald/controller/HeraldRuleViewController.php
Normal file
114
src/applications/herald/controller/HeraldRuleViewController.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?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();
|
||||
}
|
||||
|
||||
$header = id(new PhabricatorHeaderView())
|
||||
->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())));
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$header,
|
||||
$actions,
|
||||
$properties,
|
||||
),
|
||||
array(
|
||||
'title' => $rule->getName(),
|
||||
'device' => true,
|
||||
'dust' => 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();
|
||||
|
||||
$this->loadHandles(array($rule->getAuthorPHID()));
|
||||
|
||||
$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'),
|
||||
idx(HeraldAdapter::getEnabledAdapterMap(), $rule->getContentType()));
|
||||
|
||||
$view->invokeWillRenderEvent();
|
||||
|
||||
$view->addSectionHeader(pht('Rule Description'));
|
||||
$view->addTextContent(
|
||||
phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'style' => 'white-space: pre-wrap;',
|
||||
),
|
||||
$adapter->renderRuleAsText($rule)));
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue