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

Show the default value in Config.

Summary:
As mentioned by @epriestley in an inline on D4290, we should show what happens
if the user leaves the box blank.

Test Plan: Went to edit a setting and saw the default below the text box.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, asherkin

Differential Revision: https://secure.phabricator.com/D4293
This commit is contained in:
Ricky Elrod 2012-12-28 11:37:55 -08:00 committed by epriestley
parent a774620042
commit a9aedc64e4
2 changed files with 36 additions and 10 deletions

View file

@ -24,4 +24,20 @@ abstract class PhabricatorConfigController extends PhabricatorController {
return $crumbs; return $crumbs;
} }
/**
* Properly format a JSON value.
*
* @param wild Any value, but should be a raw value, not a string of JSON.
* @return string
*/
public 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)) {
return id(new PhutilJSON())->encodeFormatted($value);
} else {
return json_encode($value);
}
}
} }

View file

@ -19,6 +19,8 @@ final class PhabricatorConfigEditController
return new Aphront404Response(); return new Aphront404Response();
} }
$default = $this->prettyPrintJSON($config[$this->key]);
// Check if the config key is already stored in the database. // Check if the config key is already stored in the database.
// Grab the value if it is. // Grab the value if it is.
$value = null; $value = null;
@ -72,14 +74,7 @@ final class PhabricatorConfigEditController
->setTitle('You broke everything!') ->setTitle('You broke everything!')
->setErrors($errors); ->setErrors($errors);
} else { } else {
// Check not only that it's an array, but that it's an "unnatural" array $value = $this->prettyPrintJSON($value);
// meaning that the keys aren't 0 -> size_of_array.
if (is_array($value) &&
array_keys($value) != range(0, count($value) - 1)) {
$value = id(new PhutilJSON())->encodeFormatted($value);
} else {
$value = json_encode($value);
}
} }
$form $form
@ -91,11 +86,26 @@ final class PhabricatorConfigEditController
->setValue($value) ->setValue($value)
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setCustomClass('PhabricatorMonospaced') ->setCustomClass('PhabricatorMonospaced')
->setName('value')) ->setName('value'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton($config_entry->getURI()) ->addCancelButton($config_entry->getURI())
->setValue(pht('Save Config Entry'))); ->setValue(pht('Save Config Entry')))
->appendChild(
phutil_render_tag(
'p',
array(
'class' => 'aphront-form-input',
),
'If left blank, the setting will return to its default value. '.
'Its default value is:'))
->appendChild(
phutil_render_tag(
'pre',
array(
'class' => 'aphront-form-input',
),
phutil_escape_html($default)));
$title = pht('Edit %s', $this->key); $title = pht('Edit %s', $this->key);
$short = pht('Edit'); $short = pht('Edit');