/** * The UGC server's settings on the UGC page, beside what they change: any element with data-ugc-settings="
, *
" shows those sections of the settings catalog (the same entries, values and save path as the Settings * page, /api/settings, so a change in either place is the other's too; the servers reload at once). Settings only read * at start say so. Each has a link to it on the Settings page. Only for those with the settings permission. */ (function () { 'use strict'; if (!window.DASH || !DASH.can('settings')) return; var boxes = document.querySelectorAll('[data-ugc-settings]'); if (!boxes.length) return; var settings = null; function key(s) { return s.file + '/' + s.name; } function sourceText(s) { if (s.source === 'web') return 'set here'; if (s.source === 'file') return 'from ' + s.file; if (s.source === 'env') return 'from the environment'; return 'default'; } function input(s) { var id = 'ugcset-' + key(s).replace(/[^a-z0-9_]/gi, '-'), value = s.value === undefined || s.value === null ? '' : String(s.value); var attrs = ' id="' + id + '" data-ugc-setting="' + esc(key(s)) + '"' + (s.fileOnly ? ' disabled' : ''); if (s.type === 'bool') { return '
'; } if (s.type === 'choice') { return ''; } var number = s.type === 'int' || s.type === 'float'; return ''; } function row(s) { return '
Open in Settings
' + '
' + input(s) + (s.unit ? '' + esc(s.unit) + '' : '') + '
' + '
' + (s.description ? esc(s.description) + ' ' : '') + 'Default ' + esc(s.default === '' ? '(empty)' : s.default) + '; ' + '' + esc(sourceText(s)) + '.' + (s.restart ? ' ' + fmt.badge('restart', 'warning') : '') + '
'; } function render(box) { var sections = box.dataset.ugcSettings.split(',').map(function (x) { return x.trim(); }); var shown = settings.filter(function (s) { return sections.indexOf(s.section) !== -1 && !s.secret; }); var open = box.querySelector('details[open]') ? ' open' : ''; box.innerHTML = '
' + esc(box.dataset.title || 'Settings') + ' (' + shown.length + ')' + '
The same settings as on the Settings page; a change saves at once and the servers reload. ' + 'Those marked restart are only read when the UGC server starts.
' + shown.map(row).join('') + '
'; } function load() { return api.get('/api/settings').then(function (d) { if (!d.success) return; settings = d.settings; boxes.forEach(render); }); } document.addEventListener('change', function (e) { var el = e.target.closest && e.target.closest('[data-ugc-setting]'); if (!el || !settings) return; var s = settings.find(function (x) { return key(x) === el.dataset.ugcSetting; }); if (!s) return; var value = s.type === 'bool' ? el.checked : el.value; // A value the .ini file (or environment) sets would win over one set here unless this one is told to win api.post('/api/settings', { file: s.file, name: s.name, value: value, webWins: s.source === 'file' || s.source === 'env' || s.webWins }).then(function (d) { toast(d.success ? d.message : (d.error || 'Not saved'), d.success ? 'success' : 'danger'); if (!d.success) return; s.value = d.value; s.source = 'web'; document.querySelectorAll('[data-ugc-source="' + CSS.escape(key(s)) + '"]').forEach(function (x) { x.textContent = sourceText(s); }); }); }); if (window.Live) Live.on('settings', load); load(); })();