mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Calendar Card: Initial View Editor (#7135)
This commit is contained in:
parent
d9f42712e4
commit
e9141d82f3
@ -28,10 +28,13 @@ import { configElementStyle } from "./config-elements-style";
|
|||||||
const cardConfigStruct = object({
|
const cardConfigStruct = object({
|
||||||
type: string(),
|
type: string(),
|
||||||
title: optional(union([string(), boolean()])),
|
title: optional(union([string(), boolean()])),
|
||||||
|
initial_view: optional(string()),
|
||||||
theme: optional(string()),
|
theme: optional(string()),
|
||||||
entities: array(string()),
|
entities: array(string()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const views = ["dayGridMonth", "dayGridDay", "listWeek"];
|
||||||
|
|
||||||
@customElement("hui-calendar-card-editor")
|
@customElement("hui-calendar-card-editor")
|
||||||
export class HuiCalendarCardEditor extends LitElement
|
export class HuiCalendarCardEditor extends LitElement
|
||||||
implements LovelaceCardEditor {
|
implements LovelaceCardEditor {
|
||||||
@ -51,6 +54,10 @@ export class HuiCalendarCardEditor extends LitElement
|
|||||||
return this._config!.title || "";
|
return this._config!.title || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get _initial_view(): string {
|
||||||
|
return this._config!.initial_view || "dayGridMonth";
|
||||||
|
}
|
||||||
|
|
||||||
get _theme(): string {
|
get _theme(): string {
|
||||||
return this._config!.theme || "";
|
return this._config!.theme || "";
|
||||||
}
|
}
|
||||||
@ -74,6 +81,30 @@ export class HuiCalendarCardEditor extends LitElement
|
|||||||
.configValue=${"title"}
|
.configValue=${"title"}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></paper-input>
|
></paper-input>
|
||||||
|
<paper-dropdown-menu
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.inital_view"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<paper-listbox
|
||||||
|
slot="dropdown-content"
|
||||||
|
attr-for-selected="view"
|
||||||
|
.selected=${this._initial_view}
|
||||||
|
.configValue=${"initial_view"}
|
||||||
|
@iron-select=${this._viewChanged}
|
||||||
|
>
|
||||||
|
${views.map((view) => {
|
||||||
|
return html`
|
||||||
|
<paper-item .view=${view}
|
||||||
|
>${this.hass!.localize(
|
||||||
|
`ui.panel.lovelace.editor.card.calendar.views.${view}`
|
||||||
|
)}
|
||||||
|
</paper-item>
|
||||||
|
`;
|
||||||
|
})}
|
||||||
|
</paper-listbox>
|
||||||
|
</paper-dropdown-menu>
|
||||||
|
</div>
|
||||||
<hui-theme-select-editor
|
<hui-theme-select-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._theme}
|
.value=${this._theme}
|
||||||
@ -81,9 +112,10 @@ export class HuiCalendarCardEditor extends LitElement
|
|||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></hui-theme-select-editor>
|
></hui-theme-select-editor>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<h3>
|
<h3>
|
||||||
${"Calendar Entities" +
|
${this.hass.localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.calendar_entities"
|
||||||
|
) +
|
||||||
" (" +
|
" (" +
|
||||||
this.hass!.localize("ui.panel.lovelace.editor.card.config.required") +
|
this.hass!.localize("ui.panel.lovelace.editor.card.config.required") +
|
||||||
")"}
|
")"}
|
||||||
@ -125,6 +157,23 @@ export class HuiCalendarCardEditor extends LitElement
|
|||||||
|
|
||||||
fireEvent(this, "config-changed", { config: this._config });
|
fireEvent(this, "config-changed", { config: this._config });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _viewChanged(ev: CustomEvent): void {
|
||||||
|
if (!this._config || !this.hass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev.detail.item.view === "") {
|
||||||
|
this._config = { ...this._config };
|
||||||
|
delete this._config.initial_view;
|
||||||
|
} else {
|
||||||
|
this._config = {
|
||||||
|
...this._config,
|
||||||
|
initial_view: ev.detail.item.view,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
fireEvent(this, "config-changed", { config: this._config });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -2245,7 +2245,14 @@
|
|||||||
},
|
},
|
||||||
"calendar": {
|
"calendar": {
|
||||||
"name": "Calendar",
|
"name": "Calendar",
|
||||||
"description": "The Calendar card displays a calendar including day, week and list views"
|
"description": "The Calendar card displays a calendar including day, week and list views",
|
||||||
|
"inital_view": "Initial View",
|
||||||
|
"calendar_entities": "Calendar Entities",
|
||||||
|
"views": {
|
||||||
|
"dayGridMonth": "Month",
|
||||||
|
"dayGridDay": "Day",
|
||||||
|
"listWeek": "List"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"conditional": {
|
"conditional": {
|
||||||
"name": "Conditional",
|
"name": "Conditional",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user