2021-07-19 15:00:09 +02:00
|
|
|
<?php
|
2021-07-30 08:18:30 +02:00
|
|
|
|
2021-07-21 11:18:06 +02:00
|
|
|
$variantFromSeverity = [
|
|
|
|
'critical' => 'danger',
|
|
|
|
'warning' => 'warning',
|
|
|
|
'info' => 'info',
|
|
|
|
];
|
2021-10-12 10:21:12 +02:00
|
|
|
|
|
|
|
$navLinks = [];
|
|
|
|
$tabContents = [];
|
|
|
|
|
|
|
|
foreach ($settingsProvider as $settingTitle => $settingContent) {
|
|
|
|
$navLinks[] = h($settingTitle);
|
|
|
|
$tabContents[] = $this->element('Settings/category', [
|
|
|
|
'settings' => $settingContent,
|
|
|
|
'includeScrollspy' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
array_unshift($navLinks, __('Settings Diagnostic'));
|
|
|
|
$notice = $this->element('Settings/notice', [
|
|
|
|
'variantFromSeverity' => $variantFromSeverity,
|
|
|
|
'notices' => $notices,
|
|
|
|
]);
|
|
|
|
array_unshift($tabContents, $notice);
|
2021-07-19 15:00:09 +02:00
|
|
|
?>
|
2021-07-26 11:16:52 +02:00
|
|
|
|
|
|
|
<script>
|
|
|
|
const variantFromSeverity = <?= json_encode($variantFromSeverity) ?>;
|
|
|
|
const settingsFlattened = <?= json_encode($settingsFlattened) ?>;
|
|
|
|
</script>
|
|
|
|
|
2021-07-19 15:00:09 +02:00
|
|
|
<div class="px-5">
|
2021-09-28 10:59:57 +02:00
|
|
|
<div class="mb-3 mt-2">
|
2021-07-26 11:16:52 +02:00
|
|
|
<?=
|
|
|
|
$this->element('Settings/search', [
|
2021-10-12 10:21:12 +02:00
|
|
|
'settingsFlattened' => $settingsFlattened,
|
2021-07-26 11:16:52 +02:00
|
|
|
]);
|
|
|
|
?>
|
2021-07-19 15:00:09 +02:00
|
|
|
</div>
|
2021-10-12 10:21:12 +02:00
|
|
|
<?php
|
|
|
|
$tabsOptions = [
|
|
|
|
'card' => false,
|
|
|
|
'pills' => false,
|
|
|
|
'justify' => 'center',
|
|
|
|
'nav-class' => ['settings-tabs'],
|
|
|
|
'data' => [
|
|
|
|
'navs' => $navLinks,
|
|
|
|
'content' => $tabContents
|
|
|
|
]
|
|
|
|
];
|
|
|
|
echo $this->Bootstrap->tabs($tabsOptions);
|
|
|
|
?>
|
2021-07-19 15:00:09 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
2021-09-17 17:51:45 +02:00
|
|
|
new bootstrap.Tooltip('.depends-on-icon', {
|
2021-07-26 11:16:52 +02:00
|
|
|
placement: 'right',
|
2021-07-19 15:00:09 +02:00
|
|
|
})
|
2021-07-30 14:50:40 +02:00
|
|
|
$('select.custom-select[multiple]').select2()
|
2021-07-21 11:18:06 +02:00
|
|
|
|
2021-09-17 17:51:45 +02:00
|
|
|
$('.settings-tabs a[data-bs-toggle="tab"]').on('shown.bs.tab', function (event) {
|
|
|
|
$('[data-bs-spy="scroll"]').trigger('scroll.bs.scrollspy')
|
2021-07-21 11:18:06 +02:00
|
|
|
})
|
|
|
|
|
2021-07-22 16:59:26 +02:00
|
|
|
$('.tab-content input, .tab-content select').on('input', function() {
|
2021-07-22 15:51:06 +02:00
|
|
|
if ($(this).attr('type') == 'checkbox') {
|
|
|
|
const $input = $(this)
|
2021-09-17 17:51:45 +02:00
|
|
|
const $inputGroup = $(this).closest('.setting-group')
|
2021-07-22 15:51:06 +02:00
|
|
|
const settingName = $(this).data('setting-name')
|
2021-07-27 10:58:34 +02:00
|
|
|
const settingValue = $(this).is(':checked') ? 1 : 0
|
2021-07-22 15:51:06 +02:00
|
|
|
saveSetting($inputGroup[0], $input, settingName, settingValue)
|
|
|
|
} else {
|
|
|
|
handleSettingValueChange($(this))
|
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
})
|
|
|
|
|
2021-09-28 09:23:02 +02:00
|
|
|
$('.tab-content .setting-group .btn-save-setting').click(function() {
|
2021-07-22 16:59:26 +02:00
|
|
|
const $input = $(this).closest('.input-group').find('input, select')
|
2021-07-21 16:07:30 +02:00
|
|
|
const settingName = $input.data('setting-name')
|
|
|
|
const settingValue = $input.val()
|
2021-07-22 15:51:06 +02:00
|
|
|
saveSetting(this, $input, settingName, settingValue)
|
2021-07-21 16:07:30 +02:00
|
|
|
})
|
2021-09-28 09:23:02 +02:00
|
|
|
$('.tab-content .setting-group .btn-reset-setting').click(function() {
|
2021-07-21 16:07:30 +02:00
|
|
|
const $btn = $(this)
|
2021-07-22 16:59:26 +02:00
|
|
|
const $input = $btn.closest('.input-group').find('input, select')
|
|
|
|
let oldValue = settingsFlattened[$input.data('setting-name')].value
|
|
|
|
if ($input.is('select')) {
|
|
|
|
oldValue = oldValue !== undefined ? oldValue : -1
|
2021-07-23 14:51:48 +02:00
|
|
|
} else {
|
|
|
|
oldValue = oldValue !== undefined ? oldValue : ''
|
2021-07-22 16:59:26 +02:00
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
$input.val(oldValue)
|
|
|
|
handleSettingValueChange($input)
|
|
|
|
})
|
2021-07-30 09:23:19 +02:00
|
|
|
|
2021-07-30 11:44:53 +02:00
|
|
|
const referencedID = window.location.hash
|
|
|
|
redirectToSetting(referencedID)
|
2021-07-19 15:00:09 +02:00
|
|
|
})
|
|
|
|
|
2021-07-22 15:51:06 +02:00
|
|
|
function saveSetting(statusNode, $input, settingName, settingValue) {
|
|
|
|
const url = '/instance/saveSetting/'
|
|
|
|
const data = {
|
|
|
|
name: settingName,
|
|
|
|
value: settingValue,
|
|
|
|
}
|
|
|
|
const APIOptions = {
|
|
|
|
statusNode: statusNode,
|
|
|
|
}
|
|
|
|
AJAXApi.quickFetchAndPostForm(url, data, APIOptions).then((result) => {
|
|
|
|
settingsFlattened[settingName] = result.data
|
|
|
|
if ($input.attr('type') == 'checkbox') {
|
|
|
|
$input.prop('checked', result.data.value)
|
|
|
|
} else {
|
|
|
|
$input.val(result.data.value)
|
|
|
|
}
|
|
|
|
handleSettingValueChange($input)
|
2021-07-27 10:40:58 +02:00
|
|
|
}).catch((e) => {})
|
2021-07-22 15:51:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 16:07:30 +02:00
|
|
|
function handleSettingValueChange($input) {
|
|
|
|
const oldValue = settingsFlattened[$input.data('setting-name')].value
|
2021-07-22 15:51:06 +02:00
|
|
|
const newValue = ($input.attr('type') == 'checkbox' ? $input.is(':checked') : $input.val())
|
2021-07-23 14:51:48 +02:00
|
|
|
if (newValue == oldValue || (newValue == '' && oldValue == undefined)) {
|
2021-07-21 16:07:30 +02:00
|
|
|
restoreWarnings($input)
|
|
|
|
} else {
|
|
|
|
removeWarnings($input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeWarnings($input) {
|
|
|
|
const $inputGroup = $input.closest('.input-group')
|
2021-09-28 09:23:02 +02:00
|
|
|
const $btnSettingAction = $inputGroup.find('.btn-setting-action')
|
|
|
|
const $saveButton = $('.setting-group button.btn-save-setting')
|
2021-07-27 10:40:58 +02:00
|
|
|
$input.removeClass(['is-invalid', 'border-warning', 'border-danger', 'border-info', 'warning', 'info'])
|
2021-09-28 09:23:02 +02:00
|
|
|
$btnSettingAction.removeClass('d-none')
|
2021-07-22 16:59:26 +02:00
|
|
|
if ($input.is('select') && $input.find('option:selected').data('is-empty-option') == 1) {
|
2021-09-28 09:23:02 +02:00
|
|
|
$btnSettingAction.addClass('d-none') // hide save button if empty selection picked
|
2021-07-22 16:59:26 +02:00
|
|
|
}
|
2021-07-21 16:07:30 +02:00
|
|
|
$inputGroup.parent().find('.invalid-feedback').removeClass('d-block')
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreWarnings($input) {
|
|
|
|
const $inputGroup = $input.closest('.input-group')
|
2021-09-28 09:23:02 +02:00
|
|
|
const $btnSettingAction = $inputGroup.find('.btn-setting-action')
|
|
|
|
const $saveButton = $('.setting-group button.btn-save-setting')
|
2021-07-21 16:07:30 +02:00
|
|
|
const setting = settingsFlattened[$input.data('setting-name')]
|
|
|
|
if (setting.error) {
|
|
|
|
borderVariant = setting.severity !== undefined ? variantFromSeverity[setting.severity] : 'warning'
|
2021-07-27 10:40:58 +02:00
|
|
|
$input.addClass(['is-invalid', `border-${borderVariant}`, borderVariant])
|
2021-07-21 16:07:30 +02:00
|
|
|
$inputGroup.parent().find('.invalid-feedback').addClass('d-block').text(setting.errorMessage)
|
2021-07-22 15:51:06 +02:00
|
|
|
} else {
|
|
|
|
removeWarnings($input)
|
2021-07-21 16:07:30 +02:00
|
|
|
}
|
|
|
|
const $callout = $input.closest('.settings-group')
|
|
|
|
updateCalloutColors($callout)
|
2021-09-28 09:23:02 +02:00
|
|
|
$btnSettingAction.addClass('d-none')
|
2021-07-21 16:07:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateCalloutColors($callout) {
|
2021-07-22 15:51:06 +02:00
|
|
|
if ($callout.length == 0) {
|
|
|
|
return
|
|
|
|
}
|
2021-07-23 12:03:03 +02:00
|
|
|
const $settings = $callout.find('input, select')
|
2021-07-21 16:07:30 +02:00
|
|
|
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-30 09:23:19 +02:00
|
|
|
|
2021-07-30 11:44:53 +02:00
|
|
|
function redirectToSetting(referencedID) {
|
2021-07-30 09:23:19 +02:00
|
|
|
const $settingToFocus = $(referencedID)
|
|
|
|
const pageNavID = $(referencedID).closest('.tab-pane').attr('aria-labelledby')
|
|
|
|
const $navController = $(`#${pageNavID}`)
|
2021-09-28 11:35:39 +02:00
|
|
|
const $settingGroup = $settingToFocus.closest('.settings-group')
|
2021-07-30 09:23:19 +02:00
|
|
|
$navController
|
|
|
|
.on('shown.bs.tab.after-redirect', () => {
|
|
|
|
$settingToFocus[0].scrollIntoView()
|
|
|
|
const inputID = $settingToFocus.parent().attr('for')
|
2021-09-17 17:51:45 +02:00
|
|
|
$settingToFocus.closest('.setting-group').find(`#${inputID}`).focus()
|
2021-07-30 09:23:19 +02:00
|
|
|
$navController.off('shown.bs.tab.after-redirect')
|
2021-09-28 11:35:39 +02:00
|
|
|
$settingGroup.addClass(['to-be-slided', 'slide-in'])
|
2021-07-30 09:23:19 +02:00
|
|
|
})
|
|
|
|
.tab('show')
|
2021-09-28 11:35:39 +02:00
|
|
|
$settingGroup.on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
|
|
|
|
$(this).removeClass(['to-be-slided', 'slide-in'])
|
|
|
|
});
|
2021-07-30 09:23:19 +02:00
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2021-07-22 16:59:26 +02:00
|
|
|
.input-group-actions {
|
|
|
|
z-index: 5;
|
|
|
|
}
|
2021-07-26 11:16:52 +02:00
|
|
|
.form-control[type="number"] ~ div > a.btn-reset-setting {
|
2021-07-23 14:51:48 +02:00
|
|
|
left: -3em;
|
|
|
|
}
|
2021-07-30 14:50:40 +02:00
|
|
|
select.custom-select[multiple][data-setting-name] ~ span.select2-container{
|
|
|
|
min-width: unset;
|
|
|
|
}
|
|
|
|
span.select2-container--open {
|
|
|
|
min-width: unset;
|
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
</style>
|