Add server restart/stop to quick bar command list (#7488)
This commit is contained in:
parent
efe97e8f51
commit
ba99d1a10d
|
@ -36,6 +36,10 @@ import "../../components/ha-header-bar";
|
|||
import { domainToName } from "../../data/integration";
|
||||
import { haStyleDialog } from "../../resources/styles";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import {
|
||||
ConfirmationDialogParams,
|
||||
showConfirmationDialog,
|
||||
} from "../generic/show-dialog-box";
|
||||
import { QuickBarParams } from "./show-dialog-quick-bar";
|
||||
|
||||
interface QuickBarItem extends ScorableTextItem {
|
||||
|
@ -276,9 +280,10 @@ export class QuickBar extends LitElement {
|
|||
}
|
||||
|
||||
private _generateCommandItems(): QuickBarItem[] {
|
||||
return [...this._generateReloadCommands()].sort((a, b) =>
|
||||
compare(a.text.toLowerCase(), b.text.toLowerCase())
|
||||
);
|
||||
return [
|
||||
...this._generateReloadCommands(),
|
||||
...this._generateServerControlCommands(),
|
||||
].sort((a, b) => compare(a.text.toLowerCase(), b.text.toLowerCase()));
|
||||
}
|
||||
|
||||
private _generateReloadCommands(): QuickBarItem[] {
|
||||
|
@ -297,6 +302,41 @@ export class QuickBar extends LitElement {
|
|||
}));
|
||||
}
|
||||
|
||||
private _generateServerControlCommands(): QuickBarItem[] {
|
||||
const serverActions = ["restart", "stop"];
|
||||
|
||||
return serverActions.map((action) =>
|
||||
this._generateConfirmationCommand(
|
||||
{
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.quick-bar.commands.server_control.perform_action",
|
||||
"action",
|
||||
this.hass.localize(
|
||||
`ui.dialogs.quick-bar.commands.server_control.${action}`
|
||||
)
|
||||
),
|
||||
icon: "hass:server",
|
||||
action: () => this.hass.callService("homeassistant", action),
|
||||
},
|
||||
this.hass.localize("ui.dialogs.generic.ok")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private _generateConfirmationCommand(
|
||||
item: QuickBarItem,
|
||||
confirmText: ConfirmationDialogParams["confirmText"]
|
||||
): QuickBarItem {
|
||||
return {
|
||||
...item,
|
||||
action: () =>
|
||||
showConfirmationDialog(this, {
|
||||
confirmText,
|
||||
confirm: item.action,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private _generateEntityItems(): QuickBarItem[] {
|
||||
return Object.keys(this.hass.states)
|
||||
.map((entityId) => ({
|
||||
|
|
|
@ -485,6 +485,11 @@
|
|||
"smtp": "[%key:ui::panel::config::server_control::section::reloading::smtp%]",
|
||||
"mqtt": "[%key:ui::panel::config::server_control::section::reloading::mqtt%]",
|
||||
"rpi_gpio": "[%key:ui::panel::config::server_control::section::reloading::rpi_gpio%]"
|
||||
},
|
||||
"server_control": {
|
||||
"perform_action": "{action} Server",
|
||||
"restart": "[%key:ui::panel::config::server_control::section::server_management::restart%]",
|
||||
"stop": "[%key:ui::panel::config::server_control::section::server_management::stop%]"
|
||||
}
|
||||
},
|
||||
"filter_placeholder": "Entity Filter"
|
||||
|
|
Loading…
Reference in New Issue