-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add edit/add/delete view #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add edit/add/delete view #2172
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7884b3b
Add edit/add/delete view
bramkragten 4e42b9f
Add delete
bramkragten 7d910d4
Comments
bramkragten d4cad81
Lint
bramkragten 5eb1ea9
Fix delete with numeric ids
bramkragten 4f1ac43
fix translations
bramkragten 3728735
add translations
bramkragten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { deleteView } from "../../../data/lovelace"; | ||
| import { HomeAssistant } from "../../../types"; | ||
|
|
||
| export async function confDeleteView( | ||
| hass: HomeAssistant, | ||
| viewId: string, | ||
| reloadLovelace: () => void | ||
| ): Promise<void> { | ||
| if (!confirm("Are you sure you want to delete this view?")) { | ||
| return; | ||
| } | ||
| try { | ||
| await deleteView(hass, viewId); | ||
| reloadLovelace(); | ||
| } catch (err) { | ||
| alert(`Deleting failed: ${err.message}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element"; | ||
| import { TemplateResult } from "lit-html"; | ||
|
|
||
| import { HomeAssistant } from "../../../types"; | ||
| import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event"; | ||
| import { LovelaceViewConfig } from "../../../data/lovelace"; | ||
| import "./hui-edit-view"; | ||
| import "./hui-migrate-config"; | ||
|
|
||
| declare global { | ||
| // for fire event | ||
| interface HASSDomEvents { | ||
| "reload-lovelace": undefined; | ||
| "show-edit-view": EditViewDialogParams; | ||
| } | ||
| // for add event listener | ||
| interface HTMLElementEventMap { | ||
| "reload-lovelace": HASSDomEvent<undefined>; | ||
| } | ||
| } | ||
|
|
||
| let registeredDialog = false; | ||
| const dialogShowEvent = "show-edit-view"; | ||
| const dialogTag = "hui-dialog-edit-view"; | ||
|
|
||
| export interface EditViewDialogParams { | ||
| viewConfig?: LovelaceViewConfig; | ||
| add?: boolean; | ||
| reloadLovelace: () => void; | ||
| } | ||
|
|
||
| const registerEditViewDialog = (element: HTMLElement) => | ||
| fireEvent(element, "register-dialog", { | ||
| dialogShowEvent, | ||
| dialogTag, | ||
| dialogImport: () => import("./hui-dialog-edit-view"), | ||
| }); | ||
|
|
||
| export const showEditViewDialog = ( | ||
| element: HTMLElement, | ||
| editViewDialogParams: EditViewDialogParams | ||
| ) => { | ||
| if (!registeredDialog) { | ||
| registeredDialog = true; | ||
| registerEditViewDialog(element); | ||
| } | ||
| fireEvent(element, dialogShowEvent, editViewDialogParams); | ||
| }; | ||
|
|
||
| export class HuiDialogEditView extends LitElement { | ||
| protected hass?: HomeAssistant; | ||
| private _params?: EditViewDialogParams; | ||
|
|
||
| static get properties(): PropertyDeclarations { | ||
| return { | ||
| hass: {}, | ||
| _params: {}, | ||
| }; | ||
| } | ||
|
|
||
| public async showDialog(params: EditViewDialogParams): Promise<void> { | ||
| this._params = params; | ||
| await this.updateComplete; | ||
| (this.shadowRoot!.children[0] as any).showDialog(); | ||
| } | ||
|
|
||
| protected render(): TemplateResult { | ||
| if (!this._params) { | ||
| return html``; | ||
| } | ||
| if ( | ||
| !this._params.add && | ||
| this._params.viewConfig && | ||
| !this._params.viewConfig.id | ||
| ) { | ||
| return html` | ||
| <hui-migrate-config | ||
| .hass="${this.hass}" | ||
| @reload-lovelace="${this._params.reloadLovelace}" | ||
| ></hui-migrate-config> | ||
| `; | ||
| } | ||
| return html` | ||
| <hui-edit-view | ||
| .hass="${this.hass}" | ||
| .viewConfig="${this._params.viewConfig}" | ||
| .add="${this._params.add}" | ||
| @reload-lovelace="${this._params.reloadLovelace}" | ||
| @cancel-edit-view="${this._cancel}" | ||
| > | ||
| </hui-edit-view> | ||
| `; | ||
| } | ||
|
|
||
| private _cancel() { | ||
| this._params = { | ||
|
bramkragten marked this conversation as resolved.
Outdated
|
||
| add: undefined, | ||
| reloadLovelace: () => { | ||
| return; | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "hui-dialog-edit-view": HuiDialogEditView; | ||
| } | ||
| } | ||
|
|
||
| customElements.define(dialogTag, HuiDialogEditView); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.