Change Restart to be a button, update dialogs (#12499)

This commit is contained in:
Zack Barett 2022-04-28 15:43:00 -05:00 committed by GitHub
parent bdfb17d957
commit 1f3c23de29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 43 deletions

View File

@ -1,5 +1,3 @@
import { ActionDetail } from "@material/mwc-list";
import { mdiDotsVertical } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { canShowPage } from "../../../common/config/can_show_page"; import { canShowPage } from "../../../common/config/can_show_page";
@ -44,22 +42,18 @@ class HaConfigSystemNavigation extends LitElement {
back-path="/config" back-path="/config"
.header=${this.hass.localize("ui.panel.config.dashboard.system.main")} .header=${this.hass.localize("ui.panel.config.dashboard.system.main")}
> >
<ha-button-menu <mwc-button
corner="BOTTOM_START"
@action=${this._handleAction}
slot="toolbar-icon" slot="toolbar-icon"
> class="warning"
<ha-icon-button .label=${this.narrow
slot="trigger" ? this.hass.localize(
.label=${this.hass.localize("ui.common.overflow_menu")} "ui.panel.config.system_dashboard.restart_homeassistant_short"
.path=${mdiDotsVertical} )
></ha-icon-button> : this.hass.localize(
<mwc-list-item> "ui.panel.config.system_dashboard.restart_homeassistant"
${this.hass.localize( )}
"ui.panel.config.system_dashboard.restart_homeassistant" @click=${this._restart}
)} ></mwc-button>
</mwc-list-item>
</ha-button-menu>
<ha-config-section <ha-config-section
.narrow=${this.narrow} .narrow=${this.narrow}
.isWide=${this.isWide} .isWide=${this.isWide}
@ -77,28 +71,28 @@ class HaConfigSystemNavigation extends LitElement {
`; `;
} }
private _handleAction(ev: CustomEvent<ActionDetail>) { private _restart() {
switch (ev.detail.index) { showConfirmationDialog(this, {
case 0: title: this.hass.localize(
showConfirmationDialog(this, { "ui.panel.config.system_dashboard.confirm_restart_title"
text: this.hass.localize( ),
"ui.panel.config.system_dashboard.confirm_restart" text: this.hass.localize(
), "ui.panel.config.system_dashboard.confirm_restart_text"
confirm: () => { ),
this.hass confirmText: this.hass.localize(
.callService("homeassistant", "restart") "ui.panel.config.system_dashboard.restart_homeassistant_short"
.catch((reason) => { ),
showAlertDialog(this, { confirm: () => {
title: this.hass.localize( this.hass.callService("homeassistant", "restart").catch((reason) => {
"ui.panel.config.system_dashboard.restart_error" showAlertDialog(this, {
), title: this.hass.localize(
text: reason.message, "ui.panel.config.system_dashboard.restart_error"
}); ),
}); text: reason.message,
}, });
}); });
break; },
} });
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -167,8 +167,14 @@ export class DeveloperYamlConfig extends LitElement {
private _restart() { private _restart() {
showConfirmationDialog(this, { showConfirmationDialog(this, {
title: this.hass.localize(
"ui.panel.developer-tools.tabs.yaml.section.server_management.confirm_restart_title"
),
text: this.hass.localize( text: this.hass.localize(
"ui.panel.developer-tools.tabs.yaml.section.server_management.confirm_restart" "ui.panel.developer-tools.tabs.yaml.section.server_management.confirm_restart_text"
),
confirmText: this.hass.localize(
"ui.panel.developer-tools.tabs.yaml.section.server_management.restart"
), ),
confirm: () => { confirm: () => {
this.hass.callService("homeassistant", "restart").catch((reason) => { this.hass.callService("homeassistant", "restart").catch((reason) => {

View File

@ -3170,8 +3170,10 @@
"supervisor_stats": "Supervisor Stats" "supervisor_stats": "Supervisor Stats"
}, },
"system_dashboard": { "system_dashboard": {
"confirm_restart": "Are you sure you want to restart Home Assistant?", "confirm_restart_text": "Restarting Home Assistant will stop all your active dashboards, automations and scripts.",
"confirm_restart_title": "Restart Home Assistant?",
"restart_homeassistant": "Restart Home Assistant", "restart_homeassistant": "Restart Home Assistant",
"restart_homeassistant_short": "Restart",
"restart_error": "Failed to restart Home Assistant" "restart_error": "Failed to restart Home Assistant"
} }
}, },
@ -4203,10 +4205,9 @@
}, },
"server_management": { "server_management": {
"heading": "Home Assistant", "heading": "Home Assistant",
"introduction": "Restarting Home Assistant will stop your dashboard and automations. After the reboot, each configuration will be reloaded.", "confirm_restart_text": "Restarting Home Assistant will stop all your active dashboards, automations and scripts.",
"confirm_restart_title": "Restart Home Assistant?",
"restart": "Restart", "restart": "Restart",
"restart_home_assistant": "Restart Home Assistant",
"confirm_restart": "Are you sure you want to restart Home Assistant?",
"stop": "Stop", "stop": "Stop",
"confirm_stop": "Are you sure you want to stop Home Assistant?", "confirm_stop": "Are you sure you want to stop Home Assistant?",
"restart_error": "Failed to restart Home Assistant" "restart_error": "Failed to restart Home Assistant"