diff --git a/custom_components/bahmcloud_store/panel/panel.js b/custom_components/bahmcloud_store/panel/panel.js index 17dd9da..9ac4440 100644 --- a/custom_components/bahmcloud_store/panel/panel.js +++ b/custom_components/bahmcloud_store/panel/panel.js @@ -45,6 +45,11 @@ class BahmcloudStorePanel extends HTMLElement { this._restoreSelected = ""; this._restoring = false; this._restoreError = null; + + // Phase C1: selectable install version + this._versionsCache = {}; // repo_id -> [{ref,label,source}, ...] + this._versionsLoadingRepoId = null; + this._selectedVersionByRepoId = {}; // repo_id -> ref ("" means latest) } set hass(hass) { @@ -114,7 +119,13 @@ class BahmcloudStorePanel extends HTMLElement { this._update(); try { - const resp = await this._hass.callApi("post", `bcs/install?repo_id=${encodeURIComponent(repoId)}`, {}); + const sel = this._safeText(this._selectedVersionByRepoId?.[repoId] || "").trim(); + const qv = sel ? `&version=${encodeURIComponent(sel)}` : ""; + const resp = await this._hass.callApi( + "post", + `bcs/install?repo_id=${encodeURIComponent(repoId)}${qv}`, + {}, + ); if (!resp?.ok) { this._error = this._safeText(resp?.message) || "Install failed."; } else { @@ -140,7 +151,13 @@ class BahmcloudStorePanel extends HTMLElement { this._update(); try { - const resp = await this._hass.callApi("post", `bcs/update?repo_id=${encodeURIComponent(repoId)}`, {}); + const sel = this._safeText(this._selectedVersionByRepoId?.[repoId] || "").trim(); + const qv = sel ? `&version=${encodeURIComponent(sel)}` : ""; + const resp = await this._hass.callApi( + "post", + `bcs/update?repo_id=${encodeURIComponent(repoId)}${qv}`, + {}, + ); if (!resp?.ok) { this._error = this._safeText(resp?.message) || "Update failed."; } else { @@ -366,8 +383,41 @@ class BahmcloudStorePanel extends HTMLElement { this._readmeExpanded = false; this._readmeCanToggle = false; + // Versions dropdown + if (!(repoId in this._selectedVersionByRepoId)) { + this._selectedVersionByRepoId[repoId] = ""; // default = latest + } + this._update(); this._loadReadme(repoId); + this._loadVersions(repoId); + } + + async _loadVersions(repoId) { + if (!this._hass) return; + if (!repoId) return; + + // Cache: avoid re-fetching repeatedly in the same session. + if (Array.isArray(this._versionsCache?.[repoId]) && this._versionsCache[repoId].length) { + return; + } + + this._versionsLoadingRepoId = repoId; + this._update(); + + try { + const resp = await this._hass.callApi("get", `bcs/versions?repo_id=${encodeURIComponent(repoId)}`); + if (resp?.ok && Array.isArray(resp.versions)) { + this._versionsCache[repoId] = resp.versions; + } else { + this._versionsCache[repoId] = []; + } + } catch (e) { + this._versionsCache[repoId] = []; + } finally { + this._versionsLoadingRepoId = null; + this._update(); + } } async _loadReadme(repoId) { @@ -953,6 +1003,8 @@ class BahmcloudStorePanel extends HTMLElement { const r = this._detailRepo; if (!r) return `
No repository selected.
`; + const repoId = this._safeId(r?.id) || this._detailRepoId || ""; + const name = this._safeText(r?.name) || "Unnamed repository"; const url = this._safeText(r?.url) || ""; const desc = this._safeText(r?.description) || ""; @@ -1001,8 +1053,6 @@ class BahmcloudStorePanel extends HTMLElement { `; - const repoId = this._safeId(r?.id); - const installed = this._asBoolStrict(r?.installed); const installedVersion = this._safeText(r?.installed_version); const installedDomains = Array.isArray(r?.installed_domains) ? r.installed_domains : []; @@ -1015,6 +1065,32 @@ class BahmcloudStorePanel extends HTMLElement { const updateAvailable = installed && !!latestVersion && (!installedVersion || latestVersion !== installedVersion); + const versions = Array.isArray(this._versionsCache?.[repoId]) ? this._versionsCache[repoId] : []; + const versionsLoading = this._versionsLoadingRepoId === repoId; + const selectedRef = this._safeText(this._selectedVersionByRepoId?.[repoId] || "").trim(); + + let versionOptions = ``; + if (selectedRef && !versions.some((v) => this._safeText(v?.ref) === selectedRef)) { + versionOptions += ``; + } + for (const v of versions) { + const ref = this._safeText(v?.ref); + if (!ref) continue; + const label = this._safeText(v?.label) || ref; + const sel = selectedRef === ref ? "selected" : ""; + versionOptions += ``; + } + + const versionSelect = ` +
+
Install version:
+ + ${versionsLoading ? `
Loading versions…
` : ``} +
+ `; + const installBtn = ``; const updateBtn = ``; const uninstallBtn = ``; @@ -1067,6 +1143,8 @@ class BahmcloudStorePanel extends HTMLElement {
Domains: ${installedDomains.length ? this._esc(installedDomains.join(", ")) : "-"}
+ ${versionSelect} +
${installBtn} ${updateBtn} @@ -1091,6 +1169,7 @@ class BahmcloudStorePanel extends HTMLElement { const btnRestore = root.getElementById("btnRestore"); const btnRestart = root.getElementById("btnRestart"); const btnReadmeToggle = root.getElementById("btnReadmeToggle"); + const selVersion = root.getElementById("selVersion"); if (btnInstall) { btnInstall.addEventListener("click", () => { @@ -1099,6 +1178,14 @@ class BahmcloudStorePanel extends HTMLElement { }); } + if (selVersion) { + selVersion.addEventListener("change", () => { + if (!this._detailRepoId) return; + const v = selVersion.value != null ? String(selVersion.value) : ""; + this._selectedVersionByRepoId[this._detailRepoId] = v; + }); + } + if (btnUpdate) { btnUpdate.addEventListener("click", () => { if (btnUpdate.disabled) return;