Skip to content

Commit c00d8e1

Browse files
committed
Added schedule-view to day and week views on Calendar, and lovelace calendar card
1 parent a07772c commit c00d8e1

6 files changed

Lines changed: 100 additions & 8 deletions

File tree

src/panels/calendar/ha-full-calendar.ts

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import allLocales from "@fullcalendar/core/locales-all";
44
import dayGridPlugin from "@fullcalendar/daygrid";
55
import interactionPlugin from "@fullcalendar/interaction";
66
import listPlugin from "@fullcalendar/list";
7+
import timeGridPlugin from "@fullcalendar/timegrid";
78
import { ResizeController } from "@lit-labs/observers/resize-controller";
89
import {
10+
mdiCalendarClock,
911
mdiPlus,
12+
mdiTimetable,
1013
mdiViewAgenda,
1114
mdiViewDay,
1215
mdiViewModule,
@@ -56,12 +59,14 @@ declare global {
5659

5760
const defaultFullCalendarConfig: CalendarOptions = {
5861
headerToolbar: false,
59-
plugins: [dayGridPlugin, listPlugin, interactionPlugin],
62+
plugins: [dayGridPlugin, listPlugin, interactionPlugin, timeGridPlugin],
6063
initialView: "dayGridMonth",
6164
dayMaxEventRows: true,
6265
height: "parent",
6366
handleWindowResize: false,
6467
locales: allLocales,
68+
nowIndicator: true,
69+
scrollTime: "06:00:00",
6570
views: {
6671
listWeek: {
6772
type: "list",
@@ -86,6 +91,8 @@ export class HAFullCalendar extends LitElement {
8691
"dayGridMonth",
8792
"dayGridWeek",
8893
"dayGridDay",
94+
"timeGridWeek",
95+
"timeGridDay",
8996
"listWeek",
9097
];
9198

@@ -325,6 +332,8 @@ export class HAFullCalendar extends LitElement {
325332
selectedDate:
326333
this._activeView === "dayGridWeek" ||
327334
this._activeView === "dayGridDay" ||
335+
this._activeView === "timeGridWeek" ||
336+
this._activeView === "timeGridDay" ||
328337
(this._activeView === "dayGridMonth" &&
329338
this.calendar!.view.currentStart.getMonth() !== new Date().getMonth())
330339
? this.calendar!.view.currentStart
@@ -359,8 +368,11 @@ export class HAFullCalendar extends LitElement {
359368
if (info.view.type !== "dayGridMonth") {
360369
return;
361370
}
362-
this._activeView = "dayGridDay";
363-
this.calendar!.changeView("dayGridDay");
371+
const dayView = this.views.includes("timeGridDay")
372+
? "timeGridDay"
373+
: "dayGridDay";
374+
this._activeView = dayView;
375+
this.calendar!.changeView(dayView);
364376
this.calendar!.gotoDate(info.dateStr);
365377
this._fireViewChanged();
366378
}
@@ -473,6 +485,16 @@ export class HAFullCalendar extends LitElement {
473485
value: "dayGridDay",
474486
iconPath: mdiViewDay,
475487
},
488+
{
489+
label: localize("ui.components.calendar.views.timeGridWeek"),
490+
value: "timeGridWeek",
491+
iconPath: mdiTimetable,
492+
},
493+
{
494+
label: localize("ui.components.calendar.views.timeGridDay"),
495+
value: "timeGridDay",
496+
iconPath: mdiCalendarClock,
497+
},
476498
{
477499
label: localize("ui.components.calendar.views.listWeek"),
478500
value: "listWeek",
@@ -767,6 +789,64 @@ export class HAFullCalendar extends LitElement {
767789
scrollbar-color: var(--scrollbar-thumb-color) transparent;
768790
scrollbar-width: thin;
769791
}
792+
793+
/* timeGrid (week/day) view styles */
794+
.fc-timegrid-slot-label {
795+
font-size: var(--ha-font-size-xs);
796+
color: var(--secondary-text-color);
797+
}
798+
799+
.fc-timegrid-axis {
800+
font-size: var(--ha-font-size-xs);
801+
color: var(--secondary-text-color);
802+
}
803+
804+
.fc .fc-timegrid-col.fc-day-today {
805+
background: var(--primary-color-alpha-10, rgba(0, 0, 0, 0.04));
806+
}
807+
808+
.fc-timegrid-now-indicator-line {
809+
border-color: var(--primary-color);
810+
}
811+
812+
.fc-timegrid-now-indicator-arrow {
813+
border-top-color: var(--primary-color);
814+
border-bottom-color: var(--primary-color);
815+
}
816+
817+
.fc-timegrid-event {
818+
border-radius: var(--ha-border-radius-sm);
819+
}
820+
821+
.fc-timegrid-event .fc-event-main {
822+
padding: 2px 4px;
823+
}
824+
825+
.fc-timegrid-event .fc-event-title-container {
826+
order: -1;
827+
}
828+
829+
/* Compact styling for short events via container query */
830+
.fc-timegrid-event-harness {
831+
container-type: size;
832+
}
833+
834+
@container (max-height: 30px) {
835+
.fc-v-event {
836+
border-top-width: 0;
837+
border-bottom-width: 0;
838+
}
839+
.fc-v-event .fc-event-main {
840+
padding-top: 0;
841+
padding-bottom: 0;
842+
}
843+
.fc-v-event .fc-event-main .fc-event-main-frame {
844+
line-height: 14px;
845+
}
846+
.fc-v-event .fc-event-time {
847+
display: none;
848+
}
849+
}
770850
`,
771851
];
772852
}

src/panels/lovelace/cards/hui-calendar-card.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ export class HuiCalendarCard
188188

189189
const loading = !this._entityRegistry || !this._eventsLoaded;
190190

191-
const views: FullCalendarView[] = [
192-
"dayGridMonth",
193-
"dayGridDay",
194-
"listWeek",
195-
];
191+
const dayView: FullCalendarView = this._config.schedule_day_view
192+
? "timeGridDay"
193+
: "dayGridDay";
194+
195+
const views: FullCalendarView[] = ["dayGridMonth", dayView, "listWeek"];
196196

197197
return html`
198198
<ha-card>

src/panels/lovelace/cards/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface AlarmPanelCardConfig extends LovelaceCardConfig {
5353
export interface CalendarCardConfig extends LovelaceCardConfig {
5454
entities: string[];
5555
initial_view?: FullCalendarView;
56+
schedule_day_view?: boolean;
5657
title?: string;
5758
theme?: string;
5859
}

src/panels/lovelace/editor/config-elements/hui-calendar-card-editor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const cardConfigStruct = assign(
2626
object({
2727
title: optional(union([string(), boolean()])),
2828
initial_view: optional(string()),
29+
schedule_day_view: optional(boolean()),
2930
theme: optional(string()),
3031
entities: array(string()),
3132
})
@@ -69,6 +70,11 @@ export class HuiCalendarCardEditor
6970
},
7071
},
7172
},
73+
{
74+
name: "schedule_day_view",
75+
required: false,
76+
selector: { boolean: {} },
77+
},
7278
],
7379
},
7480
{ name: "theme", required: false, selector: { theme: {} } },

src/translations/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@
13311331
"dayGridMonth": "[%key:ui::panel::lovelace::editor::card::calendar::views::dayGridMonth%]",
13321332
"dayGridWeek": "[%key:ui::panel::lovelace::editor::card::calendar::views::dayGridWeek%]",
13331333
"dayGridDay": "[%key:ui::panel::lovelace::editor::card::calendar::views::dayGridDay%]",
1334+
"timeGridWeek": "Schedule (week)",
1335+
"timeGridDay": "Schedule (day)",
13341336
"listWeek": "[%key:ui::panel::lovelace::editor::card::calendar::views::listWeek%]"
13351337
}
13361338
},
@@ -8932,6 +8934,7 @@
89328934
"name": "Calendar",
89338935
"description": "This card displays a calendar including day, week, and list views",
89348936
"initial_view": "Initial view",
8937+
"schedule_day_view": "Use schedule for day view",
89358938
"calendar_entities": "Calendar entities",
89368939
"views": {
89378940
"dayGridMonth": "Month",

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export type FullCalendarView =
157157
| "dayGridMonth"
158158
| "dayGridWeek"
159159
| "dayGridDay"
160+
| "timeGridWeek"
161+
| "timeGridDay"
160162
| "listWeek";
161163

162164
export const THEME_MODES = ["auto", "light", "dark"] as const;

0 commit comments

Comments
 (0)