mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Style fixes to lovelace config dashboard (#5055)
* Style fixes to lovelace config dashboard * Add standard panel and show which is default * Update dialog-lovelace-dashboard-detail.ts * Updated lovelace icon * Comments and adapt to backend changes
This commit is contained in:
parent
802db71400
commit
1a3b747d17
@ -449,7 +449,7 @@ export class HaDataTable extends BaseElement {
|
|||||||
|
|
||||||
private async _calcScrollHeight() {
|
private async _calcScrollHeight() {
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
this._scroller.style.maxHeight = `calc(100% - ${this._header.clientHeight}px)`;
|
this._scroller.style.height = `calc(100% - ${this._header.clientHeight}px)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult {
|
static get styles(): CSSResult {
|
||||||
@ -670,6 +670,9 @@ export class HaDataTable extends BaseElement {
|
|||||||
slot[name="header"] {
|
slot[name="header"] {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.secondary {
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import { classMap } from "lit-html/directives/class-map";
|
|||||||
// tslint:disable-next-line: no-duplicate-imports
|
// tslint:disable-next-line: no-duplicate-imports
|
||||||
import { PaperIconItemElement } from "@polymer/paper-item/paper-icon-item";
|
import { PaperIconItemElement } from "@polymer/paper-item/paper-icon-item";
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
import { computeRTL } from "../common/util/compute_rtl";
|
||||||
|
import { compare } from "../common/string/compare";
|
||||||
|
|
||||||
const SHOW_AFTER_SPACER = ["config", "developer-tools", "hassio"];
|
const SHOW_AFTER_SPACER = ["config", "developer-tools", "hassio"];
|
||||||
|
|
||||||
@ -51,6 +52,9 @@ const panelSorter = (a: PanelInfo, b: PanelInfo) => {
|
|||||||
const aLovelace = a.component_name === "lovelace";
|
const aLovelace = a.component_name === "lovelace";
|
||||||
const bLovelace = b.component_name === "lovelace";
|
const bLovelace = b.component_name === "lovelace";
|
||||||
|
|
||||||
|
if (aLovelace && bLovelace) {
|
||||||
|
return compare(a.title!, b.title!);
|
||||||
|
}
|
||||||
if (aLovelace && !bLovelace) {
|
if (aLovelace && !bLovelace) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -71,13 +75,7 @@ const panelSorter = (a: PanelInfo, b: PanelInfo) => {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// both not built in, sort by title
|
// both not built in, sort by title
|
||||||
if (a.title! < b.title!) {
|
return compare(a.title!, b.title!);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.title! > b.title!) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
};
|
||||||
const DEFAULT_PAGE = localStorage.defaultPage || DEFAULT_PANEL;
|
const DEFAULT_PAGE = localStorage.defaultPage || DEFAULT_PANEL;
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@ import {
|
|||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { HASSDomEvent } from "../common/dom/fire_event";
|
import { HASSDomEvent } from "../common/dom/fire_event";
|
||||||
|
|
||||||
|
export interface LovelacePanelConfig {
|
||||||
|
mode: "yaml" | "storage";
|
||||||
|
}
|
||||||
|
|
||||||
export interface LovelaceConfig {
|
export interface LovelaceConfig {
|
||||||
title?: string;
|
title?: string;
|
||||||
views: LovelaceViewConfig[];
|
views: LovelaceViewConfig[];
|
||||||
@ -31,7 +35,9 @@ interface LovelaceGenericDashboard {
|
|||||||
id: string;
|
id: string;
|
||||||
url_path: string;
|
url_path: string;
|
||||||
require_admin: boolean;
|
require_admin: boolean;
|
||||||
sidebar?: { icon: string; title: string };
|
show_in_sidebar: boolean;
|
||||||
|
icon?: string;
|
||||||
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LovelaceYamlDashboard extends LovelaceGenericDashboard {
|
export interface LovelaceYamlDashboard extends LovelaceGenericDashboard {
|
||||||
@ -45,7 +51,9 @@ export interface LovelaceStorageDashboard extends LovelaceGenericDashboard {
|
|||||||
|
|
||||||
export interface LovelaceDashboardMutableParams {
|
export interface LovelaceDashboardMutableParams {
|
||||||
require_admin: boolean;
|
require_admin: boolean;
|
||||||
sidebar: { icon: string; title: string } | null;
|
show_in_sidebar: boolean;
|
||||||
|
icon?: string;
|
||||||
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LovelaceDashboardCreateParams
|
export interface LovelaceDashboardCreateParams
|
||||||
|
@ -135,6 +135,7 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
return css`
|
return css`
|
||||||
ha-data-table {
|
ha-data-table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
--data-table-border-width: 0;
|
--data-table-border-width: 0;
|
||||||
}
|
}
|
||||||
:host(:not([narrow])) ha-data-table {
|
:host(:not([narrow])) ha-data-table {
|
||||||
|
@ -25,9 +25,9 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@property() private _params?: LovelaceDashboardDetailsDialogParams;
|
@property() private _params?: LovelaceDashboardDetailsDialogParams;
|
||||||
@property() private _urlPath!: LovelaceDashboard["url_path"];
|
@property() private _urlPath!: LovelaceDashboard["url_path"];
|
||||||
@property() private _showSidebar!: boolean;
|
@property() private _showInSidebar!: boolean;
|
||||||
@property() private _sidebarIcon!: string;
|
@property() private _icon!: string;
|
||||||
@property() private _sidebarTitle!: string;
|
@property() private _title!: string;
|
||||||
@property() private _requireAdmin!: LovelaceDashboard["require_admin"];
|
@property() private _requireAdmin!: LovelaceDashboard["require_admin"];
|
||||||
|
|
||||||
@property() private _error?: string;
|
@property() private _error?: string;
|
||||||
@ -38,17 +38,16 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._urlPath = this._params.urlPath || "";
|
||||||
if (this._params.dashboard) {
|
if (this._params.dashboard) {
|
||||||
this._urlPath = this._params.dashboard.url_path || "";
|
this._showInSidebar = !!this._params.dashboard.show_in_sidebar;
|
||||||
this._showSidebar = !!this._params.dashboard.sidebar;
|
this._icon = this._params.dashboard.icon || "";
|
||||||
this._sidebarIcon = this._params.dashboard.sidebar?.icon || "";
|
this._title = this._params.dashboard.title || "";
|
||||||
this._sidebarTitle = this._params.dashboard.sidebar?.title || "";
|
|
||||||
this._requireAdmin = this._params.dashboard.require_admin || false;
|
this._requireAdmin = this._params.dashboard.require_admin || false;
|
||||||
} else {
|
} else {
|
||||||
this._urlPath = "";
|
this._showInSidebar = true;
|
||||||
this._showSidebar = true;
|
this._icon = "";
|
||||||
this._sidebarIcon = "";
|
this._title = "";
|
||||||
this._sidebarTitle = "";
|
|
||||||
this._requireAdmin = false;
|
this._requireAdmin = false;
|
||||||
}
|
}
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
@ -59,6 +58,7 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
const urlInvalid = !/^[a-zA-Z0-9_-]+$/.test(this._urlPath);
|
const urlInvalid = !/^[a-zA-Z0-9_-]+$/.test(this._urlPath);
|
||||||
|
const titleInvalid = !this._urlPath.trim();
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@ -67,21 +67,25 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
escapeKeyAction
|
escapeKeyAction
|
||||||
.heading=${createCloseHeading(
|
.heading=${createCloseHeading(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._params.dashboard
|
this._params.urlPath
|
||||||
? this._sidebarTitle ||
|
? this._title ||
|
||||||
this.hass!.localize(
|
this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.edit_dashboard"
|
"ui.panel.config.lovelace.dashboards.detail.edit_dashboard"
|
||||||
)
|
)
|
||||||
: this.hass!.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.new_dashboard"
|
"ui.panel.config.lovelace.dashboards.detail.new_dashboard"
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${this._params.dashboard && !this._params.dashboard.id
|
${this._params.dashboard && !this._params.dashboard.id
|
||||||
? this.hass!.localize(
|
? this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.cant_edit_yaml"
|
"ui.panel.config.lovelace.dashboards.cant_edit_yaml"
|
||||||
)
|
)
|
||||||
|
: this._params.urlPath === "lovelace"
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.lovelace.dashboards.cant_edit_default"
|
||||||
|
)
|
||||||
: html`
|
: html`
|
||||||
${this._error
|
${this._error
|
||||||
? html`
|
? html`
|
||||||
@ -89,60 +93,60 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<ha-switch
|
<paper-input
|
||||||
.checked=${this._showSidebar}
|
.value=${this._title}
|
||||||
@change=${this._showSidebarChanged}
|
@value-changed=${this._titleChanged}
|
||||||
>${this.hass!.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.show_sidebar"
|
"ui.panel.config.lovelace.dashboards.detail.title"
|
||||||
)}</ha-switch
|
)}
|
||||||
>
|
@blur=${this._fillUrlPath}
|
||||||
${this._showSidebar
|
.invalid=${titleInvalid}
|
||||||
? html`
|
.errorMessage=${this.hass.localize(
|
||||||
<ha-icon-input
|
"ui.panel.config.lovelace.dashboards.detail.title_required"
|
||||||
.value=${this._sidebarIcon}
|
)}
|
||||||
@value-changed=${this._sidebarIconChanged}
|
></paper-input>
|
||||||
.label=${this.hass!.localize(
|
<ha-icon-input
|
||||||
"ui.panel.config.lovelace.dashboards.detail.icon"
|
.value=${this._icon}
|
||||||
)}
|
@value-changed=${this._iconChanged}
|
||||||
></ha-icon-input>
|
.label=${this.hass.localize(
|
||||||
<paper-input
|
"ui.panel.config.lovelace.dashboards.detail.icon"
|
||||||
.value=${this._sidebarTitle}
|
)}
|
||||||
@value-changed=${this._sidebarTitleChanged}
|
></ha-icon-input>
|
||||||
.label=${this.hass!.localize(
|
|
||||||
"ui.panel.config.lovelace.dashboards.detail.title"
|
|
||||||
)}
|
|
||||||
@blur=${this._fillUrlPath}
|
|
||||||
></paper-input>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
${!this._params.dashboard
|
${!this._params.dashboard
|
||||||
? html`
|
? html`
|
||||||
<paper-input
|
<paper-input
|
||||||
.value=${this._urlPath}
|
.value=${this._urlPath}
|
||||||
@value-changed=${this._urlChanged}
|
@value-changed=${this._urlChanged}
|
||||||
.label=${this.hass!.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.url"
|
"ui.panel.config.lovelace.dashboards.detail.url"
|
||||||
)}
|
)}
|
||||||
.errorMessage=${this.hass!.localize(
|
.errorMessage=${this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.url_error_msg"
|
"ui.panel.config.lovelace.dashboards.detail.url_error_msg"
|
||||||
)}
|
)}
|
||||||
.invalid=${urlInvalid}
|
.invalid=${urlInvalid}
|
||||||
></paper-input>
|
></paper-input>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
<ha-switch
|
||||||
|
.checked=${this._showInSidebar}
|
||||||
|
@change=${this._showSidebarChanged}
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.lovelace.dashboards.detail.show_sidebar"
|
||||||
|
)}
|
||||||
|
</ha-switch>
|
||||||
<ha-switch
|
<ha-switch
|
||||||
.checked=${this._requireAdmin}
|
.checked=${this._requireAdmin}
|
||||||
@change=${this._requireAdminChanged}
|
@change=${this._requireAdminChanged}
|
||||||
>${this.hass!.localize(
|
>${this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.require_admin"
|
"ui.panel.config.lovelace.dashboards.detail.require_admin"
|
||||||
)}</ha-switch
|
)}
|
||||||
>
|
</ha-switch>
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
${this._params.dashboard
|
${this._params.urlPath
|
||||||
? html`
|
? html`
|
||||||
${this._params.dashboard.id
|
${this._params.dashboard?.id
|
||||||
? html`
|
? html`
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="secondaryAction"
|
slot="secondaryAction"
|
||||||
@ -150,18 +154,26 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
@click=${this._deleteDashboard}
|
@click=${this._deleteDashboard}
|
||||||
.disabled=${this._submitting}
|
.disabled=${this._submitting}
|
||||||
>
|
>
|
||||||
${this.hass!.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.delete"
|
"ui.panel.config.lovelace.dashboards.detail.delete"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<mwc-button slot="secondaryAction" @click=${this._toggleDefault}>
|
<mwc-button
|
||||||
${this._params.dashboard.url_path === localStorage.defaultPage
|
slot="secondaryAction"
|
||||||
? this.hass!.localize(
|
@click=${this._toggleDefault}
|
||||||
|
.disabled=${this._params.urlPath === "lovelace" &&
|
||||||
|
(!localStorage.defaultPage ||
|
||||||
|
localStorage.defaultPage === "lovelace")}
|
||||||
|
>
|
||||||
|
${this._params.urlPath === localStorage.defaultPage ||
|
||||||
|
(this._params.urlPath === "lovelace" &&
|
||||||
|
!localStorage.defaultPage)
|
||||||
|
? this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.remove_default"
|
"ui.panel.config.lovelace.dashboards.detail.remove_default"
|
||||||
)
|
)
|
||||||
: this.hass!.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.set_default"
|
"ui.panel.config.lovelace.dashboards.detail.set_default"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
@ -170,15 +182,15 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
<mwc-button
|
<mwc-button
|
||||||
slot="primaryAction"
|
slot="primaryAction"
|
||||||
@click="${this._updateDashboard}"
|
@click="${this._updateDashboard}"
|
||||||
.disabled=${urlInvalid || this._submitting}
|
.disabled=${urlInvalid || titleInvalid || this._submitting}
|
||||||
>
|
>
|
||||||
${this._params.dashboard
|
${this._params.urlPath
|
||||||
? this._params.dashboard.id
|
? this._params.dashboard?.id
|
||||||
? this.hass!.localize(
|
? this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.update"
|
"ui.panel.config.lovelace.dashboards.detail.update"
|
||||||
)
|
)
|
||||||
: this.hass!.localize("ui.common.close")
|
: this.hass.localize("ui.common.close")
|
||||||
: this.hass!.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.detail.create"
|
"ui.panel.config.lovelace.dashboards.detail.create"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
@ -191,29 +203,29 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
this._urlPath = ev.detail.value;
|
this._urlPath = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _sidebarIconChanged(ev: PolymerChangedEvent<string>) {
|
private _iconChanged(ev: PolymerChangedEvent<string>) {
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._sidebarIcon = ev.detail.value;
|
this._icon = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _sidebarTitleChanged(ev: PolymerChangedEvent<string>) {
|
private _titleChanged(ev: PolymerChangedEvent<string>) {
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._sidebarTitle = ev.detail.value;
|
this._title = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _fillUrlPath() {
|
private _fillUrlPath() {
|
||||||
if (this._urlPath) {
|
if (this._urlPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parts = this._sidebarTitle.split(" ");
|
const parts = this._title.split(" ");
|
||||||
|
|
||||||
if (parts.length) {
|
if (parts.length) {
|
||||||
this._urlPath = parts[0].toLowerCase();
|
this._urlPath = parts.join("_").toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showSidebarChanged(ev: Event) {
|
private _showSidebarChanged(ev: Event) {
|
||||||
this._showSidebar = (ev.target as HaSwitch).checked;
|
this._showInSidebar = (ev.target as HaSwitch).checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _requireAdminChanged(ev: Event) {
|
private _requireAdminChanged(ev: Event) {
|
||||||
@ -221,7 +233,7 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _toggleDefault() {
|
private _toggleDefault() {
|
||||||
const urlPath = this._params?.dashboard?.url_path;
|
const urlPath = this._params?.urlPath;
|
||||||
if (!urlPath) {
|
if (!urlPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -234,13 +246,16 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _updateDashboard() {
|
private async _updateDashboard() {
|
||||||
|
if (this._params?.urlPath && !this._params.dashboard?.id) {
|
||||||
|
this._close();
|
||||||
|
}
|
||||||
this._submitting = true;
|
this._submitting = true;
|
||||||
try {
|
try {
|
||||||
const values: Partial<LovelaceDashboardMutableParams> = {
|
const values: Partial<LovelaceDashboardMutableParams> = {
|
||||||
require_admin: this._requireAdmin,
|
require_admin: this._requireAdmin,
|
||||||
sidebar: this._showSidebar
|
show_in_sidebar: this._showInSidebar,
|
||||||
? { icon: this._sidebarIcon, title: this._sidebarTitle }
|
icon: this._icon || undefined,
|
||||||
: null,
|
title: this._title,
|
||||||
};
|
};
|
||||||
if (this._params!.dashboard) {
|
if (this._params!.dashboard) {
|
||||||
await this._params!.updateDashboard(values);
|
await this._params!.updateDashboard(values);
|
||||||
@ -251,7 +266,7 @@ export class DialogLovelaceDashboardDetail extends LitElement {
|
|||||||
values as LovelaceDashboardCreateParams
|
values as LovelaceDashboardCreateParams
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this._params = undefined;
|
this._close();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._error = err?.message || "Unknown error";
|
this._error = err?.message || "Unknown error";
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
css,
|
css,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import {
|
import {
|
||||||
DataTableColumnContainer,
|
DataTableColumnContainer,
|
||||||
RowClickedEvent,
|
RowClickedEvent,
|
||||||
@ -24,6 +25,7 @@ import {
|
|||||||
updateDashboard,
|
updateDashboard,
|
||||||
deleteDashboard,
|
deleteDashboard,
|
||||||
LovelaceDashboardCreateParams,
|
LovelaceDashboardCreateParams,
|
||||||
|
LovelacePanelConfig,
|
||||||
} from "../../../../data/lovelace";
|
} from "../../../../data/lovelace";
|
||||||
import { showDashboardDetailDialog } from "./show-dialog-lovelace-dashboard-detail";
|
import { showDashboardDetailDialog } from "./show-dialog-lovelace-dashboard-detail";
|
||||||
import { compare } from "../../../../common/string/compare";
|
import { compare } from "../../../../common/string/compare";
|
||||||
@ -40,7 +42,7 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
@property() private _dashboards: LovelaceDashboard[] = [];
|
@property() private _dashboards: LovelaceDashboard[] = [];
|
||||||
|
|
||||||
private _columns = memoize(
|
private _columns = memoize(
|
||||||
(_language, dashboards): DataTableColumnContainer => {
|
(narrow: boolean, _language, dashboards): DataTableColumnContainer => {
|
||||||
const columns: DataTableColumnContainer = {
|
const columns: DataTableColumnContainer = {
|
||||||
icon: {
|
icon: {
|
||||||
title: "",
|
title: "",
|
||||||
@ -59,8 +61,41 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
direction: "asc",
|
direction: "asc",
|
||||||
|
template: (title, dashboard: any) => {
|
||||||
|
const titleTemplate = html`
|
||||||
|
${title}
|
||||||
|
${dashboard.default
|
||||||
|
? html`
|
||||||
|
<ha-icon
|
||||||
|
style="padding-left: 10px;"
|
||||||
|
icon="hass:check-circle-outline"
|
||||||
|
></ha-icon>
|
||||||
|
<paper-tooltip>
|
||||||
|
This is the default dashdoard.
|
||||||
|
</paper-tooltip>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
`;
|
||||||
|
return narrow
|
||||||
|
? html`
|
||||||
|
${titleTemplate}
|
||||||
|
<div class="secondary">
|
||||||
|
${this.hass.localize(
|
||||||
|
`ui.panel.config.lovelace.dashboards.conf_mode.${dashboard.mode}`
|
||||||
|
)}${dashboard.filename
|
||||||
|
? html`
|
||||||
|
- ${dashboard.filename}
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: titleTemplate;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mode: {
|
};
|
||||||
|
|
||||||
|
if (!narrow) {
|
||||||
|
columns.mode = {
|
||||||
title: this.hass.localize(
|
title: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.picker.headers.conf_mode"
|
"ui.panel.config.lovelace.dashboards.picker.headers.conf_mode"
|
||||||
),
|
),
|
||||||
@ -72,21 +107,17 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
`ui.panel.config.lovelace.dashboards.conf_mode.${mode}`
|
`ui.panel.config.lovelace.dashboards.conf_mode.${mode}`
|
||||||
) || mode}
|
) || mode}
|
||||||
`,
|
`,
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (dashboards.some((dashboard) => dashboard.mode === "yaml")) {
|
|
||||||
columns.filename = {
|
|
||||||
title: this.hass.localize(
|
|
||||||
"ui.panel.config.lovelace.dashboards.picker.headers.filename"
|
|
||||||
),
|
|
||||||
sortable: true,
|
|
||||||
filterable: true,
|
|
||||||
};
|
};
|
||||||
}
|
if (dashboards.some((dashboard) => dashboard.filename)) {
|
||||||
|
columns.filename = {
|
||||||
const columns2: DataTableColumnContainer = {
|
title: this.hass.localize(
|
||||||
require_admin: {
|
"ui.panel.config.lovelace.dashboards.picker.headers.filename"
|
||||||
|
),
|
||||||
|
sortable: true,
|
||||||
|
filterable: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
columns.require_admin = {
|
||||||
title: this.hass.localize(
|
title: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.picker.headers.require_admin"
|
"ui.panel.config.lovelace.dashboards.picker.headers.require_admin"
|
||||||
),
|
),
|
||||||
@ -95,13 +126,13 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
template: (requireAdmin: boolean) =>
|
template: (requireAdmin: boolean) =>
|
||||||
requireAdmin
|
requireAdmin
|
||||||
? html`
|
? html`
|
||||||
<ha-icon icon="hass:check-circle-outline"></ha-icon>
|
<ha-icon icon="hass:check"></ha-icon>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
-
|
-
|
||||||
`,
|
`,
|
||||||
},
|
};
|
||||||
sidebar: {
|
columns.show_in_sidebar = {
|
||||||
title: this.hass.localize(
|
title: this.hass.localize(
|
||||||
"ui.panel.config.lovelace.dashboards.picker.headers.sidebar"
|
"ui.panel.config.lovelace.dashboards.picker.headers.sidebar"
|
||||||
),
|
),
|
||||||
@ -109,39 +140,62 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
template: (sidebar) =>
|
template: (sidebar) =>
|
||||||
sidebar
|
sidebar
|
||||||
? html`
|
? html`
|
||||||
<ha-icon icon="hass:check-circle-outline"></ha-icon>
|
<ha-icon icon="hass:check"></ha-icon>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
-
|
-
|
||||||
`,
|
`,
|
||||||
},
|
};
|
||||||
url_path: {
|
}
|
||||||
title: "",
|
|
||||||
type: "icon",
|
columns.url_path = {
|
||||||
filterable: true,
|
title: "",
|
||||||
template: (urlPath) =>
|
filterable: true,
|
||||||
html`
|
template: (urlPath) =>
|
||||||
<mwc-button .urlPath=${urlPath} @click=${this._navigate}
|
narrow
|
||||||
>${this.hass.localize(
|
? html`
|
||||||
"ui.panel.config.lovelace.dashboards.picker.open"
|
<paper-icon-button
|
||||||
)}</mwc-button
|
icon="hass:open-in-new"
|
||||||
>
|
.urlPath=${urlPath}
|
||||||
`,
|
@click=${this._navigate}
|
||||||
},
|
></paper-icon-button>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<mwc-button .urlPath=${urlPath} @click=${this._navigate}
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.lovelace.dashboards.picker.open"
|
||||||
|
)}</mwc-button
|
||||||
|
>
|
||||||
|
`,
|
||||||
};
|
};
|
||||||
return { ...columns, ...columns2 };
|
|
||||||
|
return columns;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
private _getItems = memoize((dashboards: LovelaceDashboard[]) => {
|
private _getItems = memoize((dashboards: LovelaceDashboard[]) => {
|
||||||
return dashboards.map((dashboard) => {
|
const defaultMode = (this.hass.panels?.lovelace
|
||||||
return {
|
?.config as LovelacePanelConfig).mode;
|
||||||
filename: "",
|
const isDefault =
|
||||||
...dashboard,
|
!localStorage.defaultPage || localStorage.defaultPage === "lovelace";
|
||||||
icon: dashboard.sidebar?.icon,
|
return [
|
||||||
title: dashboard.sidebar?.title || dashboard.url_path,
|
{
|
||||||
};
|
icon: "hass:view-dashboard",
|
||||||
});
|
title: this.hass.localize("panel.states"),
|
||||||
|
default: isDefault,
|
||||||
|
sidebar: isDefault,
|
||||||
|
require_admin: false,
|
||||||
|
url_path: "lovelace",
|
||||||
|
mode: defaultMode,
|
||||||
|
filename: defaultMode === "yaml" ? "ui-lovelace.yaml" : "",
|
||||||
|
},
|
||||||
|
...dashboards.map((dashboard) => {
|
||||||
|
return {
|
||||||
|
...dashboard,
|
||||||
|
default: localStorage.defaultPage === dashboard.url_path,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@ -158,7 +212,11 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
back-path="/config"
|
back-path="/config"
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.tabs=${lovelaceTabs}
|
.tabs=${lovelaceTabs}
|
||||||
.columns=${this._columns(this.hass.language, this._dashboards)}
|
.columns=${this._columns(
|
||||||
|
this.narrow,
|
||||||
|
this.hass.language,
|
||||||
|
this._dashboards
|
||||||
|
)}
|
||||||
.data=${this._getItems(this._dashboards)}
|
.data=${this._getItems(this._dashboards)}
|
||||||
@row-click=${this._editDashboard}
|
@row-click=${this._editDashboard}
|
||||||
id="url_path"
|
id="url_path"
|
||||||
@ -194,16 +252,20 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
|||||||
private _editDashboard(ev: CustomEvent) {
|
private _editDashboard(ev: CustomEvent) {
|
||||||
const urlPath = (ev.detail as RowClickedEvent).id;
|
const urlPath = (ev.detail as RowClickedEvent).id;
|
||||||
const dashboard = this._dashboards.find((res) => res.url_path === urlPath);
|
const dashboard = this._dashboards.find((res) => res.url_path === urlPath);
|
||||||
this._openDialog(dashboard);
|
this._openDialog(dashboard, urlPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addDashboard() {
|
private _addDashboard() {
|
||||||
this._openDialog();
|
this._openDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _openDialog(dashboard?: LovelaceDashboard): Promise<void> {
|
private async _openDialog(
|
||||||
|
dashboard?: LovelaceDashboard,
|
||||||
|
urlPath?: string
|
||||||
|
): Promise<void> {
|
||||||
showDashboardDetailDialog(this, {
|
showDashboardDetailDialog(this, {
|
||||||
dashboard,
|
dashboard,
|
||||||
|
urlPath,
|
||||||
createDashboard: async (values: LovelaceDashboardCreateParams) => {
|
createDashboard: async (values: LovelaceDashboardCreateParams) => {
|
||||||
const created = await createDashboard(this.hass!, values);
|
const created = await createDashboard(this.hass!, values);
|
||||||
this._dashboards = this._dashboards!.concat(
|
this._dashboards = this._dashboards!.concat(
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
|
|
||||||
export interface LovelaceDashboardDetailsDialogParams {
|
export interface LovelaceDashboardDetailsDialogParams {
|
||||||
dashboard?: LovelaceDashboard;
|
dashboard?: LovelaceDashboard;
|
||||||
|
urlPath?: string;
|
||||||
createDashboard: (values: LovelaceDashboardCreateParams) => Promise<unknown>;
|
createDashboard: (values: LovelaceDashboardCreateParams) => Promise<unknown>;
|
||||||
updateDashboard: (
|
updateDashboard: (
|
||||||
updates: Partial<LovelaceDashboardMutableParams>
|
updates: Partial<LovelaceDashboardMutableParams>
|
||||||
|
@ -215,6 +215,7 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
background: var(--lovelace-background);
|
background: var(--lovelace-background);
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
ha-fab {
|
ha-fab {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
@ -861,15 +861,17 @@
|
|||||||
"headers": {
|
"headers": {
|
||||||
"title": "Title",
|
"title": "Title",
|
||||||
"conf_mode": "Configuration method",
|
"conf_mode": "Configuration method",
|
||||||
|
"default": "Default",
|
||||||
"require_admin": "Admin only",
|
"require_admin": "Admin only",
|
||||||
"sidebar": "Show in sidebar",
|
"sidebar": "Show in sidebar",
|
||||||
"filename": "Filename"
|
"filename": "Filename"
|
||||||
},
|
},
|
||||||
"open": "Open dashboard",
|
"open": "Open",
|
||||||
"add_dashboard": "Add dashboard"
|
"add_dashboard": "Add dashboard"
|
||||||
},
|
},
|
||||||
"confirm_delete": "Are you sure you want to delete this dashboard?",
|
"confirm_delete": "Are you sure you want to delete this dashboard?",
|
||||||
"cant_edit_yaml": "Dashboards defined in YAML can not be edited from the UI. Change them in configuration.yaml.",
|
"cant_edit_yaml": "Dashboards defined in YAML can not be edited from the UI. Change them in configuration.yaml.",
|
||||||
|
"cant_edit_default": "The standard Lovelace dashboard can not be edited from the UI. You can hide it by setting another dashboard as default.",
|
||||||
"detail": {
|
"detail": {
|
||||||
"edit_dashboard": "Edit dashboard",
|
"edit_dashboard": "Edit dashboard",
|
||||||
"new_dashboard": "Add new dashboard",
|
"new_dashboard": "Add new dashboard",
|
||||||
@ -877,6 +879,7 @@
|
|||||||
"show_sidebar": "Show in sidebar",
|
"show_sidebar": "Show in sidebar",
|
||||||
"icon": "Sidebar icon",
|
"icon": "Sidebar icon",
|
||||||
"title": "Sidebar title",
|
"title": "Sidebar title",
|
||||||
|
"title_required": "Title is required.",
|
||||||
"url": "Url",
|
"url": "Url",
|
||||||
"url_error_msg": "The url can not contain spaces or special characters, except for _ and -",
|
"url_error_msg": "The url can not contain spaces or special characters, except for _ and -",
|
||||||
"require_admin": "Admin only",
|
"require_admin": "Admin only",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user