mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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
This commit is contained in:
parent
299b6f420d
commit
8b475898ee
3 changed files with 106 additions and 1 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorProjectTriggerAddProjectsRule
|
||||
extends PhabricatorProjectTriggerRule {
|
||||
|
||||
const TRIGGERTYPE = 'task.projects.add';
|
||||
|
||||
public function getSelectControLname() {
|
||||
return pht('Add projects');
|
||||
}
|
||||
|
||||
protected function getValueForEditorField() {
|
||||
return $this->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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -66,7 +66,7 @@ final class PhabricatorProjectTriggerManiphestOwnerRule
|
|||
return 'tokenizer';
|
||||
}
|
||||
|
||||
protected function getDatasource() {
|
||||
private function getDatasource() {
|
||||
$datasource = id(new ManiphestAssigneeDatasource())
|
||||
->setLimit(1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue