mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 21:17:47 +00:00
Move snapshot toggle to persistent checkbox
This commit is contained in:
parent
0e3eed0563
commit
0bfeb22209
@ -977,6 +977,7 @@ class HassioAddonInfo extends LitElement {
|
|||||||
showDialogSupervisorUpdate(this, {
|
showDialogSupervisorUpdate(this, {
|
||||||
supervisor: this.supervisor,
|
supervisor: this.supervisor,
|
||||||
name: this.addon.name,
|
name: this.addon.name,
|
||||||
|
slug: this.addon.slug,
|
||||||
version: this.addon.version_latest,
|
version: this.addon.version_latest,
|
||||||
snapshotParams: {
|
snapshotParams: {
|
||||||
name: `addon_${this.addon.slug}_${this.addon.version}`,
|
name: `addon_${this.addon.slug}_${this.addon.version}`,
|
||||||
|
@ -161,6 +161,7 @@ export class HassioUpdate extends LitElement {
|
|||||||
showDialogSupervisorUpdate(this, {
|
showDialogSupervisorUpdate(this, {
|
||||||
supervisor: this.supervisor,
|
supervisor: this.supervisor,
|
||||||
name: "Home Assistant Core",
|
name: "Home Assistant Core",
|
||||||
|
slug: "core",
|
||||||
version: this.supervisor.core.version_latest,
|
version: this.supervisor.core.version_latest,
|
||||||
snapshotParams: {
|
snapshotParams: {
|
||||||
name: `core_${this.supervisor.core.version}`,
|
name: `core_${this.supervisor.core.version}`,
|
||||||
|
@ -2,19 +2,32 @@ import "@material/mwc-button/mwc-button";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../src/common/dom/fire_event";
|
import { fireEvent } from "../../../../src/common/dom/fire_event";
|
||||||
|
import "../../../../src/components/ha-checkbox";
|
||||||
import "../../../../src/components/ha-circular-progress";
|
import "../../../../src/components/ha-circular-progress";
|
||||||
import "../../../../src/components/ha-dialog";
|
import "../../../../src/components/ha-dialog";
|
||||||
import "../../../../src/components/ha-settings-row";
|
import "../../../../src/components/ha-settings-row";
|
||||||
import "../../../../src/components/ha-svg-icon";
|
import "../../../../src/components/ha-svg-icon";
|
||||||
import "../../../../src/components/ha-switch";
|
|
||||||
import {
|
import {
|
||||||
extractApiErrorMessage,
|
extractApiErrorMessage,
|
||||||
ignoreSupervisorError,
|
ignoreSupervisorError,
|
||||||
} from "../../../../src/data/hassio/common";
|
} from "../../../../src/data/hassio/common";
|
||||||
|
import {
|
||||||
|
SupervisorFrontendPrefrences,
|
||||||
|
fetchSupervisorFrontendPreferences,
|
||||||
|
saveSupervisorFrontendPreferences,
|
||||||
|
} from "../../../../src/data/supervisor/supervisor";
|
||||||
import { createHassioPartialSnapshot } from "../../../../src/data/hassio/snapshot";
|
import { createHassioPartialSnapshot } from "../../../../src/data/hassio/snapshot";
|
||||||
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
import { SupervisorDialogSupervisorUpdateParams } from "./show-dialog-update";
|
import { SupervisorDialogSupervisorUpdateParams } from "./show-dialog-update";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
|
||||||
|
const snapshot_before_update = memoizeOne(
|
||||||
|
(slug: string, frontendPrefrences: SupervisorFrontendPrefrences) =>
|
||||||
|
slug in frontendPrefrences.snapshot_before_update
|
||||||
|
? frontendPrefrences.snapshot_before_update[slug]
|
||||||
|
: true
|
||||||
|
);
|
||||||
|
|
||||||
@customElement("dialog-supervisor-update")
|
@customElement("dialog-supervisor-update")
|
||||||
class DialogSupervisorUpdate extends LitElement {
|
class DialogSupervisorUpdate extends LitElement {
|
||||||
@ -22,12 +35,12 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
|
|
||||||
@state() private _opened = false;
|
@state() private _opened = false;
|
||||||
|
|
||||||
@state() private _createSnapshot = true;
|
|
||||||
|
|
||||||
@state() private _action: "snapshot" | "update" | null = null;
|
@state() private _action: "snapshot" | "update" | null = null;
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
@state() private _frontendPrefrences?: SupervisorFrontendPrefrences;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
private _dialogParams?: SupervisorDialogSupervisorUpdateParams;
|
private _dialogParams?: SupervisorDialogSupervisorUpdateParams;
|
||||||
|
|
||||||
@ -36,14 +49,17 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this._opened = true;
|
this._opened = true;
|
||||||
this._dialogParams = params;
|
this._dialogParams = params;
|
||||||
|
this._frontendPrefrences = await fetchSupervisorFrontendPreferences(
|
||||||
|
this.hass
|
||||||
|
);
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._action = null;
|
this._action = null;
|
||||||
this._createSnapshot = true;
|
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._dialogParams = undefined;
|
this._dialogParams = undefined;
|
||||||
|
this._frontendPrefrences = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +72,7 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._dialogParams) {
|
if (!this._dialogParams || !this._frontendPrefrences) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
@ -82,6 +98,16 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-settings-row>
|
<ha-settings-row>
|
||||||
|
<ha-checkbox
|
||||||
|
.checked=${snapshot_before_update(
|
||||||
|
this._dialogParams.slug,
|
||||||
|
this._frontendPrefrences
|
||||||
|
)}
|
||||||
|
haptic
|
||||||
|
@click=${this._toggleSnapshot}
|
||||||
|
slot="prefix"
|
||||||
|
>
|
||||||
|
</ha-checkbox>
|
||||||
<span slot="heading">
|
<span slot="heading">
|
||||||
${this._dialogParams.supervisor.localize(
|
${this._dialogParams.supervisor.localize(
|
||||||
"dialog.update.snapshot"
|
"dialog.update.snapshot"
|
||||||
@ -94,12 +120,6 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
this._dialogParams.name
|
this._dialogParams.name
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
<ha-switch
|
|
||||||
.checked=${this._createSnapshot}
|
|
||||||
haptic
|
|
||||||
@click=${this._toggleSnapshot}
|
|
||||||
>
|
|
||||||
</ha-switch>
|
|
||||||
</ha-settings-row>
|
</ha-settings-row>
|
||||||
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
${this._dialogParams.supervisor.localize("common.cancel")}
|
${this._dialogParams.supervisor.localize("common.cancel")}
|
||||||
@ -133,12 +153,27 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _toggleSnapshot() {
|
private async _toggleSnapshot(): Promise<void> {
|
||||||
this._createSnapshot = !this._createSnapshot;
|
this._frontendPrefrences!.snapshot_before_update[
|
||||||
|
this._dialogParams!.slug
|
||||||
|
] = !snapshot_before_update(
|
||||||
|
this._dialogParams!.slug,
|
||||||
|
this._frontendPrefrences!
|
||||||
|
);
|
||||||
|
|
||||||
|
await saveSupervisorFrontendPreferences(
|
||||||
|
this.hass,
|
||||||
|
this._frontendPrefrences!
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _update() {
|
private async _update() {
|
||||||
if (this._createSnapshot) {
|
if (
|
||||||
|
snapshot_before_update(
|
||||||
|
this._dialogParams!.slug,
|
||||||
|
this._frontendPrefrences!
|
||||||
|
)
|
||||||
|
) {
|
||||||
this._action = "snapshot";
|
this._action = "snapshot";
|
||||||
try {
|
try {
|
||||||
await createHassioPartialSnapshot(
|
await createHassioPartialSnapshot(
|
||||||
|
@ -5,6 +5,7 @@ export interface SupervisorDialogSupervisorUpdateParams {
|
|||||||
supervisor: Supervisor;
|
supervisor: Supervisor;
|
||||||
name: string;
|
name: string;
|
||||||
version: string;
|
version: string;
|
||||||
|
slug: string;
|
||||||
snapshotParams: any;
|
snapshotParams: any;
|
||||||
updateHandler: () => Promise<void>;
|
updateHandler: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ class HassioCoreInfo extends LitElement {
|
|||||||
showDialogSupervisorUpdate(this, {
|
showDialogSupervisorUpdate(this, {
|
||||||
supervisor: this.supervisor,
|
supervisor: this.supervisor,
|
||||||
name: "Home Assistant Core",
|
name: "Home Assistant Core",
|
||||||
|
slug: "core",
|
||||||
version: this.supervisor.core.version_latest,
|
version: this.supervisor.core.version_latest,
|
||||||
snapshotParams: {
|
snapshotParams: {
|
||||||
name: `core_${this.supervisor.core.version}`,
|
name: `core_${this.supervisor.core.version}`,
|
||||||
|
@ -2,6 +2,7 @@ import { Connection, getCollection } from "home-assistant-js-websocket";
|
|||||||
import { Store } from "home-assistant-js-websocket/dist/store";
|
import { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
import { LocalizeFunc } from "../../common/translations/localize";
|
import { LocalizeFunc } from "../../common/translations/localize";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
|
import { fetchFrontendUserData, saveFrontendUserData } from "../frontend";
|
||||||
import { HassioAddonsInfo } from "../hassio/addon";
|
import { HassioAddonsInfo } from "../hassio/addon";
|
||||||
import { HassioHassOSInfo, HassioHostInfo } from "../hassio/host";
|
import { HassioHassOSInfo, HassioHostInfo } from "../hassio/host";
|
||||||
import { NetworkInfo } from "../hassio/network";
|
import { NetworkInfo } from "../hassio/network";
|
||||||
@ -13,6 +14,28 @@ import {
|
|||||||
} from "../hassio/supervisor";
|
} from "../hassio/supervisor";
|
||||||
import { SupervisorStore } from "./store";
|
import { SupervisorStore } from "./store";
|
||||||
|
|
||||||
|
export interface SupervisorFrontendPrefrences {
|
||||||
|
snapshot_before_update: Record<string, boolean>;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface FrontendUserData {
|
||||||
|
supervisor: SupervisorFrontendPrefrences;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fetchSupervisorFrontendPreferences = async (
|
||||||
|
hass: HomeAssistant
|
||||||
|
): Promise<SupervisorFrontendPrefrences> => {
|
||||||
|
const stored = await fetchFrontendUserData(hass.connection, "supervisor");
|
||||||
|
return stored || { snapshot_before_update: {} };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveSupervisorFrontendPreferences = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
data: SupervisorFrontendPrefrences
|
||||||
|
) => saveFrontendUserData(hass.connection, "supervisor", data);
|
||||||
|
|
||||||
export const supervisorWSbaseCommand = {
|
export const supervisorWSbaseCommand = {
|
||||||
type: "supervisor/api",
|
type: "supervisor/api",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user