fix: [instance:settings] Improved support of select and apply correct UI coloring
parent
ac464e4129
commit
22faffb170
|
@ -51,9 +51,6 @@ class SettingsProviderTable extends AppTable
|
|||
if (isset($settings[$key])) {
|
||||
$settingConf[$key]['value'] = $settings[$key];
|
||||
}
|
||||
if (empty($settingConf[$key]['severity'])) {
|
||||
$settingConf[$key]['severity'] = 'warning';
|
||||
}
|
||||
$settingConf[$key] = $this->evaluateLeaf($settingConf[$key], $settingConf);
|
||||
$settingConf[$key]['setting-path'] = $path;
|
||||
$settingConf[$key]['true-name'] = $key;
|
||||
|
@ -95,7 +92,7 @@ class SettingsProviderTable extends AppTable
|
|||
$notices[$value['severity']][] = $key;
|
||||
}
|
||||
} else {
|
||||
$notices = array_merge($notices, $this->getNoticesFromSettingsConfiguration($value));
|
||||
$notices = array_merge_recursive($notices, $this->getNoticesFromSettingsConfiguration($value));
|
||||
}
|
||||
}
|
||||
return $notices;
|
||||
|
@ -127,29 +124,31 @@ class SettingsProviderTable extends AppTable
|
|||
}
|
||||
}
|
||||
if (!$skipValidation) {
|
||||
if (isset($setting['test'])) {
|
||||
$error = false;
|
||||
$validationResult = false;
|
||||
if (!isset($setting['value'])) {
|
||||
$validationResult = $this->settingValidator->testEmptyBecomesDefault(null, $setting);
|
||||
} else if (isset($setting['test'])) {
|
||||
$setting['value'] = $setting['value'] ?? '';
|
||||
if (is_callable($setting['test'])) { // Validate with anonymous function
|
||||
$error = $setting['test']($setting['value'], $setting, new Validator());
|
||||
$validationResult = $setting['test']($setting['value'], $setting, new Validator());
|
||||
} else if (method_exists($this->settingValidator, $setting['test'])) { // Validate with function defined in settingValidator class
|
||||
$error = $this->settingValidator->{$setting['test']}($setting['value'], $setting);
|
||||
$validationResult = $this->settingValidator->{$setting['test']}($setting['value'], $setting);
|
||||
} else {
|
||||
$validator = new Validator();
|
||||
if (method_exists($validator, $setting['test'])) { // Validate with cake's validator function
|
||||
$validator->{$setting['test']};
|
||||
$error = $validator->validate($setting['value']);
|
||||
$validationResult = $validator->validate($setting['value']);
|
||||
}
|
||||
}
|
||||
if ($error !== true) {
|
||||
$setting['severity'] = $setting['severity'] ?? 'warning';
|
||||
if (!in_array($setting['severity'], $this->severities)) {
|
||||
$setting['severity'] = 'warning';
|
||||
}
|
||||
$setting['errorMessage'] = $error;
|
||||
}
|
||||
$setting['error'] = $error !== false ? true : false;
|
||||
}
|
||||
if ($validationResult !== true) {
|
||||
$setting['severity'] = $setting['severity'] ?? 'warning';
|
||||
if (!in_array($setting['severity'], $this->severities)) {
|
||||
$setting['severity'] = 'warning';
|
||||
}
|
||||
$setting['errorMessage'] = $validationResult;
|
||||
}
|
||||
$setting['error'] = $validationResult !== true ? true : false;
|
||||
}
|
||||
return $setting;
|
||||
}
|
||||
|
@ -176,9 +175,9 @@ class SettingsProviderTable extends AppTable
|
|||
],
|
||||
'app.uuid' => [
|
||||
'description' => __('The Cerebrate instance UUID. This UUID is used to identify this instance.'),
|
||||
'severity' => 'critical',
|
||||
'default' => '',
|
||||
'name' => 'UUID',
|
||||
'severity' => 'critical',
|
||||
'test' => 'testUuid',
|
||||
'type' => 'string'
|
||||
],
|
||||
|
@ -196,19 +195,20 @@ class SettingsProviderTable extends AppTable
|
|||
],
|
||||
'sc2.hero' => [
|
||||
'description' => 'The true hero',
|
||||
'default' => '',
|
||||
'default' => 'Sarah Kerrigan',
|
||||
'name' => 'Hero',
|
||||
'options' => [
|
||||
'Jim Raynor' => 'Jim Raynor',
|
||||
'Sarah Kerrigan' => 'Sarah Kerrigan',
|
||||
'Artanis' => 'Artanis',
|
||||
'Zeratul' => 'Zeratul',
|
||||
],
|
||||
'name' => 'Hero',
|
||||
'type' => 'select'
|
||||
],
|
||||
'sc2.antagonist' => [
|
||||
'description' => 'The real bad guy',
|
||||
'default' => '',
|
||||
'default' => 'Amon',
|
||||
'name' => 'Antagonist',
|
||||
'options' => function($settingsProviders) {
|
||||
return [
|
||||
'Amon' => 'Amon',
|
||||
|
@ -249,7 +249,6 @@ class SettingsProviderTable extends AppTable
|
|||
'description' => __('The authentication username for the HTTP proxy.'),
|
||||
'default' => 'admin',
|
||||
'name' => __('User'),
|
||||
'test' => 'testEmptyBecomesDefault',
|
||||
'dependsOn' => 'proxy.host',
|
||||
'type' => 'string',
|
||||
],
|
||||
|
@ -257,7 +256,6 @@ class SettingsProviderTable extends AppTable
|
|||
'description' => __('The authentication password for the HTTP proxy.'),
|
||||
'default' => '',
|
||||
'name' => __('Password'),
|
||||
'test' => 'testEmptyBecomesDefault',
|
||||
'dependsOn' => 'proxy.host',
|
||||
'type' => 'string',
|
||||
],
|
||||
|
@ -284,7 +282,7 @@ class SettingsProviderTable extends AppTable
|
|||
'description' => __('The debug level of the instance'),
|
||||
'default' => 0,
|
||||
'dependsOn' => 'host',
|
||||
'name' => __('User'),
|
||||
'name' => __('Debug Level'),
|
||||
'test' => function($value, $setting, $validator) {
|
||||
$validator->range('value', [0, 3]);
|
||||
return testValidator($value, $validator);
|
||||
|
@ -319,10 +317,11 @@ class SettingValidator
|
|||
if (!empty($value)) {
|
||||
return true;
|
||||
} else if (!empty($setting['default'])) {
|
||||
$setting['severity'] = 'info';
|
||||
$setting['severity'] = $setting['severity'] ?? 'info';
|
||||
return __('Setting is not set, fallback to default value: {0}', $setting['default']);
|
||||
} else {
|
||||
return __('Cannot be empty');
|
||||
$setting['severity'] = $setting['severity'] ?? 'critical';
|
||||
return __('Cannot be empty. Setting does not have a default value.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -312,7 +312,10 @@ function genInputInteger($settingName, $setting, $appView)
|
|||
$settingId = str_replace('.', '_', $settingName);
|
||||
return $appView->Bootstrap->genNode('input', [
|
||||
'class' => [
|
||||
'form-control'
|
||||
'form-control',
|
||||
(!empty($setting['error']) ? 'is-invalid' : ''),
|
||||
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
|
||||
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
|
||||
],
|
||||
'type' => 'number',
|
||||
'min' => '0',
|
||||
|
@ -343,7 +346,7 @@ function genInputSelect($settingName, $setting, $appView)
|
|||
'pr-4',
|
||||
(!empty($setting['error']) ? 'is-invalid' : ''),
|
||||
(!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',
|
||||
'id' => $settingId,
|
||||
|
@ -543,7 +546,7 @@ function isLeaf($setting)
|
|||
if ($callout.length == 0) {
|
||||
return
|
||||
}
|
||||
const $settings = $callout.find('input')
|
||||
const $settings = $callout.find('input, select')
|
||||
const settingNames = Array.from($settings).map((i) => {
|
||||
return $(i).data('setting-name')
|
||||
})
|
||||
|
|
|
@ -155,6 +155,9 @@ div.progress-timeline .progress-line.progress-inactive {
|
|||
.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);
|
||||
}
|
||||
.custom-select.is-invalid.info {
|
||||
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='%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") #fff no-repeat center right 1.75rem/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
|
||||
}
|
||||
|
||||
.custom-control-input.is-invalid.warning ~ .custom-control-label {
|
||||
color: unset;
|
||||
|
|
Loading…
Reference in New Issue