Docker tab: own config file, folder.view3 becomes optional sync target
- Primary store moved to /boot/config/plugins/varaverk/docker_folders.json - No dependency on folder.view3 plugin being installed - Auto-imports folder.view3 JSON on first run if it exists (one-time bootstrap) - Mirrors writes to folder.view3 JSON only if that plugin's directory is present - Toolbar shows '⇄ folder.view3' badge when sync is active
This commit is contained in:
@@ -1,24 +1,41 @@
|
||||
<?php
|
||||
// Docker tab — folder management and container inventory
|
||||
// Reads/writes /boot/config/plugins/folder.view3/docker.json (shared with folder.view3 plugin)
|
||||
// Primary store: /boot/config/plugins/varaverk/docker_folders.json (Varaverk-owned, no external deps)
|
||||
// Optional sync: /boot/config/plugins/folder.view3/docker.json (only if folder.view3 is installed)
|
||||
// Reads/writes HOST*_DOCKER_FOLDER_MAP in host*.conf (used by onboard scripts)
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
define('VV_DOCKER_JSON', '/boot/config/plugins/folder.view3/docker.json');
|
||||
define('VV_DOCKER_JSON', '/boot/config/plugins/varaverk/docker_folders.json');
|
||||
define('VV_FV3_JSON', '/boot/config/plugins/folder.view3/docker.json');
|
||||
|
||||
// ── JSON helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
function vv_dk_read_json(): array {
|
||||
// Bootstrap: if our file doesn't exist yet but folder.view3's does, import it once
|
||||
if (!file_exists(VV_DOCKER_JSON) && file_exists(VV_FV3_JSON)) {
|
||||
$imported = json_decode(file_get_contents(VV_FV3_JSON), true) ?: [];
|
||||
vv_dk_write_json($imported);
|
||||
return $imported;
|
||||
}
|
||||
if (!file_exists(VV_DOCKER_JSON)) return [];
|
||||
return json_decode(file_get_contents(VV_DOCKER_JSON), true) ?: [];
|
||||
}
|
||||
|
||||
function vv_dk_write_json(array $data): bool {
|
||||
$path = VV_DOCKER_JSON;
|
||||
$tmp = $path . '.vv.tmp';
|
||||
@mkdir(dirname($path), 0755, true);
|
||||
$tmp = $path . '.vv.tmp';
|
||||
if (file_put_contents($tmp, json_encode($data, JSON_UNESCAPED_SLASHES)) === false) return false;
|
||||
return rename($tmp, $path);
|
||||
if (!rename($tmp, $path)) return false;
|
||||
|
||||
// Mirror to folder.view3 if installed — keeps both in sync for users who want both UIs
|
||||
if (file_exists(dirname(VV_FV3_JSON))) {
|
||||
$t = VV_FV3_JSON . '.vv.tmp';
|
||||
@file_put_contents($t, json_encode($data, JSON_UNESCAPED_SLASHES));
|
||||
@rename($t, VV_FV3_JSON);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function vv_dk_gen_id(): string {
|
||||
@@ -157,7 +174,7 @@ function vv_dk_all(): array {
|
||||
'ungrouped' => $ungrouped,
|
||||
'conf_map' => $confMap,
|
||||
'drift' => $drift,
|
||||
'json_path' => VV_DOCKER_JSON,
|
||||
'fv3_synced'=> file_exists(dirname(VV_FV3_JSON)),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<button class="vv-dk-btn warn" id="vv-dk-sync-c2j" title="Apply conf desired state to folder.view3 JSON">Sync conf → JSON</button>
|
||||
<button class="vv-dk-btn prim" id="vv-dk-sync-j2c" title="Capture current JSON state back to conf">Sync JSON → conf</button>
|
||||
<button class="vv-dk-btn" id="vv-dk-edit-toggle">Edit folders</button>
|
||||
<span style="font-size:10px;color:#2a4a2a;" id="vv-dk-fv3"></span>
|
||||
<span class="vv-dk-ts" id="vv-dk-ts"></span>
|
||||
</div>
|
||||
|
||||
@@ -159,6 +160,9 @@ function _render(data) {
|
||||
const ts = data.ts ? new Date(data.ts * 1000).toLocaleString([], {month:'numeric',day:'numeric',year:'numeric',hour:'2-digit',minute:'2-digit',second:'2-digit'}) : '';
|
||||
document.getElementById('vv-dk-ts').textContent = ts ? 'Updated: ' + ts : '';
|
||||
|
||||
const fv3El = document.getElementById('vv-dk-fv3');
|
||||
if (fv3El) fv3El.textContent = data.fv3_synced ? '⇄ folder.view3' : '';
|
||||
|
||||
_bindEvents();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user