Skip to content

Commit ba9c7f3

Browse files
authored
Expose location for calendar events (home-assistant#27983)
* Expose location for calendar events * from review
1 parent f8923ed commit ba9c7f3

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/data/calendar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface CalendarEventData {
3131
dtend: string;
3232
rrule?: string;
3333
description?: string;
34+
location?: string;
3435
}
3536

3637
export interface CalendarEventMutableParams {
@@ -39,6 +40,7 @@ export interface CalendarEventMutableParams {
3940
dtend: string;
4041
rrule?: string;
4142
description?: string;
43+
location?: string;
4244
}
4345

4446
// The scope of a delete/update for a recurring event
@@ -96,6 +98,7 @@ export const fetchCalendarEvents = async (
9698
uid: ev.uid,
9799
summary: ev.summary,
98100
description: ev.description,
101+
location: ev.location,
99102
dtstart: eventStart,
100103
dtend: eventEnd,
101104
recurrence_id: ev.recurrence_id,

src/panels/calendar/dialog-calendar-event-detail.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ class DialogCalendarEventDetail extends LitElement {
8080
${this._data!.rrule
8181
? this._renderRRuleAsText(this._data.rrule)
8282
: ""}
83+
${this._data.location
84+
? html`${this._data.location} <br />`
85+
: nothing}
8386
${this._data.description
8487
? html`<br />
85-
<div class="description">${this._data.description}</div>
86-
<br />`
88+
<div class="description">${this._data.description}</div>`
8789
: nothing}
8890
</div>
8991
</div>
@@ -241,7 +243,7 @@ class DialogCalendarEventDetail extends LitElement {
241243
haStyleDialog,
242244
css`
243245
state-info {
244-
line-height: 40px;
246+
margin-top: 24px;
245247
}
246248
ha-svg-icon {
247249
width: 40px;

src/panels/calendar/dialog-calendar-event-editor.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class DialogCalendarEventEditor extends LitElement {
6363

6464
@state() private _description? = "";
6565

66+
@state() private _location? = "";
67+
6668
@state() private _rrule?: string;
6769

6870
@state() private _allDay = false;
@@ -79,6 +81,8 @@ class DialogCalendarEventEditor extends LitElement {
7981
// timezone, but floating without a timezone.
8082
private _timeZone?: string;
8183

84+
private _hasLocation = false;
85+
8286
public showDialog(params: CalendarEventEditDialogParams): void {
8387
this._error = undefined;
8488
this._info = undefined;
@@ -99,6 +103,10 @@ class DialogCalendarEventEditor extends LitElement {
99103
this._allDay = isDate(entry.dtstart);
100104
this._summary = entry.summary;
101105
this._description = entry.description;
106+
if (entry.location) {
107+
this._hasLocation = true;
108+
this._location = entry.location;
109+
}
102110
this._rrule = entry.rrule;
103111
if (this._allDay) {
104112
this._dtstart = new Date(entry.dtstart + "T00:00:00");
@@ -130,6 +138,8 @@ class DialogCalendarEventEditor extends LitElement {
130138
this._dtend = undefined;
131139
this._summary = "";
132140
this._description = "";
141+
this._location = "";
142+
this._hasLocation = false;
133143
this._rrule = undefined;
134144
fireEvent(this, "dialog-closed", { dialog: this.localName });
135145
}
@@ -181,6 +191,15 @@ class DialogCalendarEventEditor extends LitElement {
181191
.validationMessage=${this.hass.localize("ui.common.error_required")}
182192
dialogInitialFocus
183193
></ha-textfield>
194+
<ha-textfield
195+
class="location"
196+
name="location"
197+
.label=${this.hass.localize(
198+
"ui.components.calendar.event.location"
199+
)}
200+
.value=${this._location}
201+
@change=${this._handleLocationChanged}
202+
></ha-textfield>
184203
<ha-textarea
185204
class="description"
186205
name="description"
@@ -326,6 +345,10 @@ class DialogCalendarEventEditor extends LitElement {
326345
this._description = ev.target.value;
327346
}
328347

348+
private _handleLocationChanged(ev: Event) {
349+
this._location = (ev.target as HTMLInputElement).value;
350+
}
351+
329352
private _handleRRuleChanged(ev) {
330353
this._rrule = ev.detail.value;
331354
}
@@ -399,6 +422,7 @@ class DialogCalendarEventEditor extends LitElement {
399422
const data: CalendarEventMutableParams = {
400423
summary: this._summary,
401424
description: this._description,
425+
location: this._location || (this._hasLocation ? "" : undefined),
402426
rrule: this._rrule || undefined,
403427
dtstart: "",
404428
dtend: "",

src/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,8 @@
12371237
"times": "times"
12381238
},
12391239
"summary": "Summary",
1240-
"description": "Description"
1240+
"description": "Description",
1241+
"location": "Location"
12411242
},
12421243
"views": {
12431244
"dayGridMonth": "[%key:ui::panel::lovelace::editor::card::calendar::views::dayGridMonth%]",

0 commit comments

Comments
 (0)