mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Block snapshots when system is not running (#8350)
This commit is contained in:
parent
b75dc0efe0
commit
48de8b0739
@ -22,7 +22,11 @@ import {
|
|||||||
fetchHassioSnapshotInfo,
|
fetchHassioSnapshotInfo,
|
||||||
HassioSnapshotDetail,
|
HassioSnapshotDetail,
|
||||||
} from "../../../../src/data/hassio/snapshot";
|
} from "../../../../src/data/hassio/snapshot";
|
||||||
import { showConfirmationDialog } from "../../../../src/dialogs/generic/show-dialog-box";
|
import { Supervisor } from "../../../../src/data/supervisor/supervisor";
|
||||||
|
import {
|
||||||
|
showAlertDialog,
|
||||||
|
showConfirmationDialog,
|
||||||
|
} from "../../../../src/dialogs/generic/show-dialog-box";
|
||||||
import { PolymerChangedEvent } from "../../../../src/polymer-types";
|
import { PolymerChangedEvent } from "../../../../src/polymer-types";
|
||||||
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
||||||
import { HomeAssistant } from "../../../../src/types";
|
import { HomeAssistant } from "../../../../src/types";
|
||||||
@ -75,6 +79,8 @@ interface FolderItem {
|
|||||||
class HassioSnapshotDialog extends LitElement {
|
class HassioSnapshotDialog extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public supervisor?: Supervisor;
|
||||||
|
|
||||||
@internalProperty() private _error?: string;
|
@internalProperty() private _error?: string;
|
||||||
|
|
||||||
@internalProperty() private _onboarding = false;
|
@internalProperty() private _onboarding = false;
|
||||||
@ -102,6 +108,7 @@ class HassioSnapshotDialog extends LitElement {
|
|||||||
|
|
||||||
this._dialogParams = params;
|
this._dialogParams = params;
|
||||||
this._onboarding = params.onboarding ?? false;
|
this._onboarding = params.onboarding ?? false;
|
||||||
|
this.supervisor = params.supervisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@ -298,6 +305,16 @@ class HassioSnapshotDialog extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _partialRestoreClicked() {
|
private async _partialRestoreClicked() {
|
||||||
|
if (
|
||||||
|
this.supervisor !== undefined &&
|
||||||
|
this.supervisor.info.state !== "running"
|
||||||
|
) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
title: "Could not restore snapshot",
|
||||||
|
text: `Restoring a snapshot is not possible right now because the system is in ${this.supervisor.info.state} state.`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
!(await showConfirmationDialog(this, {
|
!(await showConfirmationDialog(this, {
|
||||||
title: "Are you sure you want partially to restore this snapshot?",
|
title: "Are you sure you want partially to restore this snapshot?",
|
||||||
@ -359,6 +376,16 @@ class HassioSnapshotDialog extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fullRestoreClicked() {
|
private async _fullRestoreClicked() {
|
||||||
|
if (
|
||||||
|
this.supervisor !== undefined &&
|
||||||
|
this.supervisor.info.state !== "running"
|
||||||
|
) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
title: "Could not restore snapshot",
|
||||||
|
text: `Restoring a snapshot is not possible right now because the system is in ${this.supervisor.info.state} state.`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
!(await showConfirmationDialog(this, {
|
!(await showConfirmationDialog(this, {
|
||||||
title:
|
title:
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { fireEvent } from "../../../../src/common/dom/fire_event";
|
import { fireEvent } from "../../../../src/common/dom/fire_event";
|
||||||
|
import { Supervisor } from "../../../../src/data/supervisor/supervisor";
|
||||||
|
|
||||||
export interface HassioSnapshotDialogParams {
|
export interface HassioSnapshotDialogParams {
|
||||||
slug: string;
|
slug: string;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onboarding?: boolean;
|
onboarding?: boolean;
|
||||||
|
supervisor?: Supervisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showHassioSnapshotDialog = (
|
export const showHassioSnapshotDialog = (
|
||||||
|
@ -41,6 +41,7 @@ import {
|
|||||||
reloadHassioSnapshots,
|
reloadHassioSnapshots,
|
||||||
} from "../../../src/data/hassio/snapshot";
|
} from "../../../src/data/hassio/snapshot";
|
||||||
import { Supervisor } from "../../../src/data/supervisor/supervisor";
|
import { Supervisor } from "../../../src/data/supervisor/supervisor";
|
||||||
|
import { showAlertDialog } from "../../../src/dialogs/generic/show-dialog-box";
|
||||||
import "../../../src/layouts/hass-tabs-subpage";
|
import "../../../src/layouts/hass-tabs-subpage";
|
||||||
import { PolymerChangedEvent } from "../../../src/polymer-types";
|
import { PolymerChangedEvent } from "../../../src/polymer-types";
|
||||||
import { haStyle } from "../../../src/resources/styles";
|
import { haStyle } from "../../../src/resources/styles";
|
||||||
@ -211,7 +212,13 @@ class HassioSnapshots extends LitElement {
|
|||||||
: undefined}
|
: undefined}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
<ha-progress-button @click=${this._createSnapshot}>
|
<ha-progress-button
|
||||||
|
@click=${this._createSnapshot}
|
||||||
|
title="${this.supervisor.info.state !== "running"
|
||||||
|
? `Creating a snapshot is not possible right now because the system is in ${this.supervisor.info.state} state.`
|
||||||
|
: ""}"
|
||||||
|
.disabled=${this.supervisor.info.state !== "running"}
|
||||||
|
>
|
||||||
Create
|
Create
|
||||||
</ha-progress-button>
|
</ha-progress-button>
|
||||||
</div>
|
</div>
|
||||||
@ -325,6 +332,12 @@ class HassioSnapshots extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _createSnapshot(ev: CustomEvent): Promise<void> {
|
private async _createSnapshot(ev: CustomEvent): Promise<void> {
|
||||||
|
if (this.supervisor.info.state !== "running") {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
title: "Could not create snapshot",
|
||||||
|
text: `Creating a snapshot is not possible right now because the system is in ${this.supervisor.info.state} state.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
const button = ev.currentTarget as any;
|
const button = ev.currentTarget as any;
|
||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
@ -386,6 +399,7 @@ class HassioSnapshots extends LitElement {
|
|||||||
private _snapshotClicked(ev) {
|
private _snapshotClicked(ev) {
|
||||||
showHassioSnapshotDialog(this, {
|
showHassioSnapshotDialog(this, {
|
||||||
slug: ev.currentTarget!.snapshot.slug,
|
slug: ev.currentTarget!.snapshot.slug,
|
||||||
|
supervisor: this.supervisor,
|
||||||
onDelete: () => this._updateSnapshots(),
|
onDelete: () => this._updateSnapshots(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -395,6 +409,7 @@ class HassioSnapshots extends LitElement {
|
|||||||
showSnapshot: (slug: string) =>
|
showSnapshot: (slug: string) =>
|
||||||
showHassioSnapshotDialog(this, {
|
showHassioSnapshotDialog(this, {
|
||||||
slug,
|
slug,
|
||||||
|
supervisor: this.supervisor,
|
||||||
onDelete: () => this._updateSnapshots(),
|
onDelete: () => this._updateSnapshots(),
|
||||||
}),
|
}),
|
||||||
reloadSnapshot: () => this.refreshData(),
|
reloadSnapshot: () => this.refreshData(),
|
||||||
|
@ -49,6 +49,15 @@ export type HassioInfo = {
|
|||||||
hostname: string;
|
hostname: string;
|
||||||
logging: string;
|
logging: string;
|
||||||
machine: string;
|
machine: string;
|
||||||
|
state:
|
||||||
|
| "initialize"
|
||||||
|
| "setup"
|
||||||
|
| "startup"
|
||||||
|
| "running"
|
||||||
|
| "freeze"
|
||||||
|
| "shutdown"
|
||||||
|
| "stopping"
|
||||||
|
| "close";
|
||||||
operating_system: string;
|
operating_system: string;
|
||||||
supervisor: string;
|
supervisor: string;
|
||||||
supported: boolean;
|
supported: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user