2021-07-19 15:00:09 +02:00
|
|
|
<?php
|
|
|
|
// debug($settings);
|
|
|
|
// debug($settingsProvider);
|
2021-07-20 11:54:55 +02:00
|
|
|
// debug($notices);
|
|
|
|
$mainNoticeHeading = [
|
|
|
|
'critical' => __('Your Cerebrate instance requires immediate attention.'),
|
|
|
|
'warning' => __('Issues found, it is recommended that you resolve them.'),
|
|
|
|
'info' => __('There are some optional settings that are incorrect or not set.'),
|
|
|
|
];
|
|
|
|
$noticeDescriptionPerLevel = [
|
|
|
|
'critical' => __('Cerebrate will not operate correctly or will be unsecure until these issues are resolved.'),
|
|
|
|
'warning' => __('Some of the features of Cerebrate cannot be utilised until these issues are resolved.'),
|
|
|
|
'info' => __('There are some optional tweaks that could be done to improve the looks of your Cerebrate instance.'),
|
|
|
|
];
|
|
|
|
$headingPerLevel = [
|
|
|
|
'critical' => __('Critical settings'),
|
|
|
|
'warning' => __('Warning settings'),
|
|
|
|
'info' => __('Info settings'),
|
|
|
|
];
|
2021-07-21 11:18:06 +02:00
|
|
|
$variantFromSeverity = [
|
|
|
|
'critical' => 'danger',
|
|
|
|
'warning' => 'warning',
|
|
|
|
'info' => 'info',
|
|
|
|
];
|
|
|
|
$this->set('variantFromSeverity', $variantFromSeverity);
|
2021-07-20 11:54:55 +02:00
|
|
|
|
|
|
|
$alertVariant = 'info';
|
|
|
|
$alertBody = '';
|
|
|
|
$skipHeading = false;
|
|
|
|
$tableItems = [];
|
|
|
|
foreach (array_keys($mainNoticeHeading) as $level) {
|
|
|
|
if(!empty($notices[$level])) {
|
2021-07-21 11:18:06 +02:00
|
|
|
$variant = $variantFromSeverity[$level];
|
2021-07-20 11:54:55 +02:00
|
|
|
if (!$skipHeading) {
|
|
|
|
$alertBody .= sprintf('<h5 class="alert-heading">%s</h5>', $mainNoticeHeading[$level]);
|
|
|
|
$alertVariant = $variant;
|
|
|
|
$skipHeading = true;
|
|
|
|
}
|
|
|
|
$tableItems[] = [
|
|
|
|
'severity' => $headingPerLevel[$level],
|
|
|
|
'issues' => count($notices[$level]),
|
|
|
|
'badge-variant' => $variant,
|
|
|
|
'description' => $noticeDescriptionPerLevel[$level],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$alertBody .= $this->Bootstrap->table([
|
|
|
|
'small' => true,
|
|
|
|
'striped' => false,
|
|
|
|
'hover' => false,
|
|
|
|
'borderless' => true,
|
|
|
|
'bordered' => false,
|
|
|
|
'tableClass' => 'mb-0'
|
|
|
|
], [
|
|
|
|
'fields' => [
|
|
|
|
['key' => 'severity', 'label' => __('Severity')],
|
|
|
|
['key' => 'issues', 'label' => __('Issues'), 'formatter' => function($count, $row) {
|
|
|
|
return $this->Bootstrap->badge([
|
|
|
|
'variant' => $row['badge-variant'],
|
|
|
|
'text' => $count
|
|
|
|
]);
|
|
|
|
}],
|
|
|
|
['key' => 'description', 'label' => __('Description')]
|
|
|
|
],
|
|
|
|
'items' => $tableItems,
|
|
|
|
]);
|
|
|
|
$settingNotice = $this->Bootstrap->alert([
|
2021-07-21 11:18:06 +02:00
|
|
|
'dismissible' => false,
|
2021-07-20 11:54:55 +02:00
|
|
|
'variant' => $alertVariant,
|
|
|
|
'html' => $alertBody
|
|
|
|
]);
|
2021-07-21 11:18:06 +02:00
|
|
|
$settingNotice = sprintf('<div class="mt-3">%s</div>', $settingNotice);
|
|
|
|
$this->set('settingNotice', $settingNotice);
|
|
|
|
$settingTable = genLevel0($settingsProvider, $this);
|
2021-07-19 15:00:09 +02:00
|
|
|
?>
|
|
|
|
<div class="px-5">
|
|
|
|
<div class="mb-3">
|
2021-07-21 11:18:06 +02:00
|
|
|
<select id="search-settings" class="d-block w-100" aria-describedby="<?= __('Search setting input') ?>"><option></option></select>
|
2021-07-19 15:00:09 +02:00
|
|
|
</div>
|
|
|
|
<?= $settingTable; ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
function genLevel0($settingsProvider, $appView)
|
|
|
|
{
|
|
|
|
$content0 = [];
|
|
|
|
$level0 = array_keys($settingsProvider);
|
|
|
|
foreach ($settingsProvider as $level1Name => $level1Setting) {
|
|
|
|
if (!empty($level1Setting)) {
|
|
|
|
$content0[] = genLevel1($level1Setting, $appView);
|
|
|
|
} else {
|
|
|
|
$content0[] = __('No Settings available yet');
|
|
|
|
}
|
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
array_unshift($level0, __('Settings Diagnostic'));
|
2021-07-21 11:18:06 +02:00
|
|
|
array_unshift($content0, $appView->get('settingNotice'));
|
2021-07-19 15:00:09 +02:00
|
|
|
$tabsOptions0 = [
|
|
|
|
// 'vertical' => true,
|
|
|
|
// 'vertical-size' => 2,
|
|
|
|
'card' => false,
|
|
|
|
'pills' => false,
|
|
|
|
'justify' => 'center',
|
2021-07-21 11:18:06 +02:00
|
|
|
'nav-class' => ['settings-tabs'],
|
2021-07-19 15:00:09 +02:00
|
|
|
'data' => [
|
|
|
|
'navs' => $level0,
|
|
|
|
'content' => $content0
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$table0 = $appView->Bootstrap->tabs($tabsOptions0);
|
|
|
|
return $table0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function genLevel1($level1Setting, $appView)
|
|
|
|
{
|
|
|
|
$content1 = [];
|
|
|
|
$nav1 = [];
|
|
|
|
foreach ($level1Setting as $level2Name => $level2Setting) {
|
|
|
|
if (!empty($level2Setting)) {
|
|
|
|
$content1[] = genLevel2($level2Name, $level2Setting, $appView);
|
|
|
|
} else {
|
|
|
|
$content1[] = '';
|
|
|
|
}
|
|
|
|
$nav1[$level2Name] = array_filter( // only show grouped settings
|
|
|
|
array_keys($level2Setting),
|
|
|
|
function ($settingGroupName) use ($level2Setting) {
|
|
|
|
return !isLeaf($level2Setting[$settingGroupName]);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$contentHtml = implode('', $content1);
|
|
|
|
$scrollspyNav = genScrollspyNav($nav1);
|
|
|
|
$mainPanelHeight = 'calc(100vh - 8px - 42px - 1rem - 56px - 38px - 1rem)';
|
|
|
|
$container = '<div class="d-flex">';
|
|
|
|
$container .= "<div class=\"\" style=\"flex: 0 0 10em;\">{$scrollspyNav}</div>";
|
2021-07-21 11:18:06 +02:00
|
|
|
$container .= "<div data-spy=\"scroll\" data-target=\"#navbar-scrollspy-setting\" data-offset=\"25\" style=\"height: {$mainPanelHeight}\" class=\"p-3 overflow-auto position-relative flex-grow-1\">{$contentHtml}</div>";
|
2021-07-19 15:00:09 +02:00
|
|
|
$container .= '</div>';
|
|
|
|
return $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
function genLevel2($level2Name, $level2Setting, $appView)
|
|
|
|
{
|
|
|
|
foreach ($level2Setting as $level3Name => $level3Setting) {
|
|
|
|
if (!empty($level3Setting)) {
|
|
|
|
$level3 = genLevel3($level2Name, $level3Name, $level3Setting, $appView);
|
|
|
|
$content2[] = sprintf('<div id="%s">%s</div>', sprintf('sp-%s', h($level2Name)), $level3);
|
|
|
|
} else {
|
|
|
|
$content2[] = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return implode('', $content2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function genLevel3($level2Name, $settingGroupName, $setting, $appView)
|
|
|
|
{
|
|
|
|
$settingGroup = '';
|
|
|
|
if (isLeaf($setting)) {
|
|
|
|
$tmp = genSingleSetting($settingGroupName, $setting, $appView);
|
|
|
|
$settingGroup = "<div>{$tmp}</div>";
|
|
|
|
} else {
|
|
|
|
$tmpID = sprintf('sp-%s-%s', h($level2Name), h($settingGroupName));
|
|
|
|
$settingGroup .= sprintf('<h4 id="%s"><a class="text-reset text-decoration-none" href="#%s">%s</a></h4>', $tmpID, $tmpID, h($settingGroupName));
|
2021-07-21 11:18:06 +02:00
|
|
|
$groupIssueSeverity = false;
|
2021-07-19 15:00:09 +02:00
|
|
|
foreach ($setting as $singleSettingName => $singleSetting) {
|
|
|
|
$tmp = genSingleSetting($singleSettingName, $singleSetting, $appView);
|
|
|
|
$settingGroup .= sprintf('<div class="ml-3">%s</div>', $tmp);
|
2021-07-21 11:18:06 +02:00
|
|
|
if (!empty($singleSetting['error'])) {
|
|
|
|
$settingVariant = $appView->get('variantFromSeverity')[$singleSetting['severity']];
|
|
|
|
if ($groupIssueSeverity != 'danger') {
|
|
|
|
if ($groupIssueSeverity != 'warning') {
|
|
|
|
$groupIssueSeverity = $settingVariant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
}
|
|
|
|
$settingGroup = $appView->Bootstrap->genNode('div', [
|
2021-07-21 11:18:06 +02:00
|
|
|
'class' => [
|
|
|
|
'shadow',
|
|
|
|
'p-2',
|
|
|
|
'mb-4',
|
|
|
|
'rounded',
|
2021-07-21 16:07:30 +02:00
|
|
|
'settings-group',
|
2021-07-21 11:18:06 +02:00
|
|
|
(!empty($groupIssueSeverity) ? "callout callout-${groupIssueSeverity}" : ''),
|
|
|
|
($appView->get('darkMode') ? 'bg-dark' : 'bg-light')
|
|
|
|
],
|
2021-07-19 15:00:09 +02:00
|
|
|
], $settingGroup);
|
|
|
|
}
|
|
|
|
return $settingGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
function genSingleSetting($settingName, $setting, $appView)
|
|
|
|
{
|
2021-07-20 11:54:55 +02:00
|
|
|
$dependsOnHtml = '';
|
|
|
|
if (!empty($setting['dependsOn'])) {
|
|
|
|
$dependsOnHtml = $appView->Bootstrap->genNode('span', [
|
|
|
|
], $appView->Bootstrap->genNode('sup', [
|
|
|
|
'class' => [
|
|
|
|
$appView->FontAwesome->getClass('info'),
|
|
|
|
'ml-1',
|
|
|
|
],
|
|
|
|
'title' => __('This setting depends on the validity of: {0}', h($setting['dependsOn']))
|
|
|
|
]));
|
|
|
|
}
|
2021-07-21 11:18:06 +02:00
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-07-19 15:00:09 +02:00
|
|
|
$label = $appView->Bootstrap->genNode('label', [
|
|
|
|
'class' => ['font-weight-bolder', 'mb-0'],
|
2021-07-21 11:18:06 +02:00
|
|
|
'for' => $settingId
|
2021-07-20 11:54:55 +02:00
|
|
|
], h($setting['name']) . $dependsOnHtml);
|
2021-07-19 15:00:09 +02:00
|
|
|
$description = '';
|
|
|
|
if (!empty($setting['description'])) {
|
|
|
|
$description = $appView->Bootstrap->genNode('small', [
|
|
|
|
'class' => ['form-text', 'text-muted', 'mt-0'],
|
2021-07-21 11:18:06 +02:00
|
|
|
'id' => "{$settingId}Help"
|
2021-07-19 15:00:09 +02:00
|
|
|
], h($setting['description']));
|
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
$textColor = 'text-warning';
|
|
|
|
if (!empty($setting['severity'])) {
|
2021-07-21 11:18:06 +02:00
|
|
|
$textColor = "text-{$appView->get('variantFromSeverity')[$setting['severity']]}";
|
2021-07-20 11:54:55 +02:00
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
$error = $appView->Bootstrap->genNode('div', [
|
|
|
|
'class' => ['d-block', 'invalid-feedback', $textColor],
|
|
|
|
], (!empty($setting['error']) ? h($setting['errorMessage']) : ''));
|
2021-07-19 15:00:09 +02:00
|
|
|
if (empty($setting['type'])) {
|
|
|
|
$setting['type'] = 'string';
|
|
|
|
}
|
|
|
|
if ($setting['type'] == 'string') {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputString($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
} elseif ($setting['type'] == 'boolean') {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputCheckbox($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
$description = '';
|
|
|
|
} elseif ($setting['type'] == 'integer') {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputInteger($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
} elseif ($setting['type'] == 'select') {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputSelect($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
} elseif ($setting['type'] == 'multi-select') {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputMultiSelect($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
} else {
|
2021-07-21 16:07:30 +02:00
|
|
|
$input = genInputString($settingName, $setting, $appView);
|
2021-07-19 15:00:09 +02:00
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
|
|
|
|
$inputGroupSave = $appView->Bootstrap->genNode('div', [
|
|
|
|
'class' => ['input-group-append', 'd-none', 'position-relative', 'input-group-actions'],
|
|
|
|
], implode('', [
|
|
|
|
$appView->Bootstrap->genNode('a', [
|
|
|
|
'class' => ['position-absolute', 'fas fa-times', 'p-abs-center-y', 'text-reset text-decoration-none', 'btn-reset-setting'],
|
|
|
|
'href' => '#',
|
|
|
|
'style' => 'left: -1.25em; z-index: 5;'
|
|
|
|
]),
|
|
|
|
$appView->Bootstrap->genNode('button', [
|
|
|
|
'class' => ['btn', 'btn-success', 'btn-save-setting'],
|
|
|
|
'type' => 'button'
|
|
|
|
], __('save')),
|
|
|
|
]));
|
|
|
|
$inputGroup = $appView->Bootstrap->genNode('div', [
|
|
|
|
'class' => ['input-group'],
|
|
|
|
], implode('', [$input, $inputGroupSave]));
|
|
|
|
|
2021-07-19 15:00:09 +02:00
|
|
|
$container = $appView->Bootstrap->genNode('div', [
|
|
|
|
'class' => ['form-group', 'mb-2']
|
2021-07-21 16:07:30 +02:00
|
|
|
], implode('', [$label, $inputGroup, $description, $error]));
|
2021-07-19 15:00:09 +02:00
|
|
|
return $container;
|
|
|
|
}
|
|
|
|
|
2021-07-21 16:07:30 +02:00
|
|
|
function genInputString($settingName, $setting, $appView)
|
2021-07-19 15:00:09 +02:00
|
|
|
{
|
2021-07-21 16:07:30 +02:00
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-07-19 15:00:09 +02:00
|
|
|
return $appView->Bootstrap->genNode('input', [
|
|
|
|
'class' => [
|
2021-07-20 11:54:55 +02:00
|
|
|
'form-control',
|
|
|
|
(!empty($setting['error']) ? 'is-invalid' : ''),
|
2021-07-21 11:18:06 +02:00
|
|
|
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
|
|
|
|
(!empty($setting['error']) && $setting['severity'] == 'warning' ? 'warning' : ''),
|
2021-07-19 15:00:09 +02:00
|
|
|
],
|
|
|
|
'type' => 'text',
|
2021-07-21 11:18:06 +02:00
|
|
|
'id' => $settingId,
|
2021-07-21 16:07:30 +02:00
|
|
|
'data-setting-name' => $settingName,
|
2021-07-19 15:00:09 +02:00
|
|
|
'value' => isset($setting['value']) ? $setting['value'] : "",
|
2021-07-20 11:54:55 +02:00
|
|
|
'placeholder' => $setting['default'] ?? '',
|
2021-07-21 11:18:06 +02:00
|
|
|
'aria-describedby' => "{$settingId}Help"
|
2021-07-19 15:00:09 +02:00
|
|
|
]);
|
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
function genInputCheckbox($settingName, $setting, $appView)
|
2021-07-19 15:00:09 +02:00
|
|
|
{
|
2021-07-21 16:07:30 +02:00
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-07-19 15:00:09 +02:00
|
|
|
$switch = $appView->Bootstrap->genNode('input', [
|
|
|
|
'class' => [
|
|
|
|
'custom-control-input'
|
|
|
|
],
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'value' => !empty($setting['value']) ? 1 : 0,
|
|
|
|
'checked' => !empty($setting['value']) ? 'checked' : '',
|
2021-07-21 11:18:06 +02:00
|
|
|
'id' => $settingId,
|
2021-07-21 16:07:30 +02:00
|
|
|
'data-setting-name' => $settingName,
|
2021-07-19 15:00:09 +02:00
|
|
|
]);
|
|
|
|
$label = $appView->Bootstrap->genNode('label', [
|
|
|
|
'class' => [
|
|
|
|
'custom-control-label'
|
|
|
|
],
|
2021-07-21 11:18:06 +02:00
|
|
|
'for' => $settingId,
|
2021-07-19 15:00:09 +02:00
|
|
|
], h($setting['description']));
|
|
|
|
$container = $appView->Bootstrap->genNode('div', [
|
|
|
|
'class' => [
|
|
|
|
'custom-control',
|
|
|
|
'custom-switch',
|
|
|
|
],
|
|
|
|
], implode('', [$switch, $label]));
|
|
|
|
return $container;
|
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
function genInputInteger($settingName, $setting, $appView)
|
2021-07-19 15:00:09 +02:00
|
|
|
{
|
2021-07-21 16:07:30 +02:00
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-07-19 15:00:09 +02:00
|
|
|
return $appView->Bootstrap->genNode('input', [
|
|
|
|
'class' => [
|
|
|
|
'form-control'
|
|
|
|
],
|
2021-07-21 11:18:06 +02:00
|
|
|
'type' => 'number',
|
|
|
|
'min' => '0',
|
|
|
|
'step' => 1,
|
|
|
|
'id' => $settingId,
|
2021-07-21 16:07:30 +02:00
|
|
|
'data-setting-name' => $settingName,
|
2021-07-21 11:18:06 +02:00
|
|
|
'aria-describedby' => "{$settingId}Help"
|
2021-07-19 15:00:09 +02:00
|
|
|
]);
|
|
|
|
}
|
2021-07-21 11:18:06 +02:00
|
|
|
function genInputSelect($settingId, $setting, $appView)
|
2021-07-19 15:00:09 +02:00
|
|
|
{
|
|
|
|
}
|
2021-07-21 11:18:06 +02:00
|
|
|
function genInputMultiSelect($settingId, $setting, $appView)
|
2021-07-19 15:00:09 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
function genScrollspyNav($nav1)
|
|
|
|
{
|
|
|
|
$nav = '<nav id="navbar-scrollspy-setting" class="navbar">';
|
|
|
|
$nav .= '<nav class="nav nav-pills flex-column">';
|
|
|
|
foreach ($nav1 as $group => $sections) {
|
|
|
|
$nav .= sprintf('<a class="nav-link main-group text-reset p-1" href="#%s">%s</a>', sprintf('sp-%s', h($group)), h($group));
|
|
|
|
$nav .= sprintf('<nav class="nav nav-pills sub-group collapse flex-column" data-maingroup="%s">', sprintf('sp-%s', h($group)));
|
|
|
|
foreach ($sections as $section) {
|
|
|
|
$nav .= sprintf('<a class="nav-link nav-link-group text-reset ml-3 my-1 p-1" href="#%s">%s</a>', sprintf('sp-%s-%s', h($group), h($section)), h($section));
|
|
|
|
}
|
|
|
|
$nav .= '</nav>';
|
|
|
|
}
|
|
|
|
$nav .= '</nav>';
|
|
|
|
$nav .= '</nav>';
|
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isLeaf($setting)
|
|
|
|
{
|
|
|
|
return !empty($setting['name']) && !empty($setting['type']);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
2021-07-21 11:18:06 +02:00
|
|
|
|
2021-07-19 15:00:09 +02:00
|
|
|
<script>
|
2021-07-21 16:07:30 +02:00
|
|
|
const variantFromSeverity = <?= json_encode($variantFromSeverity) ?>;
|
2021-07-21 11:18:06 +02:00
|
|
|
const settingsFlattened = <?= json_encode($settingsFlattened) ?>;
|
|
|
|
let selectData = []
|
|
|
|
for (const settingName in settingsFlattened) {
|
|
|
|
if (Object.hasOwnProperty.call(settingsFlattened, settingName)) {
|
|
|
|
const setting = settingsFlattened[settingName];
|
|
|
|
const selectID = settingName.replaceAll('.', '_')
|
|
|
|
selectData.push({
|
|
|
|
id: selectID,
|
|
|
|
text: setting.name,
|
|
|
|
setting: setting
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('[data-spy="scroll"]').on('activate.bs.scrollspy', function(evt, {relatedTarget}) {
|
|
|
|
const $associatedLink = $(`#navbar-scrollspy-setting nav.nav-pills .nav-link[href="${relatedTarget}"]`)
|
|
|
|
let $associatedNav
|
|
|
|
if ($associatedLink.hasClass('main-group')) {
|
|
|
|
$associatedNav = $associatedLink.next()
|
|
|
|
} else {
|
|
|
|
$associatedNav = $associatedLink.parent()
|
|
|
|
}
|
|
|
|
const $allNavs = $('#navbar-scrollspy-setting nav.nav-pills.sub-group')
|
|
|
|
$allNavs.removeClass('group-active').hide()
|
|
|
|
$associatedNav.addClass('group-active').show()
|
|
|
|
})
|
2021-07-21 11:18:06 +02:00
|
|
|
|
|
|
|
$('.settings-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (event) {
|
|
|
|
$('[data-spy="scroll"]').trigger('scroll.bs.scrollspy')
|
|
|
|
})
|
|
|
|
|
|
|
|
$("#search-settings").select2({
|
|
|
|
data: selectData,
|
|
|
|
placeholder: '<?= __('Search setting by typing here...') ?>',
|
|
|
|
templateResult: formatSettingSearchResult,
|
|
|
|
templateSelection: formatSettingSearchSelection,
|
|
|
|
})
|
|
|
|
.on('select2:select', function (e) {
|
|
|
|
const selected = e.params.data
|
|
|
|
const settingPath = selected.setting['setting-path']
|
|
|
|
const settingPathTokenized = settingPath.split('.')
|
|
|
|
const tabName = settingPathTokenized[0]
|
|
|
|
const IDtoFocus = 'sp-' + settingPathTokenized.slice(1).join('-')
|
|
|
|
const $navController = $('.settings-tabs').find('a.nav-link').filter(function() {
|
|
|
|
return $(this).text() == tabName
|
|
|
|
})
|
|
|
|
if ($navController.length == 1) {
|
|
|
|
$toFocus = $(`#${IDtoFocus}`).parent()
|
|
|
|
if ($navController.hasClass('active')) {
|
|
|
|
$toFocus[0].scrollIntoView()
|
|
|
|
$toFocus.find(`input#${selected.id}`).focus()
|
|
|
|
} else {
|
|
|
|
$navController.on('shown.bs.tab.after-selection', () => {
|
|
|
|
$toFocus[0].scrollIntoView()
|
|
|
|
$toFocus.find(`input#${selected.id}`).focus()
|
|
|
|
$navController.off('shown.bs.tab.after-selection')
|
|
|
|
}).tab('show')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#search-settings").val(null).trigger('change.select2');
|
|
|
|
})
|
2021-07-21 16:07:30 +02:00
|
|
|
|
|
|
|
$('.tab-content input').on('input', function() {
|
|
|
|
handleSettingValueChange($(this))
|
|
|
|
})
|
|
|
|
|
|
|
|
$('.tab-content .input-group-actions .btn-save-setting').click(function() {
|
|
|
|
const $input = $(this).closest('.input-group').find('input')
|
|
|
|
const settingName = $input.data('setting-name')
|
|
|
|
const settingValue = $input.val()
|
|
|
|
const url = '/instance/saveSetting/'
|
|
|
|
const data = {
|
|
|
|
name: settingName,
|
|
|
|
value: settingValue,
|
|
|
|
}
|
|
|
|
const APIOptions = {
|
|
|
|
statusNode: this
|
|
|
|
}
|
|
|
|
AJAXApi.quickFetchAndPostForm(url, data, APIOptions).then((result) => {
|
|
|
|
settingsFlattened[settingName] = result.data
|
|
|
|
$input.val(result.data.value)
|
|
|
|
handleSettingValueChange($input)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
$('.tab-content .input-group-actions .btn-reset-setting').click(function() {
|
|
|
|
const $btn = $(this)
|
|
|
|
const $input = $btn.closest('.input-group').find('input')
|
|
|
|
const oldValue = settingsFlattened[$input.data('setting-name')].value
|
|
|
|
$input.val(oldValue)
|
|
|
|
handleSettingValueChange($input)
|
|
|
|
})
|
2021-07-19 15:00:09 +02:00
|
|
|
})
|
|
|
|
|
2021-07-21 11:18:06 +02:00
|
|
|
function formatSettingSearchResult(state) {
|
|
|
|
if (!state.id) {
|
|
|
|
return state.text;
|
|
|
|
}
|
|
|
|
const $state = $('<div/>').append(
|
|
|
|
$('<div/>').addClass('d-flex justify-content-between')
|
|
|
|
.append(
|
|
|
|
$('<span/>').addClass('font-weight-bold').text(state.text),
|
|
|
|
$('<span/>').addClass('font-weight-light').text(state.setting['setting-path'].replaceAll('.', ' ▸ '))
|
|
|
|
),
|
|
|
|
$('<div/>').addClass('font-italic font-weight-light ml-3').text(state.setting['description'])
|
|
|
|
)
|
|
|
|
return $state
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatSettingSearchSelection(state) {
|
|
|
|
return state.text
|
|
|
|
}
|
|
|
|
|
2021-07-21 16:07:30 +02:00
|
|
|
function handleSettingValueChange($input) {
|
|
|
|
const oldValue = settingsFlattened[$input.data('setting-name')].value
|
|
|
|
if ($input.val() == oldValue) {
|
|
|
|
restoreWarnings($input)
|
|
|
|
} else {
|
|
|
|
removeWarnings($input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeWarnings($input) {
|
|
|
|
const $inputGroup = $input.closest('.input-group')
|
|
|
|
const $inputGroupAppend = $inputGroup.find('.input-group-append')
|
|
|
|
const $saveButton = $inputGroup.find('button.btn-save-setting')
|
|
|
|
$input.removeClass(['is-invalid', 'border-warning', 'border-danger'])
|
|
|
|
$inputGroupAppend.removeClass('d-none')
|
|
|
|
$inputGroup.parent().find('.invalid-feedback').removeClass('d-block')
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreWarnings($input) {
|
|
|
|
const $inputGroup = $input.closest('.input-group')
|
|
|
|
const $inputGroupAppend = $inputGroup.find('.input-group-append')
|
|
|
|
const $saveButton = $inputGroup.find('button.btn-save-setting')
|
|
|
|
const setting = settingsFlattened[$input.data('setting-name')]
|
|
|
|
if (setting.error) {
|
|
|
|
borderVariant = setting.severity !== undefined ? variantFromSeverity[setting.severity] : 'warning'
|
|
|
|
$input.addClass(['is-invalid', `border-${borderVariant}`])
|
|
|
|
if (setting.severity == 'warning') {
|
|
|
|
$input.addClass('warning')
|
|
|
|
}
|
|
|
|
$inputGroup.parent().find('.invalid-feedback').addClass('d-block').text(setting.errorMessage)
|
|
|
|
}
|
|
|
|
const $callout = $input.closest('.settings-group')
|
|
|
|
updateCalloutColors($callout)
|
|
|
|
$inputGroupAppend.addClass('d-none')
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCalloutColors($callout) {
|
|
|
|
const $settings = $callout.find('input')
|
|
|
|
const settingNames = Array.from($settings).map((i) => {
|
|
|
|
return $(i).data('setting-name')
|
|
|
|
})
|
|
|
|
const severityMapping = {null: 0, info: 1, warning: 2, critical: 3}
|
|
|
|
const severityMappingInverted = Object.assign({}, ...Object.entries(severityMapping).map(([k, v]) => ({[v]: k})))
|
|
|
|
let highestSeverity = severityMapping[null]
|
|
|
|
settingNames.forEach(name => {
|
|
|
|
if (settingsFlattened[name].error) {
|
|
|
|
highestSeverity = severityMapping[settingsFlattened[name].severity] > highestSeverity ? severityMapping[settingsFlattened[name].severity] : highestSeverity
|
|
|
|
}
|
|
|
|
});
|
|
|
|
highestSeverity = severityMappingInverted[highestSeverity]
|
|
|
|
$callout.removeClass(['callout', 'callout-danger', 'callout-warning', 'callout-info'])
|
|
|
|
if (highestSeverity !== null) {
|
|
|
|
$callout.addClass(['callout', `callout-${variantFromSeverity[highestSeverity]}`])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 15:00:09 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#navbar-scrollspy-setting nav.nav-pills .nav-link {
|
|
|
|
background-color: unset !important;
|
|
|
|
color: black;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
#navbar-scrollspy-setting nav.nav-pills .nav-link:not(.main-group).active {
|
|
|
|
color: #007bff !important;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
#navbar-scrollspy-setting nav.nav-pills .nav-link.main-group:before {
|
|
|
|
margin-right: 0.25em;
|
|
|
|
font-family: 'Font Awesome 5 Free';
|
|
|
|
font-weight: 900;
|
|
|
|
-webkit-font-smoothing: antialiased;
|
|
|
|
display: inline-block;
|
|
|
|
font-style: normal;
|
|
|
|
font-variant: normal;
|
|
|
|
text-rendering: auto;
|
|
|
|
line-height: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#navbar-scrollspy-setting nav.nav-pills .nav-link.main-group.active:before {
|
|
|
|
content: "\f0d7";
|
|
|
|
}
|
|
|
|
|
|
|
|
#navbar-scrollspy-setting nav.nav-pills .nav-link.main-group:before {
|
|
|
|
content: "\f0da";
|
|
|
|
}
|
2021-07-21 11:18:06 +02:00
|
|
|
|
|
|
|
.select2-container {
|
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
</style>
|