mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Render default/current settings in the same format they'll be edited
Summary: Fixes T4773. For config settings of type `list<string>`, `set`, or `list<regex>`, the "defaults" table and "examples" aren't always in the same format you should actually use when changing the setting. This is pretty confusing. Instead, always show the settings in the desired format. For example, if the user should enter a newline-separated list, show them a newline separated list. Test Plan: - Grepped for `list<string>`, `list<regex>`, and `'set'`; verified all the config had the right example format (most already did). - Viewed config settings of various kinds, including custom settings. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4773 Differential Revision: https://secure.phabricator.com/D8725
This commit is contained in:
parent
d5ded805b2
commit
f79320e64e
6 changed files with 36 additions and 30 deletions
|
@ -94,7 +94,14 @@ final class PhabricatorConfigEditController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$display_value = $this->getDisplayValue($option, $config_entry);
|
if ($config_entry->getIsDeleted()) {
|
||||||
|
$display_value = null;
|
||||||
|
} else {
|
||||||
|
$display_value = $this->getDisplayValue(
|
||||||
|
$option,
|
||||||
|
$config_entry,
|
||||||
|
$config_entry->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
|
@ -186,7 +193,7 @@ final class PhabricatorConfigEditController
|
||||||
$form->appendChild(
|
$form->appendChild(
|
||||||
id(new AphrontFormMarkupControl())
|
id(new AphrontFormMarkupControl())
|
||||||
->setLabel(pht('Default'))
|
->setLabel(pht('Default'))
|
||||||
->setValue($this->renderDefaults($option)));
|
->setValue($this->renderDefaults($option, $config_entry)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = pht('Edit %s', $this->key);
|
$title = pht('Edit %s', $this->key);
|
||||||
|
@ -348,17 +355,16 @@ final class PhabricatorConfigEditController
|
||||||
|
|
||||||
private function getDisplayValue(
|
private function getDisplayValue(
|
||||||
PhabricatorConfigOption $option,
|
PhabricatorConfigOption $option,
|
||||||
PhabricatorConfigEntry $entry) {
|
PhabricatorConfigEntry $entry,
|
||||||
|
$value) {
|
||||||
if ($entry->getIsDeleted()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($option->isCustomType()) {
|
if ($option->isCustomType()) {
|
||||||
return $option->getCustomObject()->getDisplayValue($option, $entry);
|
return $option->getCustomObject()->getDisplayValue(
|
||||||
|
$option,
|
||||||
|
$entry,
|
||||||
|
$value);
|
||||||
} else {
|
} else {
|
||||||
$type = $option->getType();
|
$type = $option->getType();
|
||||||
$value = $entry->getValue();
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'int':
|
case 'int':
|
||||||
case 'string':
|
case 'string':
|
||||||
|
@ -497,7 +503,10 @@ final class PhabricatorConfigEditController
|
||||||
$table);
|
$table);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderDefaults(PhabricatorConfigOption $option) {
|
private function renderDefaults(
|
||||||
|
PhabricatorConfigOption $option,
|
||||||
|
PhabricatorConfigEntry $entry) {
|
||||||
|
|
||||||
$stack = PhabricatorEnv::getConfigSourceStack();
|
$stack = PhabricatorEnv::getConfigSourceStack();
|
||||||
$stack = $stack->getStack();
|
$stack = $stack->getStack();
|
||||||
|
|
||||||
|
@ -515,7 +524,9 @@ final class PhabricatorConfigEditController
|
||||||
if (!array_key_exists($option->getKey(), $value)) {
|
if (!array_key_exists($option->getKey(), $value)) {
|
||||||
$value = phutil_tag('em', array(), pht('(empty)'));
|
$value = phutil_tag('em', array(), pht('(empty)'));
|
||||||
} else {
|
} else {
|
||||||
$value = PhabricatorConfigJSON::prettyPrintJSON(
|
$value = $this->getDisplayValue(
|
||||||
|
$option,
|
||||||
|
$entry,
|
||||||
$value[$option->getKey()]);
|
$value[$option->getKey()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,18 +34,6 @@ abstract class PhabricatorConfigJSONOptionType
|
||||||
return array($e_value, $errors, $storage_value, $display_value);
|
return array($e_value, $errors, $storage_value, $display_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDisplayValue(
|
|
||||||
PhabricatorConfigOption $option,
|
|
||||||
PhabricatorConfigEntry $entry) {
|
|
||||||
$value = $entry->getValue();
|
|
||||||
if (!$value) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$json = new PhutilJSON();
|
|
||||||
return $json->encodeFormatted($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderControl(
|
public function renderControl(
|
||||||
PhabricatorConfigOption $option,
|
PhabricatorConfigOption $option,
|
||||||
$display_value,
|
$display_value,
|
||||||
|
|
|
@ -20,8 +20,16 @@ abstract class PhabricatorConfigOptionType {
|
||||||
|
|
||||||
public function getDisplayValue(
|
public function getDisplayValue(
|
||||||
PhabricatorConfigOption $option,
|
PhabricatorConfigOption $option,
|
||||||
PhabricatorConfigEntry $entry) {
|
PhabricatorConfigEntry $entry,
|
||||||
return $entry->getValue();
|
$value) {
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
$json = new PhutilJSON();
|
||||||
|
return $json->encodeFormatted($value);
|
||||||
|
} else {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderControl(
|
public function renderControl(
|
||||||
|
|
|
@ -59,8 +59,8 @@ final class PhabricatorCoreConfigOptions
|
||||||
"won't work. The major use case for this is moving installs ".
|
"won't work. The major use case for this is moving installs ".
|
||||||
"across domains."))
|
"across domains."))
|
||||||
->addExample(
|
->addExample(
|
||||||
'["http://phabricator2.example.com/", '.
|
"http://phabricator2.example.com/\n".
|
||||||
'"http://phabricator3.example.com/"]',
|
"http://phabricator3.example.com/",
|
||||||
pht('Valid Setting')),
|
pht('Valid Setting')),
|
||||||
$this->newOption('phabricator.timezone', 'string', null)
|
$this->newOption('phabricator.timezone', 'string', null)
|
||||||
->setSummary(
|
->setSummary(
|
||||||
|
|
|
@ -124,8 +124,7 @@ final class PhabricatorSecurityConfigOptions
|
||||||
"automatically linked if the protocol appears in this set. This ".
|
"automatically linked if the protocol appears in this set. This ".
|
||||||
"whitelist is primarily to prevent security issues like ".
|
"whitelist is primarily to prevent security issues like ".
|
||||||
"javascript:// URIs."))
|
"javascript:// URIs."))
|
||||||
->addExample(
|
->addExample("http\nhttps", pht('Valid Setting'))
|
||||||
'{"http": true, "https": true"}', pht('Valid Setting'))
|
|
||||||
->setLocked(true),
|
->setLocked(true),
|
||||||
$this->newOption(
|
$this->newOption(
|
||||||
'uri.allowed-editor-protocols',
|
'uri.allowed-editor-protocols',
|
||||||
|
|
|
@ -196,7 +196,7 @@ final class CelerityManagementMapWorkflow
|
||||||
*
|
*
|
||||||
* @param string Resource name.
|
* @param string Resource name.
|
||||||
* @param string Resource data.
|
* @param string Resource data.
|
||||||
* @return pair<string|null, list<string>|nul> The `@provides` symbol and the
|
* @return pair<string|null, list<string>|null> The `@provides` symbol and the
|
||||||
* list of `@requires` symbols. If the resource is not part of the
|
* list of `@requires` symbols. If the resource is not part of the
|
||||||
* dependency graph, both are null.
|
* dependency graph, both are null.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue