mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +01:00
Improve UI formatting of some configuration values
Summary: This just pretties up some config like `maniphest.custom-field-definitions` which I noticed was kind of hard to read while chasing down other stuff. Test Plan: {F1014940} Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D14679
This commit is contained in:
parent
1fcdcddd5f
commit
eb439cf577
2 changed files with 38 additions and 11 deletions
|
@ -8,12 +8,34 @@ final class PhabricatorConfigJSON extends Phobject {
|
|||
* @return string
|
||||
*/
|
||||
public static function prettyPrintJSON($value) {
|
||||
// Check not only that it's an array, but that it's an "unnatural" array
|
||||
// meaning that the keys aren't 0 -> size_of_array.
|
||||
if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
|
||||
$result = id(new PhutilJSON())->encodeFormatted($value);
|
||||
} else {
|
||||
$result = json_encode($value);
|
||||
// If the value is an array with keys "0, 1, 2, ..." then we want to
|
||||
// show it as a list.
|
||||
// If the value is an array with other keys, we want to show it as an
|
||||
// object.
|
||||
// Otherwise, just use the default encoder.
|
||||
|
||||
$type = null;
|
||||
if (is_array($value)) {
|
||||
$list_keys = range(0, count($value) - 1);
|
||||
$actual_keys = array_keys($value);
|
||||
|
||||
if ($actual_keys === $list_keys) {
|
||||
$type = 'list';
|
||||
} else {
|
||||
$type = 'object';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'list':
|
||||
$result = id(new PhutilJSON())->encodeAsList($value);
|
||||
break;
|
||||
case 'object':
|
||||
$result = id(new PhutilJSON())->encodeFormatted($value);
|
||||
break;
|
||||
default:
|
||||
$result = json_encode($value);
|
||||
break;
|
||||
}
|
||||
|
||||
// For readability, unescape forward slashes. These are normally escaped
|
||||
|
|
|
@ -242,6 +242,15 @@ EOTEXT
|
|||
|
||||
$custom_field_type = 'custom:PhabricatorCustomFieldConfigOptionType';
|
||||
|
||||
$fields_example = array(
|
||||
'mycompany.estimated-hours' => array(
|
||||
'name' => pht('Estimated Hours'),
|
||||
'type' => 'int',
|
||||
'caption' => pht('Estimated number of hours this will take.'),
|
||||
),
|
||||
);
|
||||
$fields_json = id(new PhutilJSON())->encodeFormatted($fields_example);
|
||||
|
||||
return array(
|
||||
$this->newOption('maniphest.custom-field-definitions', 'wild', array())
|
||||
->setSummary(pht('Custom Maniphest fields.'))
|
||||
|
@ -250,11 +259,7 @@ EOTEXT
|
|||
'Array of custom fields for Maniphest tasks. For details on '.
|
||||
'adding custom fields to Maniphest, see "Configuring Custom '.
|
||||
'Fields" in the documentation.'))
|
||||
->addExample(
|
||||
'{"mycompany:estimated-hours": {"name": "Estimated Hours", '.
|
||||
'"type": "int", "caption": "Estimated number of hours this will '.
|
||||
'take."}}',
|
||||
pht('Valid Setting')),
|
||||
->addExample($fields_json, pht('Valid setting')),
|
||||
$this->newOption('maniphest.fields', $custom_field_type, $default_fields)
|
||||
->setCustomData(id(new ManiphestTask())->getCustomFieldBaseClass())
|
||||
->setDescription(pht('Select and reorder task fields.')),
|
||||
|
|
Loading…
Reference in a new issue