feat (ui): keuze default roof folder
This commit is contained in:
+50
-1
@@ -16,6 +16,7 @@
|
||||
syncScrolling: false,
|
||||
settings: {
|
||||
set_file_date_to_first_aired_date: false,
|
||||
default_media_root_path: null,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -38,6 +39,7 @@
|
||||
closeSettingsModalBtn: document.getElementById("closeSettingsModalBtn"),
|
||||
saveSettingsBtn: document.getElementById("saveSettingsBtn"),
|
||||
setFileDateToFirstAiredDateInput: document.getElementById("setFileDateToFirstAiredDateInput"),
|
||||
defaultMediaRootSelect: document.getElementById("defaultMediaRootSelect"),
|
||||
refreshEpisodesBtn: document.getElementById("refreshEpisodesBtn"),
|
||||
episodesList: document.getElementById("episodesList"),
|
||||
episodeMeta: document.getElementById("episodeMeta"),
|
||||
@@ -209,6 +211,36 @@
|
||||
|
||||
function applySettingsToForm() {
|
||||
el.setFileDateToFirstAiredDateInput.checked = !!state.settings.set_file_date_to_first_aired_date;
|
||||
if (el.defaultMediaRootSelect) {
|
||||
const wanted = state.settings.default_media_root_path || "";
|
||||
el.defaultMediaRootSelect.value = wanted;
|
||||
if (el.defaultMediaRootSelect.value !== wanted) {
|
||||
el.defaultMediaRootSelect.value = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function populateDefaultRootOptions() {
|
||||
if (!el.defaultMediaRootSelect) return;
|
||||
const selectedValue = state.settings.default_media_root_path || "";
|
||||
|
||||
el.defaultMediaRootSelect.innerHTML = "";
|
||||
const auto = document.createElement("option");
|
||||
auto.value = "";
|
||||
auto.textContent = "Auto (first available)";
|
||||
el.defaultMediaRootSelect.appendChild(auto);
|
||||
|
||||
state.roots.forEach((root) => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = root.path || "";
|
||||
opt.textContent = `${root.id}: ${root.path}`;
|
||||
el.defaultMediaRootSelect.appendChild(opt);
|
||||
});
|
||||
|
||||
el.defaultMediaRootSelect.value = selectedValue;
|
||||
if (el.defaultMediaRootSelect.value !== selectedValue) {
|
||||
el.defaultMediaRootSelect.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function openSettingsModal() {
|
||||
@@ -224,13 +256,17 @@
|
||||
|
||||
async function loadSettings() {
|
||||
const data = await api("/api/session/settings");
|
||||
state.settings = data.settings || { set_file_date_to_first_aired_date: false };
|
||||
state.settings = data.settings || {
|
||||
set_file_date_to_first_aired_date: false,
|
||||
default_media_root_path: null,
|
||||
};
|
||||
applySettingsToForm();
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
const payload = {
|
||||
set_file_date_to_first_aired_date: !!el.setFileDateToFirstAiredDateInput.checked,
|
||||
default_media_root_path: (el.defaultMediaRootSelect.value || "").trim() || null,
|
||||
};
|
||||
const data = await api("/api/session/settings", {
|
||||
method: "PUT",
|
||||
@@ -239,10 +275,21 @@
|
||||
});
|
||||
state.settings = data.settings || payload;
|
||||
applySettingsToForm();
|
||||
await loadRoots();
|
||||
closeSettingsModal();
|
||||
out("Settings saved", data);
|
||||
}
|
||||
|
||||
function preferredRootId() {
|
||||
if (!state.roots.length) return "";
|
||||
const wantedPath = (state.settings.default_media_root_path || "").trim();
|
||||
if (wantedPath) {
|
||||
const match = state.roots.find((root) => (root.path || "") === wantedPath);
|
||||
if (match) return match.id;
|
||||
}
|
||||
return state.roots[0].id;
|
||||
}
|
||||
|
||||
function selectPair(index) {
|
||||
state.selectedPairIndex = index;
|
||||
renderSelectedEpisodes();
|
||||
@@ -311,7 +358,9 @@
|
||||
opt.textContent = `${root.id}: ${root.path}`;
|
||||
el.modalRootSelect.appendChild(opt);
|
||||
});
|
||||
populateDefaultRootOptions();
|
||||
if (state.roots.length) {
|
||||
el.modalRootSelect.value = preferredRootId();
|
||||
el.modalSubpathInput.value = "";
|
||||
await loadModalFolders();
|
||||
}
|
||||
|
||||
@@ -285,6 +285,23 @@ button.secondary {
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.settings-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.settings-field label {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.settings-field select {
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.settings-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user