chg: [instance:settings] UI improvements

pull/70/head
mokaddem 2021-07-23 10:32:00 +02:00
parent 99e3576221
commit ac464e4129
3 changed files with 41 additions and 36 deletions

View File

@ -131,7 +131,7 @@ class SettingsProviderTable extends AppTable
$error = false; $error = false;
$setting['value'] = $setting['value'] ?? ''; $setting['value'] = $setting['value'] ?? '';
if (is_callable($setting['test'])) { // Validate with anonymous function if (is_callable($setting['test'])) { // Validate with anonymous function
$error = $setting['test']($setting['value'], $setting); $error = $setting['test']($setting['value'], $setting, new Validator());
} else if (method_exists($this->settingValidator, $setting['test'])) { // Validate with function defined in settingValidator class } else if (method_exists($this->settingValidator, $setting['test'])) { // Validate with function defined in settingValidator class
$error = $this->settingValidator->{$setting['test']}($setting['value'], $setting); $error = $this->settingValidator->{$setting['test']}($setting['value'], $setting);
} else { } else {
@ -223,8 +223,9 @@ class SettingsProviderTable extends AppTable
'floating-setting' => [ 'floating-setting' => [
'description' => 'floaringSetting', 'description' => 'floaringSetting',
'errorMessage' => 'floaringSetting', 'errorMessage' => 'floaringSetting',
'default' => '', 'default' => 'A default value',
'name' => 'Uncategorized Setting', 'name' => 'Uncategorized Setting',
'test' => 'testEmptyBecomesDefault',
'type' => 'string' 'type' => 'string'
], ],
], ],
@ -277,37 +278,23 @@ class SettingsProviderTable extends AppTable
], ],
], ],
'Security' => [ 'Security' => [
'Network' => [ 'Development' => [
'Proxy Test' => [ 'Debugging' => [
'proxy-test.host' => [ 'Debug' => [
'description' => __('The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.'), 'description' => __('The debug level of the instance'),
'default' => '', 'default' => 0,
'name' => __('Host'),
'test' => 'testHostname',
'type' => 'string',
],
'proxy-test.port' => [
'description' => __('The TCP port for the HTTP proxy.'),
'default' => '',
'name' => __('Port'),
'test' => 'testForRangeXY',
'type' => 'integer',
],
'proxy-test.user' => [
'description' => __('The authentication username for the HTTP proxy.'),
'default' => '',
'dependsOn' => 'host', 'dependsOn' => 'host',
'name' => __('User'), 'name' => __('User'),
'test' => 'testEmptyBecomesDefault', 'test' => function($value, $setting, $validator) {
'type' => 'string', $validator->range('value', [0, 3]);
], return testValidator($value, $validator);
'proxy-test.password' => [ },
'description' => __('The authentication password for the HTTP proxy.'), 'type' => 'select',
'default' => '', 'options' => [
'dependsOn' => 'host', 0 => __('Debug Off'),
'name' => __('Password'), 1 => __('Debug On'),
'test' => 'testEmptyBecomesDefault', 2 => __('Debug On + SQL Dump'),
'type' => 'string', ]
], ],
], ],
] ]
@ -318,26 +305,33 @@ class SettingsProviderTable extends AppTable
} }
} }
function testValidator($value, $validator)
{
$errors = $validator->validate(['value' => $value]);
return !empty($errors) ? implode(', ', $errors['value']) : true;
}
class SettingValidator class SettingValidator
{ {
public function testEmptyBecomesDefault($value, $setting) public function testEmptyBecomesDefault($value, &$setting)
{ {
if (!empty($value)) { if (!empty($value)) {
return true; return true;
} else if (!empty($setting['default'])) { } else if (!empty($setting['default'])) {
$setting['severity'] = 'info';
return __('Setting is not set, fallback to default value: {0}', $setting['default']); return __('Setting is not set, fallback to default value: {0}', $setting['default']);
} else { } else {
return __('Cannot be empty'); return __('Cannot be empty');
} }
} }
public function testForEmpty($value, $setting) public function testForEmpty($value, &$setting)
{ {
return !empty($value) ? true : __('Cannot be empty'); return !empty($value) ? true : __('Cannot be empty');
} }
public function testBaseURL($value, $setting) public function testBaseURL($value, &$setting)
{ {
if (empty($value)) { if (empty($value)) {
return __('Cannot be empty'); return __('Cannot be empty');
@ -348,7 +342,7 @@ class SettingValidator
return true; return true;
} }
public function testUuid($value, $setting) { public function testUuid($value, &$setting) {
if (empty($value) || !preg_match('/^\{?[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}\}?$/', $value)) { if (empty($value) || !preg_match('/^\{?[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}\}?$/', $value)) {
return __('Invalid UUID.'); return __('Invalid UUID.');
} }

View File

@ -268,7 +268,7 @@ function genInputString($settingName, $setting, $appView)
'pr-4', 'pr-4',
(!empty($setting['error']) ? 'is-invalid' : ''), (!empty($setting['error']) ? 'is-invalid' : ''),
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''), (!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
(!empty($setting['error']) && $setting['severity'] == 'warning' ? 'warning' : ''), (!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
], ],
'type' => 'text', 'type' => 'text',
'id' => $settingId, 'id' => $settingId,

View File

@ -141,6 +141,17 @@ div.progress-timeline .progress-line.progress-inactive {
.form-control.is-invalid.warning { .form-control.is-invalid.warning {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23ffc107' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ffc107' stroke='none'/%3e%3c/svg%3e") background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23ffc107' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ffc107' stroke='none'/%3e%3c/svg%3e")
} }
.form-control.is-invalid.warning:focus {
box-shadow: 0 0 0 0.2rem #ffc10740;
}
.form-control.is-invalid.info {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2317a2b8' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%2317a2b8' stroke='none'/%3e%3c/svg%3e")
}
.form-control.is-invalid.info:focus {
box-shadow: 0 0 0 0.2rem #17a2b840;
}
.custom-select.is-invalid.warning { .custom-select.is-invalid.warning {
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") no-repeat right 0.75rem center/8px 10px, url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23ffc107' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ffc107' stroke='none'/%3e%3c/svg%3e") #fff no-repeat center right 1.75rem/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem); background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") no-repeat right 0.75rem center/8px 10px, url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23ffc107' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ffc107' stroke='none'/%3e%3c/svg%3e") #fff no-repeat center right 1.75rem/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
} }