1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00

Add maniphest.subtypes for configuring task subtypes

Summary:
Ref T12314. Builds toward letting you define "animal" and "plant" tasks.

This just adds some configuration. I'll probably add some more quality-of-life options (like "icon") later but these are the only bits I'm sure I'll need.

Test Plan:
  - Configured sensible subtypes.
  - Tried to configure bad subtypes: bad key, missing "default", duplicate keys. Got sensible error messages.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12314

Differential Revision: https://secure.phabricator.com/D17440
This commit is contained in:
epriestley 2017-03-01 15:19:21 -08:00
parent 91ef237290
commit 1b96f2fc28
4 changed files with 108 additions and 0 deletions

View file

@ -1471,6 +1471,7 @@ phutil_register_library_map(array(
'ManiphestStatusConfigOptionType' => 'applications/maniphest/config/ManiphestStatusConfigOptionType.php', 'ManiphestStatusConfigOptionType' => 'applications/maniphest/config/ManiphestStatusConfigOptionType.php',
'ManiphestStatusEmailCommand' => 'applications/maniphest/command/ManiphestStatusEmailCommand.php', 'ManiphestStatusEmailCommand' => 'applications/maniphest/command/ManiphestStatusEmailCommand.php',
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php', 'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
'ManiphestSubtypesConfigOptionsType' => 'applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php',
'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php', 'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php',
'ManiphestTaskAssignHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignHeraldAction.php', 'ManiphestTaskAssignHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignHeraldAction.php',
'ManiphestTaskAssignOtherHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignOtherHeraldAction.php', 'ManiphestTaskAssignOtherHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignOtherHeraldAction.php',
@ -6348,6 +6349,7 @@ phutil_register_library_map(array(
'ManiphestStatusConfigOptionType' => 'PhabricatorConfigJSONOptionType', 'ManiphestStatusConfigOptionType' => 'PhabricatorConfigJSONOptionType',
'ManiphestStatusEmailCommand' => 'ManiphestEmailCommand', 'ManiphestStatusEmailCommand' => 'ManiphestEmailCommand',
'ManiphestSubpriorityController' => 'ManiphestController', 'ManiphestSubpriorityController' => 'ManiphestController',
'ManiphestSubtypesConfigOptionsType' => 'PhabricatorConfigJSONOptionType',
'ManiphestTask' => array( 'ManiphestTask' => array(
'ManiphestDAO', 'ManiphestDAO',
'PhabricatorSubscribableInterface', 'PhabricatorSubscribableInterface',

View file

@ -0,0 +1,10 @@
<?php
final class ManiphestSubtypesConfigOptionsType
extends PhabricatorConfigJSONOptionType {
public function validateOption(PhabricatorConfigOption $option, $value) {
PhabricatorEditEngineSubtype::validateConfiguration($value);
}
}

View file

@ -297,6 +297,50 @@ See the example below for a starting point.
EOTEXT EOTEXT
)); ));
$subtype_type = 'custom:ManiphestSubtypesConfigOptionsType';
$subtype_default_key = PhabricatorEditEngineSubtype::SUBTYPE_DEFAULT;
$subtype_example = array(
array(
'key' => $subtype_default_key,
'name' => pht('Task'),
),
array(
'key' => 'bug',
'name' => pht('Bug'),
),
array(
'key' => 'feature',
'name' => pht('Feature Request'),
),
);
$subtype_example = id(new PhutilJSON())->encodeAsList($subtype_example);
$subtype_default = array(
array(
'key' => $subtype_default_key,
'name' => pht('Task'),
),
);
$subtype_description = $this->deformat(pht(<<<EOTEXT
Allows you to define task subtypes. Subtypes let you hide fields you don't
need to simplify the workflows for editing tasks.
To define subtypes, provide a list of subtypes. Each subtype should be a
dictionary with these keys:
- `key` //Required string.// Internal identifier for the subtype, like
"task", "feature", or "bug".
- `name` //Required string.// Human-readable name for this subtype, like
"Task", "Feature Request" or "Bug Report".
Each subtype must have a unique key, and you must define a subtype with
the key "%s", which is used as a default subtype.
EOTEXT
,
$subtype_default_key));
return array( return array(
$this->newOption('maniphest.custom-field-definitions', 'wild', array()) $this->newOption('maniphest.custom-field-definitions', 'wild', array())
->setSummary(pht('Custom Maniphest fields.')) ->setSummary(pht('Custom Maniphest fields.'))
@ -361,6 +405,10 @@ EOTEXT
->setDescription($points_description) ->setDescription($points_description)
->addExample($points_json_1, pht('Points Config')) ->addExample($points_json_1, pht('Points Config'))
->addExample($points_json_2, pht('Hours Config')), ->addExample($points_json_2, pht('Hours Config')),
$this->newOption('maniphest.subtypes', $subtype_type, $subtype_default)
->setSummary(pht('Define task subtypes.'))
->setDescription($subtype_description)
->addExample($subtype_example, pht('Simple Subtypes')),
); );
} }

View file

@ -32,5 +32,53 @@ final class PhabricatorEditEngineSubtype
} }
} }
public static function validateConfiguration($config) {
if (!is_array($config)) {
throw new Exception(
pht(
'Subtype configuration is invalid: it must be a list of subtype '.
'specifications.'));
}
$map = array();
foreach ($config as $value) {
PhutilTypeSpec::checkMap(
$value,
array(
'key' => 'string',
'name' => 'string',
));
$key = $value['key'];
self::validateSubtypeKey($key);
if (isset($map[$key])) {
throw new Exception(
pht(
'Subtype configuration is invalid: two subtypes use the same '.
'key ("%s"). Each subtype must have a unique key.',
$key));
}
$map[$key] = true;
$name = $value['name'];
if (!strlen($name)) {
throw new Exception(
pht(
'Subtype configuration is invalid: subtype with key "%s" has '.
'no name. Subtypes must have a name.',
$key));
}
}
if (!isset($map[self::SUBTYPE_DEFAULT])) {
throw new Exception(
pht(
'Subtype configuration is invalid: there is no subtype defined '.
'with key "%s". This subtype is required and must be defined.',
self::SUBTYPE_DEFAULT));
}
}
} }