mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Simplify calendar "listWeek" and enable for "initial_view" (#9993)
fixes undefined
This commit is contained in:
parent
b644407260
commit
0ae8246d8a
@ -29,28 +29,29 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { useAmPm } from "../../common/datetime/use_am_pm";
|
import { useAmPm } from "../../common/datetime/use_am_pm";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { supportsFeature } from "../../common/entity/supports-feature";
|
||||||
|
import { LocalizeFunc } from "../../common/translations/localize";
|
||||||
|
import { computeRTLDirection } from "../../common/util/compute_rtl";
|
||||||
import "../../components/ha-button-toggle-group";
|
import "../../components/ha-button-toggle-group";
|
||||||
import "../../components/ha-fab";
|
import "../../components/ha-fab";
|
||||||
import "../../components/ha-icon-button-prev";
|
|
||||||
import "../../components/ha-icon-button-next";
|
import "../../components/ha-icon-button-next";
|
||||||
|
import "../../components/ha-icon-button-prev";
|
||||||
|
import type {
|
||||||
|
Calendar as CalendarData,
|
||||||
|
CalendarEvent,
|
||||||
|
} from "../../data/calendar";
|
||||||
|
import { CalendarEntityFeature } from "../../data/calendar";
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
import { computeRTLDirection } from "../../common/util/compute_rtl";
|
|
||||||
import type {
|
import type {
|
||||||
CalendarViewChanged,
|
CalendarViewChanged,
|
||||||
FullCalendarView,
|
FullCalendarView,
|
||||||
HomeAssistant,
|
HomeAssistant,
|
||||||
ToggleButton,
|
ToggleButton,
|
||||||
} from "../../types";
|
} from "../../types";
|
||||||
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
|
||||||
import { supportsFeature } from "../../common/entity/supports-feature";
|
|
||||||
import { showCalendarEventDetailDialog } from "./show-dialog-calendar-event-detail";
|
import { showCalendarEventDetailDialog } from "./show-dialog-calendar-event-detail";
|
||||||
import type {
|
|
||||||
Calendar as CalendarData,
|
|
||||||
CalendarEvent,
|
|
||||||
} from "../../data/calendar";
|
|
||||||
import { CalendarEntityFeature } from "../../data/calendar";
|
|
||||||
import { showCalendarEventEditDialog } from "./show-dialog-calendar-event-editor";
|
import { showCalendarEventEditDialog } from "./show-dialog-calendar-event-editor";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -62,15 +63,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getListWeekRange = (currentDate: Date): { start: Date; end: Date } => {
|
|
||||||
const startDate = new Date(currentDate.valueOf());
|
|
||||||
const endDate = new Date(currentDate.valueOf());
|
|
||||||
|
|
||||||
endDate.setDate(endDate.getDate() + 7);
|
|
||||||
|
|
||||||
return { start: startDate, end: endDate };
|
|
||||||
};
|
|
||||||
|
|
||||||
const defaultFullCalendarConfig: CalendarOptions = {
|
const defaultFullCalendarConfig: CalendarOptions = {
|
||||||
headerToolbar: false,
|
headerToolbar: false,
|
||||||
plugins: [dayGridPlugin, listPlugin, interactionPlugin],
|
plugins: [dayGridPlugin, listPlugin, interactionPlugin],
|
||||||
@ -80,19 +72,13 @@ const defaultFullCalendarConfig: CalendarOptions = {
|
|||||||
eventDisplay: "list-item",
|
eventDisplay: "list-item",
|
||||||
locales: allLocales,
|
locales: allLocales,
|
||||||
views: {
|
views: {
|
||||||
list: {
|
listWeek: {
|
||||||
visibleRange: getListWeekRange,
|
type: "list",
|
||||||
|
duration: { days: 7 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewButtons: ToggleButton[] = [
|
|
||||||
{ label: "Month View", value: "dayGridMonth", iconPath: mdiViewModule },
|
|
||||||
{ label: "Week View", value: "dayGridWeek", iconPath: mdiViewWeek },
|
|
||||||
{ label: "Day View", value: "dayGridDay", iconPath: mdiViewDay },
|
|
||||||
{ label: "List View", value: "list", iconPath: mdiViewAgenda },
|
|
||||||
];
|
|
||||||
|
|
||||||
export class HAFullCalendar extends LitElement {
|
export class HAFullCalendar extends LitElement {
|
||||||
public hass!: HomeAssistant;
|
public hass!: HomeAssistant;
|
||||||
|
|
||||||
@ -106,12 +92,15 @@ export class HAFullCalendar extends LitElement {
|
|||||||
"dayGridMonth",
|
"dayGridMonth",
|
||||||
"dayGridWeek",
|
"dayGridWeek",
|
||||||
"dayGridDay",
|
"dayGridDay",
|
||||||
|
"listWeek",
|
||||||
];
|
];
|
||||||
|
|
||||||
@property() public initialView: FullCalendarView = "dayGridMonth";
|
@property() public initialView: FullCalendarView = "dayGridMonth";
|
||||||
|
|
||||||
private calendar?: Calendar;
|
private calendar?: Calendar;
|
||||||
|
|
||||||
|
private _viewButtons?: ToggleButton[];
|
||||||
|
|
||||||
@state() private _activeView = this.initialView;
|
@state() private _activeView = this.initialView;
|
||||||
|
|
||||||
public updateSize(): void {
|
public updateSize(): void {
|
||||||
@ -119,7 +108,10 @@ export class HAFullCalendar extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const viewToggleButtons = this._viewToggleButtons(this.views);
|
const viewToggleButtons = this._viewToggleButtons(
|
||||||
|
this.views,
|
||||||
|
this.hass.localize
|
||||||
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this.calendar
|
${this.calendar
|
||||||
@ -349,11 +341,44 @@ export class HAFullCalendar extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _viewToggleButtons = memoize((views) =>
|
private _viewToggleButtons = memoize((views, localize: LocalizeFunc) => {
|
||||||
viewButtons.filter((button) =>
|
if (!this._viewButtons) {
|
||||||
|
this._viewButtons = [
|
||||||
|
{
|
||||||
|
label: localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.views.dayGridMonth"
|
||||||
|
),
|
||||||
|
value: "dayGridMonth",
|
||||||
|
iconPath: mdiViewModule,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.views.dayGridWeek"
|
||||||
|
),
|
||||||
|
value: "dayGridWeek",
|
||||||
|
iconPath: mdiViewWeek,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.views.dayGridDay"
|
||||||
|
),
|
||||||
|
value: "dayGridDay",
|
||||||
|
iconPath: mdiViewDay,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: localize(
|
||||||
|
"ui.panel.lovelace.editor.card.calendar.views.listWeek"
|
||||||
|
),
|
||||||
|
value: "listWeek",
|
||||||
|
iconPath: mdiViewAgenda,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._viewButtons.filter((button) =>
|
||||||
views.includes(button.value as FullCalendarView)
|
views.includes(button.value as FullCalendarView)
|
||||||
)
|
);
|
||||||
);
|
});
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
|
@ -119,8 +119,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const views: FullCalendarView[] = this._veryNarrow
|
const views: FullCalendarView[] = this._veryNarrow
|
||||||
? ["list"]
|
? ["listWeek"]
|
||||||
: ["list", "dayGridMonth", "dayGridDay"];
|
: ["dayGridMonth", "dayGridDay", "listWeek"];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
|
@ -31,7 +31,7 @@ const cardConfigStruct = assign(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const views = ["dayGridMonth", "dayGridDay", "list"] as const;
|
const views = ["dayGridMonth", "dayGridDay", "listWeek"] as const;
|
||||||
|
|
||||||
@customElement("hui-calendar-card-editor")
|
@customElement("hui-calendar-card-editor")
|
||||||
export class HuiCalendarCardEditor
|
export class HuiCalendarCardEditor
|
||||||
|
@ -4010,8 +4010,9 @@
|
|||||||
"calendar_entities": "Calendar Entities",
|
"calendar_entities": "Calendar Entities",
|
||||||
"views": {
|
"views": {
|
||||||
"dayGridMonth": "Month",
|
"dayGridMonth": "Month",
|
||||||
|
"dayGridWeek": "Week",
|
||||||
"dayGridDay": "Day",
|
"dayGridDay": "Day",
|
||||||
"list": "List"
|
"listWeek": "List (7 days)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"conditional": {
|
"conditional": {
|
||||||
|
@ -122,7 +122,7 @@ export type FullCalendarView =
|
|||||||
| "dayGridMonth"
|
| "dayGridMonth"
|
||||||
| "dayGridWeek"
|
| "dayGridWeek"
|
||||||
| "dayGridDay"
|
| "dayGridDay"
|
||||||
| "list";
|
| "listWeek";
|
||||||
|
|
||||||
export interface ToggleButton {
|
export interface ToggleButton {
|
||||||
label: string;
|
label: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user