1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Add trigger rule to remove projects from tasks

Summary: Ref T13269. Same as D20379 with the polarity reversed.

Test Plan: Added some triggers, removed some projects, observed expected results.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T13269

Differential Revision: https://secure.phabricator.com/D20390
This commit is contained in:
Austin McKinley 2019-04-10 12:13:55 -07:00
parent 8b475898ee
commit 55d64d0fab
2 changed files with 105 additions and 0 deletions

View file

@ -4222,6 +4222,7 @@ phutil_register_library_map(array(
'PhabricatorProjectTriggerPHIDType' => 'applications/project/phid/PhabricatorProjectTriggerPHIDType.php',
'PhabricatorProjectTriggerPlaySoundRule' => 'applications/project/trigger/PhabricatorProjectTriggerPlaySoundRule.php',
'PhabricatorProjectTriggerQuery' => 'applications/project/query/PhabricatorProjectTriggerQuery.php',
'PhabricatorProjectTriggerRemoveProjectsRule' => 'applications/project/trigger/PhabricatorProjectTriggerRemoveProjectsRule.php',
'PhabricatorProjectTriggerRule' => 'applications/project/trigger/PhabricatorProjectTriggerRule.php',
'PhabricatorProjectTriggerRuleRecord' => 'applications/project/trigger/PhabricatorProjectTriggerRuleRecord.php',
'PhabricatorProjectTriggerRulesetTransaction' => 'applications/project/xaction/trigger/PhabricatorProjectTriggerRulesetTransaction.php',
@ -10398,6 +10399,7 @@ phutil_register_library_map(array(
'PhabricatorProjectTriggerPHIDType' => 'PhabricatorPHIDType',
'PhabricatorProjectTriggerPlaySoundRule' => 'PhabricatorProjectTriggerRule',
'PhabricatorProjectTriggerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorProjectTriggerRemoveProjectsRule' => 'PhabricatorProjectTriggerRule',
'PhabricatorProjectTriggerRule' => 'Phobject',
'PhabricatorProjectTriggerRuleRecord' => 'Phobject',
'PhabricatorProjectTriggerRulesetTransaction' => 'PhabricatorProjectTriggerTransactionType',

View file

@ -0,0 +1,103 @@
<?php
final class PhabricatorProjectTriggerRemoveProjectsRule
extends PhabricatorProjectTriggerRule {
const TRIGGERTYPE = 'task.projects.remove';
public function getSelectControLname() {
return pht('Remove projects');
}
protected function getValueForEditorField() {
return $this->getDatasource()->getWireTokens($this->getValue());
}
protected function assertValidRuleValue($value) {
if (!is_array($value)) {
throw new Exception(
pht(
'Remove 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', 'red')
->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('Remove Projects');
}
public function getRuleViewDescription($value) {
return pht(
'Remove projects: %s.',
phutil_tag(
'strong',
array(),
$this->getViewer()
->renderHandleList($value)
->setAsInline(true)
->render()));
}
public function getRuleViewIcon($value) {
return id(new PHUIIconView())
->setIcon('fa-briefcase', 'red');
}
}