mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-02 19:52:44 +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',
|
'HeraldRuleTransactionComment' => 'applications/herald/storage/HeraldRuleTransactionComment.php',
|
||||||
'HeraldRuleTranscript' => 'applications/herald/storage/transcript/HeraldRuleTranscript.php',
|
'HeraldRuleTranscript' => 'applications/herald/storage/transcript/HeraldRuleTranscript.php',
|
||||||
'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php',
|
'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php',
|
||||||
|
'HeraldRuleViewController' => 'applications/herald/controller/HeraldRuleViewController.php',
|
||||||
'HeraldTestConsoleController' => 'applications/herald/controller/HeraldTestConsoleController.php',
|
'HeraldTestConsoleController' => 'applications/herald/controller/HeraldTestConsoleController.php',
|
||||||
'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php',
|
'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php',
|
||||||
'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php',
|
'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php',
|
||||||
|
@ -2640,6 +2641,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'HeraldRuleTransaction' => 'PhabricatorApplicationTransaction',
|
'HeraldRuleTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'HeraldRuleTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
'HeraldRuleTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||||
|
'HeraldRuleViewController' => 'HeraldController',
|
||||||
'HeraldTestConsoleController' => 'HeraldController',
|
'HeraldTestConsoleController' => 'HeraldController',
|
||||||
'HeraldTranscript' => 'HeraldDAO',
|
'HeraldTranscript' => 'HeraldDAO',
|
||||||
'HeraldTranscriptController' => 'HeraldController',
|
'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',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'HeraldRuleListController',
|
||||||
'new/(?:(?P<type>[^/]+)/(?:(?P<rule_type>[^/]+)/)?)?'
|
'new/(?:(?P<type>[^/]+)/(?:(?P<rule_type>[^/]+)/)?)?'
|
||||||
=> 'HeraldNewController',
|
=> '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',
|
'history/(?:(?P<id>[1-9]\d*)/)?' => 'HeraldRuleEditHistoryController',
|
||||||
'delete/(?P<id>[1-9]\d*)/' => 'HeraldDeleteController',
|
'delete/(?P<id>[1-9]\d*)/' => 'HeraldDeleteController',
|
||||||
'test/' => 'HeraldTestConsoleController',
|
'test/' => 'HeraldTestConsoleController',
|
||||||
|
|
|
@ -56,7 +56,7 @@ final class HeraldNewController extends HeraldController {
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setAction('/herald/rule/')
|
->setAction('/herald/edit/')
|
||||||
->setFlexible(true)
|
->setFlexible(true)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSelectControl())
|
id(new AphrontFormSelectControl())
|
||||||
|
@ -68,15 +68,13 @@ final class HeraldNewController extends HeraldController {
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Create Rule'))
|
->setValue(pht('Create Rule'))
|
||||||
->addCancelButton('/herald/view/'.$this->contentType.'/'));
|
->addCancelButton($this->getApplicationURI()));
|
||||||
|
|
||||||
$crumbs = $this
|
$crumbs = $this
|
||||||
->buildApplicationCrumbs()
|
->buildApplicationCrumbs()
|
||||||
->addCrumb(
|
->addCrumb(
|
||||||
id(new PhabricatorCrumbView())
|
id(new PhabricatorCrumbView())
|
||||||
->setName(pht('Create Herald Rule'))
|
->setName(pht('Create Rule')));
|
||||||
->setHref($this->getApplicationURI(
|
|
||||||
'view/'.$this->contentType.'/'.$this->ruleType)));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -18,9 +18,10 @@ final class HeraldRuleController extends HeraldController {
|
||||||
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
|
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
|
||||||
|
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
|
$id = $this->id;
|
||||||
$rule = id(new HeraldRuleQuery())
|
$rule = id(new HeraldRuleQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
@ -30,6 +31,7 @@ final class HeraldRuleController extends HeraldController {
|
||||||
if (!$rule) {
|
if (!$rule) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
$cancel_uri = $this->getApplicationURI("rule/{$id}/");
|
||||||
} else {
|
} else {
|
||||||
$rule = new HeraldRule();
|
$rule = new HeraldRule();
|
||||||
$rule->setAuthorPHID($user->getPHID());
|
$rule->setAuthorPHID($user->getPHID());
|
||||||
|
@ -43,6 +45,8 @@ final class HeraldRuleController extends HeraldController {
|
||||||
$rule_type = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
|
$rule_type = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
|
||||||
}
|
}
|
||||||
$rule->setRuleType($rule_type);
|
$rule->setRuleType($rule_type);
|
||||||
|
|
||||||
|
$cancel_uri = $this->getApplicationURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
|
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
|
||||||
|
@ -70,9 +74,8 @@ final class HeraldRuleController extends HeraldController {
|
||||||
if ($request->isFormPost() && $request->getStr('save')) {
|
if ($request->isFormPost() && $request->getStr('save')) {
|
||||||
list($e_name, $errors) = $this->saveRule($adapter, $rule, $request);
|
list($e_name, $errors) = $this->saveRule($adapter, $rule, $request);
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$uri = '/herald/view/'.
|
$id = $rule->getID();
|
||||||
$rule->getContentType().'/'.
|
$uri = $this->getApplicationURI("rule/{$id}/");
|
||||||
$rule->getRuleType().'/';
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +174,7 @@ final class HeraldRuleController extends HeraldController {
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Save Rule'))
|
->setValue(pht('Save Rule'))
|
||||||
->addCancelButton('/herald/view/'.$rule->getContentType().'/'));
|
->addCancelButton($cancel_uri));
|
||||||
|
|
||||||
$this->setupEditorBehavior($rule, $handles, $adapter);
|
$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