mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Allow to clear due date (#19201)
This commit is contained in:
parent
fe18f70e51
commit
cb29d35949
@ -18,7 +18,8 @@ export interface datePickerDialogParams {
|
|||||||
max?: string;
|
max?: string;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
firstWeekday?: number;
|
firstWeekday?: number;
|
||||||
onChange: (value: string) => void;
|
canClear?: boolean;
|
||||||
|
onChange: (value: string | undefined) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const showDatePickerDialog = (
|
const showDatePickerDialog = (
|
||||||
@ -49,6 +50,8 @@ export class HaDateInput extends LitElement {
|
|||||||
|
|
||||||
@property() public helper?: string;
|
@property() public helper?: string;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public canClear?: boolean;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`<ha-textfield
|
return html`<ha-textfield
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
@ -58,6 +61,7 @@ export class HaDateInput extends LitElement {
|
|||||||
helperPersistent
|
helperPersistent
|
||||||
readonly
|
readonly
|
||||||
@click=${this._openDialog}
|
@click=${this._openDialog}
|
||||||
|
@keydown=${this._keyDown}
|
||||||
.value=${this.value
|
.value=${this.value
|
||||||
? formatDateNumeric(
|
? formatDateNumeric(
|
||||||
new Date(`${this.value.split("T")[0]}T00:00:00`),
|
new Date(`${this.value.split("T")[0]}T00:00:00`),
|
||||||
@ -82,13 +86,23 @@ export class HaDateInput extends LitElement {
|
|||||||
min: this.min || "1970-01-01",
|
min: this.min || "1970-01-01",
|
||||||
max: this.max,
|
max: this.max,
|
||||||
value: this.value,
|
value: this.value,
|
||||||
|
canClear: this.canClear,
|
||||||
onChange: (value) => this._valueChanged(value),
|
onChange: (value) => this._valueChanged(value),
|
||||||
locale: this.locale.language,
|
locale: this.locale.language,
|
||||||
firstWeekday: firstWeekdayIndex(this.locale),
|
firstWeekday: firstWeekdayIndex(this.locale),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(value: string) {
|
private _keyDown(ev: KeyboardEvent) {
|
||||||
|
if (!this.canClear) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (["Backspace", "Delete"].includes(ev.key)) {
|
||||||
|
this._valueChanged(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(value: string | undefined) {
|
||||||
if (this.value !== value) {
|
if (this.value !== value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
|
@ -50,6 +50,15 @@ export class HaDialogDatePicker extends LitElement {
|
|||||||
@datepicker-value-updated=${this._valueChanged}
|
@datepicker-value-updated=${this._valueChanged}
|
||||||
.firstDayOfWeek=${this._params.firstWeekday}
|
.firstDayOfWeek=${this._params.firstWeekday}
|
||||||
></app-datepicker>
|
></app-datepicker>
|
||||||
|
${this._params.canClear
|
||||||
|
? html`<mwc-button
|
||||||
|
slot="secondaryAction"
|
||||||
|
@click=${this._clear}
|
||||||
|
class="warning"
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.dialogs.date-picker.clear")}
|
||||||
|
</mwc-button>`
|
||||||
|
: nothing}
|
||||||
<mwc-button slot="secondaryAction" @click=${this._setToday}>
|
<mwc-button slot="secondaryAction" @click=${this._setToday}>
|
||||||
${this.hass.localize("ui.dialogs.date-picker.today")}
|
${this.hass.localize("ui.dialogs.date-picker.today")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
@ -66,6 +75,11 @@ export class HaDialogDatePicker extends LitElement {
|
|||||||
this._value = ev.detail.value;
|
this._value = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _clear() {
|
||||||
|
this._params?.onChange(undefined);
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
private _setToday() {
|
private _setToday() {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
this._value = format(today, "yyyy-MM-dd");
|
this._value = format(today, "yyyy-MM-dd");
|
||||||
|
@ -18,8 +18,8 @@ export interface TodoItem {
|
|||||||
uid: string;
|
uid: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
status: TodoItemStatus;
|
status: TodoItemStatus;
|
||||||
description?: string;
|
description?: string | null;
|
||||||
due?: string;
|
due?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum TodoListEntityFeature {
|
export const enum TodoListEntityFeature {
|
||||||
@ -83,9 +83,9 @@ export const updateItem = (
|
|||||||
item: item.uid,
|
item: item.uid,
|
||||||
rename: item.summary,
|
rename: item.summary,
|
||||||
status: item.status,
|
status: item.status,
|
||||||
description: item.description || undefined,
|
description: item.description || null,
|
||||||
due_datetime: item.due?.includes("T") ? item.due : undefined,
|
due_datetime: item.due?.includes("T") ? item.due : undefined,
|
||||||
due_date: item.due?.includes("T") ? undefined : item.due || undefined,
|
due_date: item.due?.includes("T") ? undefined : item.due || null,
|
||||||
},
|
},
|
||||||
{ entity_id }
|
{ entity_id }
|
||||||
);
|
);
|
||||||
|
@ -161,7 +161,8 @@ class DialogTodoItemEditor extends LitElement {
|
|||||||
.value=${dueDate}
|
.value=${dueDate}
|
||||||
.locale=${this.hass.locale}
|
.locale=${this.hass.locale}
|
||||||
.disabled=${!canUpdate}
|
.disabled=${!canUpdate}
|
||||||
@value-changed=${this._endDateChanged}
|
@value-changed=${this._dueDateChanged}
|
||||||
|
canClear
|
||||||
></ha-date-input>
|
></ha-date-input>
|
||||||
${this._todoListSupportsFeature(
|
${this._todoListSupportsFeature(
|
||||||
TodoListEntityFeature.SET_DUE_DATETIME_ON_ITEM
|
TodoListEntityFeature.SET_DUE_DATETIME_ON_ITEM
|
||||||
@ -170,7 +171,7 @@ class DialogTodoItemEditor extends LitElement {
|
|||||||
.value=${dueTime}
|
.value=${dueTime}
|
||||||
.locale=${this.hass.locale}
|
.locale=${this.hass.locale}
|
||||||
.disabled=${!canUpdate}
|
.disabled=${!canUpdate}
|
||||||
@value-changed=${this._endTimeChanged}
|
@value-changed=${this._dueTimeChanged}
|
||||||
></ha-time-input>`
|
></ha-time-input>`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
@ -259,12 +260,16 @@ class DialogTodoItemEditor extends LitElement {
|
|||||||
this._description = ev.target.value;
|
this._description = ev.target.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _endDateChanged(ev: CustomEvent) {
|
private _dueDateChanged(ev: CustomEvent) {
|
||||||
|
if (!ev.detail.value) {
|
||||||
|
this._due = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const time = this._due ? this._formatTime(this._due) : undefined;
|
const time = this._due ? this._formatTime(this._due) : undefined;
|
||||||
this._due = this._parseDate(`${ev.detail.value}${time ? `T${time}` : ""}`);
|
this._due = this._parseDate(`${ev.detail.value}${time ? `T${time}` : ""}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _endTimeChanged(ev: CustomEvent) {
|
private _dueTimeChanged(ev: CustomEvent) {
|
||||||
this._hasTime = true;
|
this._hasTime = true;
|
||||||
this._due = this._parseDate(
|
this._due = this._parseDate(
|
||||||
`${this._formatDate(this._due || new Date())}T${ev.detail.value}`
|
`${this._formatDate(this._due || new Date())}T${ev.detail.value}`
|
||||||
@ -320,13 +325,13 @@ class DialogTodoItemEditor extends LitElement {
|
|||||||
TodoListEntityFeature.SET_DESCRIPTION_ON_ITEM
|
TodoListEntityFeature.SET_DESCRIPTION_ON_ITEM
|
||||||
)
|
)
|
||||||
? // backend should accept null to clear the field, but it doesn't now
|
? // backend should accept null to clear the field, but it doesn't now
|
||||||
" "
|
null
|
||||||
: undefined),
|
: undefined),
|
||||||
due: this._due
|
due: this._due
|
||||||
? this._hasTime
|
? this._hasTime
|
||||||
? this._due.toISOString()
|
? this._due.toISOString()
|
||||||
: this._formatDate(this._due)
|
: this._formatDate(this._due)
|
||||||
: undefined,
|
: null,
|
||||||
status: this._checked
|
status: this._checked
|
||||||
? TodoItemStatus.Completed
|
? TodoItemStatus.Completed
|
||||||
: TodoItemStatus.NeedsAction,
|
: TodoItemStatus.NeedsAction,
|
||||||
|
@ -1009,7 +1009,8 @@
|
|||||||
"crop_image": "Picture to crop"
|
"crop_image": "Picture to crop"
|
||||||
},
|
},
|
||||||
"date-picker": {
|
"date-picker": {
|
||||||
"today": "Today"
|
"today": "Today",
|
||||||
|
"clear": "Clear"
|
||||||
},
|
},
|
||||||
"more_info_control": {
|
"more_info_control": {
|
||||||
"dismiss": "Dismiss dialog",
|
"dismiss": "Dismiss dialog",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user