From 8b475898ee922170bcf7a0add520dd73af6ecf68 Mon Sep 17 00:00:00 2001 From: Austin McKinley Date: Fri, 5 Apr 2019 12:48:18 -0700 Subject: [PATCH] Add trigger rule for adding projects to a task Summary: Ref T13269. This is mostly copying code from the similar Herald implementation. Note that the drop effect preview always renders because we don't have the infrastructure to compare lists of edge targets. Test Plan: Created some triggers, dragged some tasks around, checked that tasks that already had project membership didn't write additional edges. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T13269 Differential Revision: https://secure.phabricator.com/D20379 --- src/__phutil_library_map__.php | 2 + ...abricatorProjectTriggerAddProjectsRule.php | 103 ++++++++++++++++++ ...icatorProjectTriggerManiphestOwnerRule.php | 2 +- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/applications/project/trigger/PhabricatorProjectTriggerAddProjectsRule.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 56a55a3d1b..f35838d0eb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4208,6 +4208,7 @@ phutil_register_library_map(array( 'PhabricatorProjectTransactionQuery' => 'applications/project/query/PhabricatorProjectTransactionQuery.php', 'PhabricatorProjectTransactionType' => 'applications/project/xaction/PhabricatorProjectTransactionType.php', 'PhabricatorProjectTrigger' => 'applications/project/storage/PhabricatorProjectTrigger.php', + 'PhabricatorProjectTriggerAddProjectsRule' => 'applications/project/trigger/PhabricatorProjectTriggerAddProjectsRule.php', 'PhabricatorProjectTriggerController' => 'applications/project/controller/trigger/PhabricatorProjectTriggerController.php', 'PhabricatorProjectTriggerCorruptionException' => 'applications/project/exception/PhabricatorProjectTriggerCorruptionException.php', 'PhabricatorProjectTriggerEditController' => 'applications/project/controller/trigger/PhabricatorProjectTriggerEditController.php', @@ -10383,6 +10384,7 @@ phutil_register_library_map(array( 'PhabricatorIndexableInterface', 'PhabricatorDestructibleInterface', ), + 'PhabricatorProjectTriggerAddProjectsRule' => 'PhabricatorProjectTriggerRule', 'PhabricatorProjectTriggerController' => 'PhabricatorProjectController', 'PhabricatorProjectTriggerCorruptionException' => 'Exception', 'PhabricatorProjectTriggerEditController' => 'PhabricatorProjectTriggerController', diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerAddProjectsRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerAddProjectsRule.php new file mode 100644 index 0000000000..2c8418ee02 --- /dev/null +++ b/src/applications/project/trigger/PhabricatorProjectTriggerAddProjectsRule.php @@ -0,0 +1,103 @@ +getDatasource()->getWireTokens($this->getValue()); + } + + protected function assertValidRuleValue($value) { + if (!is_array($value)) { + throw new Exception( + pht( + 'Add project rule value should be a list, but is not '. + '(value is "%s").', + phutil_describe_type($value))); + } + } + + protected function newDropTransactions($object, $value) { + $project_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; + + $xaction = $object->getApplicationTransactionTemplate() + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) + ->setMetadataValue('edge:type', $project_edge_type) + ->setNewValue( + array( + '+' => array_fuse($value), + )); + + return array($xaction); + } + + protected function newDropEffects($value) { + return array( + $this->newEffect() + ->setIcon('fa-briefcase') + ->setContent($this->getRuleViewDescription($value)), + ); + } + + protected function getDefaultValue() { + return null; + } + + protected function getPHUIXControlType() { + return 'tokenizer'; + } + + private function getDatasource() { + return id(new PhabricatorProjectDatasource()) + ->setViewer($this->getViewer()); + } + + protected function getPHUIXControlSpecification() { + $template = id(new AphrontTokenizerTemplateView()) + ->setViewer($this->getViewer()); + + $template_markup = $template->render(); + $datasource = $this->getDatasource(); + + return array( + 'markup' => (string)hsprintf('%s', $template_markup), + 'config' => array( + 'src' => $datasource->getDatasourceURI(), + 'browseURI' => $datasource->getBrowseURI(), + 'placeholder' => $datasource->getPlaceholderText(), + 'limit' => $datasource->getLimit(), + ), + 'value' => null, + ); + } + + public function getRuleViewLabel() { + return pht('Add Projects'); + } + + public function getRuleViewDescription($value) { + return pht( + 'Add projects: %s.', + phutil_tag( + 'strong', + array(), + $this->getViewer() + ->renderHandleList($value) + ->setAsInline(true) + ->render())); + } + + public function getRuleViewIcon($value) { + return id(new PHUIIconView()) + ->setIcon('fa-briefcase', 'green'); + } + + + +} diff --git a/src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php b/src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php index e59a69cdf5..ef9863549e 100644 --- a/src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php +++ b/src/applications/project/trigger/PhabricatorProjectTriggerManiphestOwnerRule.php @@ -66,7 +66,7 @@ final class PhabricatorProjectTriggerManiphestOwnerRule return 'tokenizer'; } - protected function getDatasource() { + private function getDatasource() { $datasource = id(new ManiphestAssigneeDatasource()) ->setLimit(1);