mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-20 02:38:39 +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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function prettyPrintJSON($value) {
|
public static function prettyPrintJSON($value) {
|
||||||
// Check not only that it's an array, but that it's an "unnatural" array
|
// If the value is an array with keys "0, 1, 2, ..." then we want to
|
||||||
// meaning that the keys aren't 0 -> size_of_array.
|
// show it as a list.
|
||||||
if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
|
// If the value is an array with other keys, we want to show it as an
|
||||||
$result = id(new PhutilJSON())->encodeFormatted($value);
|
// 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 {
|
} 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);
|
$result = json_encode($value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For readability, unescape forward slashes. These are normally escaped
|
// For readability, unescape forward slashes. These are normally escaped
|
||||||
|
|
|
@ -242,6 +242,15 @@ EOTEXT
|
||||||
|
|
||||||
$custom_field_type = 'custom:PhabricatorCustomFieldConfigOptionType';
|
$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(
|
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.'))
|
||||||
|
@ -250,11 +259,7 @@ EOTEXT
|
||||||
'Array of custom fields for Maniphest tasks. For details on '.
|
'Array of custom fields for Maniphest tasks. For details on '.
|
||||||
'adding custom fields to Maniphest, see "Configuring Custom '.
|
'adding custom fields to Maniphest, see "Configuring Custom '.
|
||||||
'Fields" in the documentation.'))
|
'Fields" in the documentation.'))
|
||||||
->addExample(
|
->addExample($fields_json, pht('Valid setting')),
|
||||||
'{"mycompany:estimated-hours": {"name": "Estimated Hours", '.
|
|
||||||
'"type": "int", "caption": "Estimated number of hours this will '.
|
|
||||||
'take."}}',
|
|
||||||
pht('Valid Setting')),
|
|
||||||
$this->newOption('maniphest.fields', $custom_field_type, $default_fields)
|
$this->newOption('maniphest.fields', $custom_field_type, $default_fields)
|
||||||
->setCustomData(id(new ManiphestTask())->getCustomFieldBaseClass())
|
->setCustomData(id(new ManiphestTask())->getCustomFieldBaseClass())
|
||||||
->setDescription(pht('Select and reorder task fields.')),
|
->setDescription(pht('Select and reorder task fields.')),
|
||||||
|
|
Loading…
Add table
Reference in a new issue