From 25e055a7ace55f4e4261c3800ab6578aec5440ba Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Mon, 17 Aug 2026 16:11:52 -0400 Subject: [PATCH] Merge the partnership settings into one section, arrays and scalars together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They were two sections drawing the same endpoint, split on whether a value happened to be a list — with two Save buttons for one subject. --- Plugin/unraid/pages/partnership.php | 125 +++++----------------------- 1 file changed, 21 insertions(+), 104 deletions(-) diff --git a/Plugin/unraid/pages/partnership.php b/Plugin/unraid/pages/partnership.php index 27cc6f7..07552b5 100644 --- a/Plugin/unraid/pages/partnership.php +++ b/Plugin/unraid/pages/partnership.php @@ -172,8 +172,6 @@ textarea.vv-pt-set-input { resize:vertical; white-space:pre; } Collapsed together they cost one line until opened. --> @@ -418,103 +416,10 @@ async function vvPtStopSeed(btn) { // ── Array settings cards ─────────────────────────────────────────────────────── -let _vvArrFiles = null; -function _vvInitArrayCards() { - if (_vvArrFiles !== null) return; - _vvArrFiles = false; // loading sentinel - fetch('/plugins/varaverk/api/partnership_settings.php?_=' + Date.now()) - .then(r => r.json()) - .then(d => { - _vvArrFiles = (d.ok && d.files) ? d.files : []; - _vvRenderArrayCards(); - }) - .catch(() => { _vvArrFiles = []; document.getElementById('vv-pt-arrays-wrap').style.display = 'none'; }); -} -function _vvRenderArrayCards() { - const files = _vvArrFiles; - if (!files || !files.length) { document.getElementById('vv-pt-arrays-wrap').style.display = 'none'; return; } - let html = ''; - let hasArrays = false; - for (const f of files) { - for (const g of f.groups) { - for (const fld of g.fields) { - if (fld.type === 'scalar') continue; - hasArrays = true; - const rows = Math.min(16, (fld.value.match(/\n/g) || []).length + 2); - const attrs = `class="vv-pt-set-input" data-key="${_vvSetEsc(fld.key)}" ` - + `data-file="${_vvSetEsc(fld.file)}" data-type="${_vvSetEsc(fld.type)}" ` - + `data-orig="${_vvSetEsc(fld.value)}" oninput="vvPtArrChanged(this)"`; - html += `
-
- ${_vvSetEsc(fld.key)} -
- ${fld.desc ? `${_vvSetEsc(fld.desc)}` : ''} - -
-
- -
`; - } - } - } - const wrap = document.getElementById('vv-pt-arrays-wrap'); - if (!hasArrays) { wrap.style.display = 'none'; return; } - - wrap.style.display = ''; - wrap.innerHTML = `
-
-
Array settings
- -
- ${html} -
`; -} - -function vvPtArrChanged(el) { - el.classList.toggle('changed', el.value !== el.dataset.orig); - const any = document.querySelector('#vv-pt-arrays-wrap .vv-pt-set-input.changed'); - const saveBtn = document.getElementById('vv-pt-arrays-save'); - if (saveBtn) saveBtn.style.display = any ? '' : 'none'; -} - -async function vvPtSaveArrays(btn) { - const changedEls = document.querySelectorAll('#vv-pt-arrays-wrap .vv-pt-set-input.changed'); - if (!changedEls.length) return; - const changes = []; - changedEls.forEach(el => changes.push({key: el.dataset.key, file: el.dataset.file, type: el.dataset.type, value: el.value})); - if (!await vvConfirm(`Save ${changes.length} changed setting(s)?`)) return; - btn.disabled = true; btn.textContent = '⟳ Saving…'; - fetch('/plugins/varaverk/api/confform.php', { - method: 'POST', - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - body: new URLSearchParams({ - csrf_token: typeof csrf_token !== 'undefined' ? csrf_token : '', - id: '__settings__', - changes: JSON.stringify(changes) - }) - }) - .then(r => r.json()) - .then(d => { - btn.disabled = false; - if (d.ok) { - changedEls.forEach(el => { el.dataset.orig = el.value; el.classList.remove('changed'); }); - btn.textContent = '✓ Saved'; - _vvArrFiles = null; // invalidate so next init re-fetches - setTimeout(() => _vvInitArrayCards(), 600); - } else { - btn.textContent = 'Save Changes'; - vvAlert('Save failed: ' + (d.error ?? 'Unknown error')); - } - }) - .catch(e => { btn.disabled = false; btn.textContent = 'Save Changes'; vvAlert('Error: ' + e); }); -} // ── Settings panel ───────────────────────────────────────────────────────────── let _vvSetLoaded = false; @@ -555,29 +460,43 @@ function vvPtLoadSettings() { .catch(e => { body.innerHTML = '
Error: ' + e + '
'; }); } +// Every partnership field, scalars and arrays together, in the order the conf declares them. +// +// These were two sections drawing the same endpoint and splitting it on whether a value happened +// to be a list: 25 scalars under "Partnership settings", 10 arrays under "Array settings", each +// with its own Save. Nothing about the subject is divided that way — PROVISION_SHARES and +// PARTNERSHIP_ENABLED are the same conversation — and the split meant looking in two places for +// one setting, with the arrays half easy to mistake for something belonging to another page. +// +// Both render into the same .vv-pt-set-field wrapper so a list and a value read as siblings; the +// only difference is a textarea instead of an input, sized to the content. function vvPtRenderSettings(files) { let html = ''; for (const f of files) { - const label = f.file === 'master.conf' ? 'master.conf — shared' : f.file + ' — this host'; - const scalarFields = f.groups.flatMap(g => g.fields.filter(fld => fld.type === 'scalar')); - if (!scalarFields.length) continue; + const label = f.file === 'master.conf' ? 'master.conf — shared' : f.file + ' — this host'; + const fields = f.groups.flatMap(g => g.fields); + if (!fields.length) continue; html += `
${_vvSetEsc(label)}
`; - for (const fld of scalarFields) { + for (const fld of fields) { + const isArr = fld.type !== 'scalar'; const attrs = `class="vv-pt-set-input" data-key="${_vvSetEsc(fld.key)}" ` + `data-file="${_vvSetEsc(fld.file)}" data-type="${_vvSetEsc(fld.type)}" ` + `data-orig="${_vvSetEsc(fld.value)}" oninput="vvPtSetChanged(this)"`; html += `
-
${_vvSetEsc(fld.key)}
`; +
${_vvSetEsc(fld.key)}${isArr ? ' list' : ''}
`; if (fld.desc) html += `
${_vvSetEsc(fld.desc)}
`; - html += `
`; + html += isArr + ? `` + : ``; + html += `
`; } html += `
`; } - return html || '
No scalar settings available.
'; + return html || '
No settings available.
'; } function vvPtToggleNode(hdr) { @@ -1304,8 +1223,6 @@ function _render(data) { // Actions document.getElementById('vv-pt-actions-body').innerHTML = _renderActions(nodes, cfg); - // Array settings cards above Actions — load once - _vvInitArrayCards(); // Settings panel — host1 only document.getElementById('vv-pt-settings-card').style.display = isOwner ? '' : 'none';