chg: [settings] Possibility to add icons and description in setting panels

pull/72/head
mokaddem 2021-09-03 10:48:18 +02:00
parent 9662e15afe
commit feeda3b32b
3 changed files with 73 additions and 3 deletions

View File

@ -51,6 +51,8 @@ class SettingsProviderTable extends AppTable
'Application' => [
'General' => [
'Essentials' => [
'_description' => __('Ensentials settings required for the application to run normally.'),
'_icon' => 'user-cog',
'app.baseurl' => [
'name' => __('Base URL'),
'type' => 'string',
@ -200,6 +202,9 @@ class SettingsProviderTable extends AppTable
private function mergeSettingsIntoSettingConfiguration(array $settingConf, array $settings, string $path=''): array
{
foreach ($settingConf as $key => $value) {
if ($this->isSettingMetaKey($key)) {
continue;
}
if ($this->isLeaf($value)) {
if (isset($settings[$key])) {
$settingConf[$key]['value'] = $settings[$key];
@ -218,6 +223,9 @@ class SettingsProviderTable extends AppTable
public function flattenSettingsConfiguration(array $settingsProvider, $flattenedSettings=[]): array
{
foreach ($settingsProvider as $key => $value) {
if ($this->isSettingMetaKey($key)) {
continue;
}
if ($this->isLeaf($value)) {
$flattenedSettings[$key] = $value;
} else {
@ -237,6 +245,9 @@ class SettingsProviderTable extends AppTable
{
$notices = [];
foreach ($settingsProvider as $key => $value) {
if ($this->isSettingMetaKey($key)) {
continue;
}
if ($this->isLeaf($value)) {
if (!empty($value['error'])) {
if (empty($notices[$value['severity']])) {
@ -320,6 +331,11 @@ class SettingsProviderTable extends AppTable
}
return $functionResult;
}
function isSettingMetaKey($key)
{
return substr($key, 0, 1) == '_';
}
}
function testValidator($value, $validator)

View File

@ -75,6 +75,12 @@ class BootstrapHelper extends Helper
return $bsButton->button();
}
public function icon($icon, $options=[])
{
$bsIcon = new BoostrapIcon($icon, $options);
return $bsIcon->icon();
}
public function badge($options)
{
$bsBadge = new BoostrapBadge($options);
@ -733,9 +739,10 @@ class BoostrapButton extends BootstrapGeneric {
private function genIcon()
{
return $this->genNode('span', [
'class' => ['mr-1', "fa fa-{$this->options['icon']}"],
$bsIcon = new BoostrapIcon($this->options['icon'], [
'class' => ['mr-1']
]);
return $bsIcon->icon();
}
private function genContent()
@ -784,6 +791,40 @@ class BoostrapBadge extends BootstrapGeneric {
}
}
class BoostrapIcon extends BootstrapGeneric {
private $icon = '';
private $defaultOptions = [
'class' => [],
];
function __construct($icon, $options=[]) {
$this->icon = $icon;
$this->processOptions($options);
}
private function processOptions($options)
{
$this->options = array_merge($this->defaultOptions, $options);
$this->checkOptionValidity();
}
public function icon()
{
return $this->genIcon();
}
private function genIcon()
{
$html = $this->genNode('span', [
'class' => array_merge(
is_array($this->options['class']) ? $this->options['class'] : [$this->options['class']],
["fa fa-{$this->icon}"]
),
]);
return $html;
}
}
class BoostrapModal extends BootstrapGeneric {
private $defaultOptions = [
'size' => '',

View File

@ -10,9 +10,22 @@ if (isLeaf($panelSettings)) {
$panelHTML = "<div>{$singleSetting}</div>";
} else {
$panelID = getResolvableID($sectionName, $panelName);
$panelHTML .= sprintf('<h4 id="%s"><a class="text-reset text-decoration-none" href="#%s">%s</a></h4>', $panelID, $panelID, h($panelName));
$panelHTML .= sprintf('<h4 id="%s"><a class="text-reset text-decoration-none" href="#%s">%s%s</a></h4>',
$panelID,
$panelID,
!empty($panelSettings['_icon']) ? $this->Bootstrap->icon($panelSettings['_icon'], ['class' => 'mr-1']) : '',
h($panelName)
);
if (!empty($panelSettings['_description'])) {
$panelHTML .= $this->Bootstrap->genNode('div', [
'class' => ['mb-1',],
], h($panelSettings['_description']));
}
$groupIssueSeverity = false;
foreach ($panelSettings as $singleSettingName => $singleSetting) {
if (substr($singleSettingName, 0, 1) == '_') {
continue;
}
$singleSettingHTML = $this->element('Settings/fieldGroup', [
'panelName' => $panelName,
'panelSettings' => $panelSettings,