mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 23:31:03 +01:00
Show all configuration defaults when editing configuration
Summary: Show the value for all loaded configuration sources. Test Plan: {F28469} {F28470} {F28471} Reviewers: btrahan, codeblock Reviewed By: codeblock CC: aran Maniphest Tasks: T2255 Differential Revision: https://secure.phabricator.com/D4312
This commit is contained in:
parent
3852ca632b
commit
21efc7cb64
8 changed files with 150 additions and 40 deletions
|
@ -684,6 +684,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConduitMethodCallLog' => 'applications/conduit/storage/PhabricatorConduitMethodCallLog.php',
|
||||
'PhabricatorConduitTokenController' => 'applications/conduit/controller/PhabricatorConduitTokenController.php',
|
||||
'PhabricatorConfigController' => 'applications/config/controller/PhabricatorConfigController.php',
|
||||
'PhabricatorConfigDefaultSource' => 'infrastructure/env/PhabricatorConfigDefaultSource.php',
|
||||
'PhabricatorConfigDictionarySource' => 'infrastructure/env/PhabricatorConfigDictionarySource.php',
|
||||
'PhabricatorConfigEditController' => 'applications/config/controller/PhabricatorConfigEditController.php',
|
||||
'PhabricatorConfigEntry' => 'applications/config/storage/PhabricatorConfigEntry.php',
|
||||
|
@ -2019,6 +2020,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConduitMethodCallLog' => 'PhabricatorConduitDAO',
|
||||
'PhabricatorConduitTokenController' => 'PhabricatorConduitController',
|
||||
'PhabricatorConfigController' => 'PhabricatorController',
|
||||
'PhabricatorConfigDefaultSource' => 'PhabricatorConfigProxySource',
|
||||
'PhabricatorConfigDictionarySource' => 'PhabricatorConfigSource',
|
||||
'PhabricatorConfigEditController' => 'PhabricatorConfigController',
|
||||
'PhabricatorConfigEntry' => 'PhabricatorConfigEntryDAO',
|
||||
|
|
|
@ -122,30 +122,13 @@ final class PhabricatorConfigEditController
|
|||
->setValue($examples));
|
||||
}
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel(pht('Default'))
|
||||
->setValue($this->renderDefaults($option)));
|
||||
|
||||
// TODO: This isn't quite correct -- we should read from the entire
|
||||
// configuration stack, ignoring database configuration. For now, though,
|
||||
// it's a reasonable approximation.
|
||||
$default = $this->prettyPrintJSON($option->getDefault());
|
||||
$form
|
||||
->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);
|
||||
$short = pht('Edit');
|
||||
$title = pht('Edit %s', $this->key);
|
||||
$short = pht('Edit');
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addCrumb(
|
||||
|
@ -302,18 +285,22 @@ final class PhabricatorConfigEditController
|
|||
}
|
||||
|
||||
$table = array();
|
||||
$table[] = '<tr class="column-labels">';
|
||||
$table[] = '<th>'.pht('Example').'</th>';
|
||||
$table[] = '<th>'.pht('Value').'</th>';
|
||||
$table[] = '</tr>';
|
||||
foreach ($examples as $example) {
|
||||
list($value, $description) = $example;
|
||||
|
||||
if ($value === null) {
|
||||
$value = '<em>(empty)</em>';
|
||||
$value = '<em>'.pht('(empty)').'</em>';
|
||||
} else {
|
||||
$value = phutil_escape_html($value);
|
||||
}
|
||||
|
||||
$table[] = '<tr>';
|
||||
$table[] = '<th>'.$value.'</th>';
|
||||
$table[] = '<td>'.phutil_escape_html($description).'</td>';
|
||||
$table[] = '<th>'.phutil_escape_html($description).'</th>';
|
||||
$table[] = '<td>'.$value.'</td>';
|
||||
$table[] = '</tr>';
|
||||
}
|
||||
|
||||
|
@ -322,7 +309,58 @@ final class PhabricatorConfigEditController
|
|||
return phutil_render_tag(
|
||||
'table',
|
||||
array(
|
||||
'class' => 'config-option-examples',
|
||||
'class' => 'config-option-table',
|
||||
),
|
||||
implode("\n", $table));
|
||||
}
|
||||
|
||||
private function renderDefaults(PhabricatorConfigOption $option) {
|
||||
$stack = PhabricatorEnv::getConfigSourceStack();
|
||||
$stack = $stack->getStack();
|
||||
|
||||
/*
|
||||
|
||||
TODO: Once DatabaseSource lands, do this:
|
||||
|
||||
foreach ($stack as $key => $source) {
|
||||
unset($stack[$key]);
|
||||
if ($source instanceof PhabricatorConfigDatabaseSource) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
$table = array();
|
||||
$table[] = '<tr class="column-labels">';
|
||||
$table[] = '<th>'.pht('Source').'</th>';
|
||||
$table[] = '<th>'.pht('Value').'</th>';
|
||||
$table[] = '</tr>';
|
||||
foreach ($stack as $key => $source) {
|
||||
$value = $source->getKeys(
|
||||
array(
|
||||
$option->getKey(),
|
||||
));
|
||||
|
||||
if (!array_key_exists($option->getKey(), $value)) {
|
||||
$value = '<em>'.pht('(empty)').'</em>';
|
||||
} else {
|
||||
$value = $this->prettyPrintJSON($value[$option->getKey()]);
|
||||
}
|
||||
|
||||
$table[] = '<tr>';
|
||||
$table[] = '<th>'.phutil_escape_html($source->getName()).'</th>';
|
||||
$table[] = '<td>'.$value.'</td>';
|
||||
$table[] = '</tr>';
|
||||
}
|
||||
|
||||
require_celerity_resource('config-options-css');
|
||||
|
||||
return phutil_render_tag(
|
||||
'table',
|
||||
array(
|
||||
'class' => 'config-option-table',
|
||||
),
|
||||
implode("\n", $table));
|
||||
}
|
||||
|
|
16
src/infrastructure/env/PhabricatorConfigDefaultSource.php
vendored
Normal file
16
src/infrastructure/env/PhabricatorConfigDefaultSource.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Configuration source which reads from defaults defined in the authoritative
|
||||
* configuration definitions.
|
||||
*/
|
||||
final class PhabricatorConfigDefaultSource
|
||||
extends PhabricatorConfigProxySource {
|
||||
|
||||
public function __construct() {
|
||||
$options = PhabricatorApplicationConfigOptions::loadAllOptions();
|
||||
$options = mpull($options, 'getDefault');
|
||||
$this->setSource(new PhabricatorConfigDictionarySource($options));
|
||||
}
|
||||
|
||||
}
|
|
@ -33,11 +33,22 @@ abstract class PhabricatorConfigProxySource
|
|||
}
|
||||
|
||||
public function setKeys(array $keys) {
|
||||
return $this->getSource()->setKeys($keys);
|
||||
$this->getSource()->setKeys($keys);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function deleteKeys(array $keys) {
|
||||
return $this->getSource()->deleteKeys();
|
||||
$this->getSource()->deleteKeys();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->getSource()->setName($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->getSource()->getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
abstract class PhabricatorConfigSource {
|
||||
|
||||
private $name;
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
abstract public function getKeys(array $keys);
|
||||
abstract public function getAllKeys();
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ final class PhabricatorConfigStackSource
|
|||
return array_shift($this->stack);
|
||||
}
|
||||
|
||||
public function getStack() {
|
||||
return $this->stack;
|
||||
}
|
||||
|
||||
public function getKeys(array $keys) {
|
||||
$result = array();
|
||||
foreach ($this->stack as $source) {
|
||||
|
|
24
src/infrastructure/env/PhabricatorEnv.php
vendored
24
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -96,8 +96,7 @@ final class PhabricatorEnv {
|
|||
private static function initializeCommonEnvironment() {
|
||||
$env = self::getSelectedEnvironmentName();
|
||||
|
||||
self::$sourceStack = new PhabricatorConfigStackSource();
|
||||
self::$sourceStack->pushSource(new PhabricatorConfigFileSource($env));
|
||||
self::buildConfigurationSourceStack();
|
||||
|
||||
PhutilErrorHandler::initialize();
|
||||
|
||||
|
@ -126,6 +125,24 @@ final class PhabricatorEnv {
|
|||
->addTranslations($translation->getTranslations());
|
||||
}
|
||||
|
||||
private static function buildConfigurationSourceStack() {
|
||||
$stack = new PhabricatorConfigStackSource();
|
||||
self::$sourceStack = $stack;
|
||||
|
||||
$stack->pushSource(
|
||||
id(new PhabricatorConfigDefaultSource())
|
||||
->setName(pht('Global Default')));
|
||||
|
||||
$env = self::getSelectedEnvironmentName();
|
||||
$stack->pushSource(
|
||||
id(new PhabricatorConfigFileSource($env))
|
||||
->setName(pht("File '%s'", $env)));
|
||||
|
||||
$stack->pushSource(
|
||||
id(new PhabricatorConfigLocalSource())
|
||||
->setName(pht("Local Config")));
|
||||
}
|
||||
|
||||
public static function getSelectedEnvironmentName() {
|
||||
$env_var = 'PHABRICATOR_ENV';
|
||||
|
||||
|
@ -398,6 +415,9 @@ final class PhabricatorEnv {
|
|||
return self::$sourceStack->getAllKeys();
|
||||
}
|
||||
|
||||
public static function getConfigSourceStack() {
|
||||
return self::$sourceStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @task internal
|
||||
|
|
|
@ -2,31 +2,39 @@
|
|||
* @provides config-options-css
|
||||
*/
|
||||
|
||||
.config-option-examples {
|
||||
.config-option-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #cccccc;
|
||||
}
|
||||
|
||||
.config-option-examples th,
|
||||
.config-option-examples td {
|
||||
padding: 4px 6px;
|
||||
.config-option-table th,
|
||||
.config-option-table td {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #cccccc;
|
||||
}
|
||||
|
||||
.config-option-examples th {
|
||||
background: #dfdfdf;
|
||||
.config-option-table th {
|
||||
background: #e9e9e9;
|
||||
text-align: right;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.config-option-examples th em {
|
||||
.config-option-table th em {
|
||||
font-weight: normal;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.config-option-examples td {
|
||||
.config-option-table td {
|
||||
color: #333333;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.config-option-table .column-labels th {
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
text-align: center;
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue