0.6.2
This commit is contained in:
@@ -45,6 +45,11 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
this._restoreSelected = "";
|
this._restoreSelected = "";
|
||||||
this._restoring = false;
|
this._restoring = false;
|
||||||
this._restoreError = null;
|
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) {
|
set hass(hass) {
|
||||||
@@ -114,7 +119,13 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
this._update();
|
this._update();
|
||||||
|
|
||||||
try {
|
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) {
|
if (!resp?.ok) {
|
||||||
this._error = this._safeText(resp?.message) || "Install failed.";
|
this._error = this._safeText(resp?.message) || "Install failed.";
|
||||||
} else {
|
} else {
|
||||||
@@ -140,7 +151,13 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
this._update();
|
this._update();
|
||||||
|
|
||||||
try {
|
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) {
|
if (!resp?.ok) {
|
||||||
this._error = this._safeText(resp?.message) || "Update failed.";
|
this._error = this._safeText(resp?.message) || "Update failed.";
|
||||||
} else {
|
} else {
|
||||||
@@ -366,8 +383,41 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
this._readmeExpanded = false;
|
this._readmeExpanded = false;
|
||||||
this._readmeCanToggle = false;
|
this._readmeCanToggle = false;
|
||||||
|
|
||||||
|
// Versions dropdown
|
||||||
|
if (!(repoId in this._selectedVersionByRepoId)) {
|
||||||
|
this._selectedVersionByRepoId[repoId] = ""; // default = latest
|
||||||
|
}
|
||||||
|
|
||||||
this._update();
|
this._update();
|
||||||
this._loadReadme(repoId);
|
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) {
|
async _loadReadme(repoId) {
|
||||||
@@ -953,6 +1003,8 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
const r = this._detailRepo;
|
const r = this._detailRepo;
|
||||||
if (!r) return `<div class="card">No repository selected.</div>`;
|
if (!r) return `<div class="card">No repository selected.</div>`;
|
||||||
|
|
||||||
|
const repoId = this._safeId(r?.id) || this._detailRepoId || "";
|
||||||
|
|
||||||
const name = this._safeText(r?.name) || "Unnamed repository";
|
const name = this._safeText(r?.name) || "Unnamed repository";
|
||||||
const url = this._safeText(r?.url) || "";
|
const url = this._safeText(r?.url) || "";
|
||||||
const desc = this._safeText(r?.description) || "";
|
const desc = this._safeText(r?.description) || "";
|
||||||
@@ -1001,8 +1053,6 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const repoId = this._safeId(r?.id);
|
|
||||||
|
|
||||||
const installed = this._asBoolStrict(r?.installed);
|
const installed = this._asBoolStrict(r?.installed);
|
||||||
const installedVersion = this._safeText(r?.installed_version);
|
const installedVersion = this._safeText(r?.installed_version);
|
||||||
const installedDomains = Array.isArray(r?.installed_domains) ? r.installed_domains : [];
|
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 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 = `<option value="">Latest (recommended)</option>`;
|
||||||
|
if (selectedRef && !versions.some((v) => this._safeText(v?.ref) === selectedRef)) {
|
||||||
|
versionOptions += `<option value="${this._esc(selectedRef)}" selected>Selected: ${this._esc(selectedRef)}</option>`;
|
||||||
|
}
|
||||||
|
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 += `<option value="${this._esc(ref)}" ${sel}>${this._esc(label)}</option>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionSelect = `
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<div class="muted small" style="margin-bottom:6px;"><strong>Install version:</strong></div>
|
||||||
|
<select id="selVersion" ${busy ? "disabled" : ""} style="width:100%;">
|
||||||
|
${versionOptions}
|
||||||
|
</select>
|
||||||
|
${versionsLoading ? `<div class="muted small" style="margin-top:6px;">Loading versions…</div>` : ``}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
const installBtn = `<button class="primary" id="btnInstall" ${installed || busy ? "disabled" : ""}>${busyInstall ? "Installing…" : installed ? "Installed" : "Install"}</button>`;
|
const installBtn = `<button class="primary" id="btnInstall" ${installed || busy ? "disabled" : ""}>${busyInstall ? "Installing…" : installed ? "Installed" : "Install"}</button>`;
|
||||||
const updateBtn = `<button class="primary" id="btnUpdate" ${!updateAvailable || busy ? "disabled" : ""}>${busyUpdate ? "Updating…" : updateAvailable ? "Update" : "Up to date"}</button>`;
|
const updateBtn = `<button class="primary" id="btnUpdate" ${!updateAvailable || busy ? "disabled" : ""}>${busyUpdate ? "Updating…" : updateAvailable ? "Update" : "Up to date"}</button>`;
|
||||||
const uninstallBtn = `<button class="primary" id="btnUninstall" ${!installed || busy ? "disabled" : ""}>${busyUninstall ? "Uninstalling…" : "Uninstall"}</button>`;
|
const uninstallBtn = `<button class="primary" id="btnUninstall" ${!installed || busy ? "disabled" : ""}>${busyUninstall ? "Uninstalling…" : "Uninstall"}</button>`;
|
||||||
@@ -1067,6 +1143,8 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
<div style="margin-top:6px;"><strong>Domains:</strong> ${installedDomains.length ? this._esc(installedDomains.join(", ")) : "-"}</div>
|
<div style="margin-top:6px;"><strong>Domains:</strong> ${installedDomains.length ? this._esc(installedDomains.join(", ")) : "-"}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
${versionSelect}
|
||||||
|
|
||||||
<div class="row" style="margin-top:14px; gap:10px; flex-wrap:wrap;">
|
<div class="row" style="margin-top:14px; gap:10px; flex-wrap:wrap;">
|
||||||
${installBtn}
|
${installBtn}
|
||||||
${updateBtn}
|
${updateBtn}
|
||||||
@@ -1091,6 +1169,7 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
const btnRestore = root.getElementById("btnRestore");
|
const btnRestore = root.getElementById("btnRestore");
|
||||||
const btnRestart = root.getElementById("btnRestart");
|
const btnRestart = root.getElementById("btnRestart");
|
||||||
const btnReadmeToggle = root.getElementById("btnReadmeToggle");
|
const btnReadmeToggle = root.getElementById("btnReadmeToggle");
|
||||||
|
const selVersion = root.getElementById("selVersion");
|
||||||
|
|
||||||
if (btnInstall) {
|
if (btnInstall) {
|
||||||
btnInstall.addEventListener("click", () => {
|
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) {
|
if (btnUpdate) {
|
||||||
btnUpdate.addEventListener("click", () => {
|
btnUpdate.addEventListener("click", () => {
|
||||||
if (btnUpdate.disabled) return;
|
if (btnUpdate.disabled) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user