From 614f39b806790d6298e0a0b3d11aac95f7a8d8bc Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 21 Mar 2019 12:27:14 -0700 Subject: [PATCH] Show a trigger rule summary on the rule view page Summary: Ref T5474. When you view the main page for a rule, show what the rule does before you actually edit it. Test Plan: Viewed a real trigger, then faked invalid/unknown rules: {F6300211} {F6300212} {F6300213} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T5474 Differential Revision: https://secure.phabricator.com/D20303 --- ...habricatorProjectTriggerViewController.php | 44 +++++++++++++++++++ .../storage/PhabricatorProjectTrigger.php | 3 +- .../PhabricatorProjectTriggerInvalidRule.php | 37 ++++++++++++++++ ...catorProjectTriggerManiphestStatusRule.php | 21 +++++++++ .../trigger/PhabricatorProjectTriggerRule.php | 3 ++ .../PhabricatorProjectTriggerUnknownRule.php | 16 +++++++ 6 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/applications/project/controller/trigger/PhabricatorProjectTriggerViewController.php b/src/applications/project/controller/trigger/PhabricatorProjectTriggerViewController.php index d1966cf106..2750adc2ea 100644 --- a/src/applications/project/controller/trigger/PhabricatorProjectTriggerViewController.php +++ b/src/applications/project/controller/trigger/PhabricatorProjectTriggerViewController.php @@ -21,6 +21,7 @@ final class PhabricatorProjectTriggerViewController return new Aphront404Response(); } + $rules_view = $this->newRulesView($trigger); $columns_view = $this->newColumnsView($trigger); $title = $trigger->getObjectName(); @@ -40,6 +41,7 @@ final class PhabricatorProjectTriggerViewController ->setCurtain($curtain) ->setMainColumn( array( + $rules_view, $columns_view, $timeline, )); @@ -139,6 +141,48 @@ final class PhabricatorProjectTriggerViewController ->setTable($table_view); } + private function newRulesView(PhabricatorProjectTrigger $trigger) { + $viewer = $this->getViewer(); + $rules = $trigger->getTriggerRules(); + + $rows = array(); + foreach ($rules as $rule) { + $value = $rule->getRecord()->getValue(); + + $rows[] = array( + $rule->getRuleViewIcon($value), + $rule->getRuleViewLabel(), + $rule->getRuleViewDescription($value), + ); + } + + $table_view = id(new AphrontTableView($rows)) + ->setNoDataString(pht('This trigger has no rules.')) + ->setHeaders( + array( + null, + pht('Rule'), + pht('Action'), + )) + ->setColumnClasses( + array( + null, + 'pri', + 'wide', + )); + + $header_view = id(new PHUIHeaderView()) + ->setHeader(pht('Trigger Rules')) + ->setSubheader( + pht( + 'When a card is dropped into a column that uses this trigger, '. + 'these actions will be taken.')); + + return id(new PHUIObjectBoxView()) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->setHeader($header_view) + ->setTable($table_view); + } private function newCurtain(PhabricatorProjectTrigger $trigger) { $viewer = $this->getViewer(); diff --git a/src/applications/project/storage/PhabricatorProjectTrigger.php b/src/applications/project/storage/PhabricatorProjectTrigger.php index a195e9fc44..5029c2caea 100644 --- a/src/applications/project/storage/PhabricatorProjectTrigger.php +++ b/src/applications/project/storage/PhabricatorProjectTrigger.php @@ -174,7 +174,8 @@ final class PhabricatorProjectTrigger } $rule = id(new PhabricatorProjectTriggerInvalidRule()) - ->setRecord($record); + ->setRecord($record) + ->setException($ex); } $trigger_rules[] = $rule; diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerInvalidRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerInvalidRule.php index 0f9fe52abb..184d818aa5 100644 --- a/src/applications/project/trigger/PhabricatorProjectTriggerInvalidRule.php +++ b/src/applications/project/trigger/PhabricatorProjectTriggerInvalidRule.php @@ -5,6 +5,17 @@ final class PhabricatorProjectTriggerInvalidRule const TRIGGERTYPE = 'invalid'; + private $exception; + + public function setException(Exception $exception) { + $this->exception = $exception; + return $this; + } + + public function getException() { + return $this->exception; + } + public function getDescription() { return pht( 'Invalid rule (of type "%s").', @@ -59,4 +70,30 @@ final class PhabricatorProjectTriggerInvalidRule return null; } + public function getRuleViewLabel() { + return pht('Invalid Rule'); + } + + public function getRuleViewDescription($value) { + $record = $this->getRecord(); + $type = $record->getType(); + + $exception = $this->getException(); + if ($exception) { + return pht( + 'This rule (of type "%s") is invalid: %s', + $type, + $exception->getMessage()); + } else { + return pht( + 'This rule (of type "%s") is invalid.', + $type); + } + } + + public function getRuleViewIcon($value) { + return id(new PHUIIconView()) + ->setIcon('fa-exclamation-triangle', 'red'); + } + } diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerManiphestStatusRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerManiphestStatusRule.php index 2c40563884..5b1ad2db36 100644 --- a/src/applications/project/trigger/PhabricatorProjectTriggerManiphestStatusRule.php +++ b/src/applications/project/trigger/PhabricatorProjectTriggerManiphestStatusRule.php @@ -77,4 +77,25 @@ final class PhabricatorProjectTriggerManiphestStatusRule ); } + public function getRuleViewLabel() { + return pht('Change Status'); + } + + public function getRuleViewDescription($value) { + $status_name = ManiphestTaskStatus::getTaskStatusName($value); + + return pht( + 'Change task status to %s.', + phutil_tag('strong', array(), $status_name)); + } + + public function getRuleViewIcon($value) { + $status_icon = ManiphestTaskStatus::getStatusIcon($value); + $status_color = ManiphestTaskStatus::getStatusColor($value); + + return id(new PHUIIconView()) + ->setIcon($status_icon, $status_color); + } + + } diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerRule.php index 9634086235..49fdbf8a93 100644 --- a/src/applications/project/trigger/PhabricatorProjectTriggerRule.php +++ b/src/applications/project/trigger/PhabricatorProjectTriggerRule.php @@ -39,6 +39,9 @@ abstract class PhabricatorProjectTriggerRule abstract public function getDescription(); abstract public function getSelectControlName(); + abstract public function getRuleViewLabel(); + abstract public function getRuleViewDescription($value); + abstract public function getRuleViewIcon($value); abstract protected function assertValidRuleValue($value); abstract protected function newDropTransactions($object, $value); abstract protected function newDropEffects($value); diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerUnknownRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerUnknownRule.php index 008092061d..f71ee44ad7 100644 --- a/src/applications/project/trigger/PhabricatorProjectTriggerUnknownRule.php +++ b/src/applications/project/trigger/PhabricatorProjectTriggerUnknownRule.php @@ -58,4 +58,20 @@ final class PhabricatorProjectTriggerUnknownRule return null; } + public function getRuleViewLabel() { + return pht('Unknown Rule'); + } + + public function getRuleViewDescription($value) { + return pht( + 'This is an unknown rule of type "%s". An administrator may have '. + 'edited or removed an extension which implements this rule type.', + $this->getRecord()->getType()); + } + + public function getRuleViewIcon($value) { + return id(new PHUIIconView()) + ->setIcon('fa-question-circle', 'yellow'); + } + }