mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Allow delete floor (#20208)
* Allow delete floor * Update src/translations/en.json Co-authored-by: Paul Bottein <paul.bottein@gmail.com> --------- Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
parent
7427e17926
commit
705c0e58fc
@ -1,4 +1,10 @@
|
|||||||
import { mdiHelpCircle, mdiPencil, mdiPlus } from "@mdi/js";
|
import {
|
||||||
|
mdiDelete,
|
||||||
|
mdiDotsVertical,
|
||||||
|
mdiHelpCircle,
|
||||||
|
mdiPencil,
|
||||||
|
mdiPlus,
|
||||||
|
} from "@mdi/js";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -11,6 +17,7 @@ import {
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
|
import { ActionDetail } from "@material/mwc-list";
|
||||||
import { formatListWithAnds } from "../../../common/string/format-list";
|
import { formatListWithAnds } from "../../../common/string/format-list";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -22,11 +29,15 @@ import {
|
|||||||
import {
|
import {
|
||||||
FloorRegistryEntry,
|
FloorRegistryEntry,
|
||||||
createFloorRegistryEntry,
|
createFloorRegistryEntry,
|
||||||
|
deleteFloorRegistryEntry,
|
||||||
getFloorAreaLookup,
|
getFloorAreaLookup,
|
||||||
subscribeFloorRegistry,
|
subscribeFloorRegistry,
|
||||||
updateFloorRegistryEntry,
|
updateFloorRegistryEntry,
|
||||||
} from "../../../data/floor_registry";
|
} from "../../../data/floor_registry";
|
||||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
import {
|
||||||
|
showAlertDialog,
|
||||||
|
showConfirmationDialog,
|
||||||
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../layouts/hass-tabs-subpage";
|
import "../../../layouts/hass-tabs-subpage";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import "../ha-config-section";
|
import "../ha-config-section";
|
||||||
@ -148,11 +159,34 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
${floor.name}
|
${floor.name}
|
||||||
</h2>
|
</h2>
|
||||||
<ha-icon-button
|
<ha-button-menu
|
||||||
.path=${mdiPencil}
|
|
||||||
@click=${this._editFloor}
|
|
||||||
.floor=${floor}
|
.floor=${floor}
|
||||||
></ha-icon-button>
|
@action=${this._handleFloorAction}
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
slot="trigger"
|
||||||
|
.path=${mdiDotsVertical}
|
||||||
|
></ha-icon-button>
|
||||||
|
<ha-list-item graphic="icon"
|
||||||
|
><ha-svg-icon
|
||||||
|
.path=${mdiPencil}
|
||||||
|
slot="graphic"
|
||||||
|
></ha-svg-icon
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.areas.picker.floor.edit_floor"
|
||||||
|
)}</ha-list-item
|
||||||
|
>
|
||||||
|
<ha-list-item class="warning" graphic="icon"
|
||||||
|
><ha-svg-icon
|
||||||
|
class="warning"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
slot="graphic"
|
||||||
|
></ha-svg-icon
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.areas.picker.floor.delete_floor"
|
||||||
|
)}</ha-list-item
|
||||||
|
>
|
||||||
|
</ha-button-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="areas">
|
<div class="areas">
|
||||||
${floor.areas.map((area) => this._renderArea(area))}
|
${floor.areas.map((area) => this._renderArea(area))}
|
||||||
@ -248,15 +282,43 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) {
|
|||||||
loadAreaRegistryDetailDialog();
|
loadAreaRegistryDetailDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleFloorAction(ev: CustomEvent<ActionDetail>) {
|
||||||
|
const floor = (ev.currentTarget as any).floor;
|
||||||
|
switch (ev.detail.index) {
|
||||||
|
case 0:
|
||||||
|
this._editFloor(floor);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this._deleteFloor(floor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _createFloor() {
|
private _createFloor() {
|
||||||
this._openFloorDialog();
|
this._openFloorDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _editFloor(ev) {
|
private _editFloor(floor) {
|
||||||
const floor = ev.currentTarget.floor;
|
|
||||||
this._openFloorDialog(floor);
|
this._openFloorDialog(floor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _deleteFloor(floor) {
|
||||||
|
const confirm = await showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.areas.picker.floor.confirm_delete"
|
||||||
|
),
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.config.areas.picker.floor.confirm_delete_text"
|
||||||
|
),
|
||||||
|
confirmText: this.hass.localize("ui.common.delete"),
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
if (!confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await deleteFloorRegistryEntry(this.hass, floor.floor_id);
|
||||||
|
}
|
||||||
|
|
||||||
private _createArea() {
|
private _createArea() {
|
||||||
this._openAreaDialog();
|
this._openAreaDialog();
|
||||||
}
|
}
|
||||||
@ -365,6 +427,9 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) {
|
|||||||
--primary-color: var(--secondary-text-color);
|
--primary-color: var(--secondary-text-color);
|
||||||
margin-inline-end: 8px;
|
margin-inline-end: 8px;
|
||||||
}
|
}
|
||||||
|
.warning {
|
||||||
|
color: var(--error-color);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2008,7 +2008,13 @@
|
|||||||
"no_areas": "Looks like you have no areas yet!",
|
"no_areas": "Looks like you have no areas yet!",
|
||||||
"unassigned_areas": "Unassigned areas",
|
"unassigned_areas": "Unassigned areas",
|
||||||
"create_area": "Create Area",
|
"create_area": "Create Area",
|
||||||
"create_floor": "Create floor"
|
"create_floor": "Create floor",
|
||||||
|
"floor": {
|
||||||
|
"edit_floor": "Edit floor",
|
||||||
|
"delete_floor": "Delete floor",
|
||||||
|
"confirm_delete": "Delete floor?",
|
||||||
|
"confirm_delete_text": "Removing the floor will unassign all areas from it."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"editor": {
|
"editor": {
|
||||||
"create_area": "Create area",
|
"create_area": "Create area",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user