mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Calendar: Adds an Update Size and Makes list view start today and adds in local for first day of week (#7541)
This commit is contained in:
parent
14db37459f
commit
e555b24f50
@ -2,6 +2,7 @@
|
|||||||
import fullcalendarStyle from "@fullcalendar/common/main.css";
|
import fullcalendarStyle from "@fullcalendar/common/main.css";
|
||||||
import type { CalendarOptions } from "@fullcalendar/core";
|
import type { CalendarOptions } from "@fullcalendar/core";
|
||||||
import { Calendar } from "@fullcalendar/core";
|
import { Calendar } from "@fullcalendar/core";
|
||||||
|
import allLocales from "@fullcalendar/core/locales-all";
|
||||||
import dayGridPlugin from "@fullcalendar/daygrid";
|
import dayGridPlugin from "@fullcalendar/daygrid";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import daygridStyle from "@fullcalendar/daygrid/main.css";
|
import daygridStyle from "@fullcalendar/daygrid/main.css";
|
||||||
@ -44,6 +45,15 @@ 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],
|
||||||
@ -51,16 +61,22 @@ const defaultFullCalendarConfig: CalendarOptions = {
|
|||||||
dayMaxEventRows: true,
|
dayMaxEventRows: true,
|
||||||
height: "parent",
|
height: "parent",
|
||||||
eventDisplay: "list-item",
|
eventDisplay: "list-item",
|
||||||
|
locales: allLocales,
|
||||||
|
views: {
|
||||||
|
list: {
|
||||||
|
visibleRange: getListWeekRange,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewButtons: ToggleButton[] = [
|
const viewButtons: ToggleButton[] = [
|
||||||
{ label: "Month View", value: "dayGridMonth", iconPath: mdiViewModule },
|
{ label: "Month View", value: "dayGridMonth", iconPath: mdiViewModule },
|
||||||
{ label: "Week View", value: "dayGridWeek", iconPath: mdiViewWeek },
|
{ label: "Week View", value: "dayGridWeek", iconPath: mdiViewWeek },
|
||||||
{ label: "Day View", value: "dayGridDay", iconPath: mdiViewDay },
|
{ label: "Day View", value: "dayGridDay", iconPath: mdiViewDay },
|
||||||
{ label: "List View", value: "listWeek", iconPath: mdiViewAgenda },
|
{ label: "List View", value: "list", iconPath: mdiViewAgenda },
|
||||||
];
|
];
|
||||||
|
|
||||||
class HAFullCalendar extends LitElement {
|
export class HAFullCalendar extends LitElement {
|
||||||
public hass!: HomeAssistant;
|
public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow = false;
|
@property({ type: Boolean, reflect: true }) public narrow = false;
|
||||||
@ -79,6 +95,10 @@ class HAFullCalendar extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _activeView?: FullCalendarView;
|
@internalProperty() private _activeView?: FullCalendarView;
|
||||||
|
|
||||||
|
public updateSize(): void {
|
||||||
|
this.calendar?.updateSize();
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const viewToggleButtons = this._viewToggleButtons(this.views);
|
const viewToggleButtons = this._viewToggleButtons(this.views);
|
||||||
|
|
||||||
@ -186,6 +206,12 @@ class HAFullCalendar extends LitElement {
|
|||||||
this.calendar!.changeView(this._activeView);
|
this.calendar!.changeView(this._activeView);
|
||||||
this._fireViewChanged();
|
this._fireViewChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const oldHass = changedProps.get("hass") as HomeAssistant;
|
||||||
|
|
||||||
|
if (oldHass && oldHass.language !== this.hass.language) {
|
||||||
|
this.calendar.setOption("locale", this.hass.language);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(): void {
|
protected firstUpdated(): void {
|
||||||
@ -243,7 +269,7 @@ class HAFullCalendar extends LitElement {
|
|||||||
this._fireViewChanged();
|
this._fireViewChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleView(ev): void {
|
private _handleView(ev: CustomEvent): void {
|
||||||
this._activeView = ev.detail.value;
|
this._activeView = ev.detail.value;
|
||||||
this.calendar!.changeView(this._activeView!);
|
this.calendar!.changeView(this._activeView!);
|
||||||
this._fireViewChanged();
|
this._fireViewChanged();
|
||||||
@ -496,6 +522,23 @@ class HAFullCalendar extends LitElement {
|
|||||||
:host([narrow]) .fc-dayGridMonth-view .fc-scrollgrid-sync-table {
|
:host([narrow]) .fc-dayGridMonth-view .fc-scrollgrid-sync-table {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fc-scroller::-webkit-scrollbar {
|
||||||
|
width: 0.4rem;
|
||||||
|
height: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fc-scroller::-webkit-scrollbar-thumb {
|
||||||
|
-webkit-border-radius: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--scrollbar-thumb-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fc-scroller {
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-color: var(--scrollbar-thumb-color) transparent;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
|
query,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { HA_COLOR_PALETTE } from "../../../common/const";
|
import { HA_COLOR_PALETTE } from "../../../common/const";
|
||||||
@ -24,6 +25,7 @@ import type {
|
|||||||
HomeAssistant,
|
HomeAssistant,
|
||||||
} from "../../../types";
|
} from "../../../types";
|
||||||
import "../../calendar/ha-full-calendar";
|
import "../../calendar/ha-full-calendar";
|
||||||
|
import type { HAFullCalendar } from "../../calendar/ha-full-calendar";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
import { installResizeObserver } from "../common/install-resize-observer";
|
import { installResizeObserver } from "../common/install-resize-observer";
|
||||||
import "../components/hui-warning";
|
import "../components/hui-warning";
|
||||||
@ -71,6 +73,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
@internalProperty() private _veryNarrow = false;
|
@internalProperty() private _veryNarrow = false;
|
||||||
|
|
||||||
|
@query("ha-full-calendar", true) private _calendar?: HAFullCalendar;
|
||||||
|
|
||||||
private _startDate?: Date;
|
private _startDate?: Date;
|
||||||
|
|
||||||
private _endDate?: Date;
|
private _endDate?: Date;
|
||||||
@ -121,8 +125,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const views: FullCalendarView[] = this._veryNarrow
|
const views: FullCalendarView[] = this._veryNarrow
|
||||||
? ["listWeek"]
|
? ["list"]
|
||||||
: ["listWeek", "dayGridMonth", "dayGridDay"];
|
: ["list", "dayGridMonth", "dayGridDay"];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
@ -186,6 +190,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
this._narrow = card.offsetWidth < 870;
|
this._narrow = card.offsetWidth < 870;
|
||||||
this._veryNarrow = card.offsetWidth < 350;
|
this._veryNarrow = card.offsetWidth < 350;
|
||||||
|
|
||||||
|
this._calendar?.updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _attachObserver(): Promise<void> {
|
private async _attachObserver(): Promise<void> {
|
||||||
|
@ -148,7 +148,7 @@ export type FullCalendarView =
|
|||||||
| "dayGridMonth"
|
| "dayGridMonth"
|
||||||
| "dayGridWeek"
|
| "dayGridWeek"
|
||||||
| "dayGridDay"
|
| "dayGridDay"
|
||||||
| "listWeek";
|
| "list";
|
||||||
|
|
||||||
export interface ToggleButton {
|
export interface ToggleButton {
|
||||||
label: string;
|
label: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user