mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-29 12:16:39 +00:00
Show the user that made the change in logbook (#6173)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
4e17875011
commit
f15cc0b424
@ -4,4 +4,5 @@ export interface LogbookEntry {
|
|||||||
message: string;
|
message: string;
|
||||||
entity_id?: string;
|
entity_id?: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
|
context_user_id?: string;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { scroll } from "lit-virtualizer";
|
import { scroll } from "lit-virtualizer";
|
||||||
import { formatDate } from "../../common/datetime/format_date";
|
import { formatDate } from "../../common/datetime/format_date";
|
||||||
|
import { fetchUsers } from "../../data/user";
|
||||||
import { formatTimeWithSeconds } from "../../common/datetime/format_time";
|
import { formatTimeWithSeconds } from "../../common/datetime/format_time";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { domainIcon } from "../../common/entity/domain_icon";
|
import { domainIcon } from "../../common/entity/domain_icon";
|
||||||
@ -21,6 +22,9 @@ import { HomeAssistant } from "../../types";
|
|||||||
class HaLogbook extends LitElement {
|
class HaLogbook extends LitElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
private _userid_to_name = {};
|
||||||
|
|
||||||
@property() public entries: LogbookEntry[] = [];
|
@property() public entries: LogbookEntry[] = [];
|
||||||
|
|
||||||
@property({ attribute: "rtl", type: Boolean, reflect: true })
|
@property({ attribute: "rtl", type: Boolean, reflect: true })
|
||||||
@ -58,6 +62,20 @@ class HaLogbook extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _fetchUsers() {
|
||||||
|
const users = await fetchUsers(this.hass);
|
||||||
|
const userid_to_name = {};
|
||||||
|
users.forEach((user) => {
|
||||||
|
userid_to_name[user.id] = user.name;
|
||||||
|
});
|
||||||
|
this._userid_to_name = userid_to_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(changedProperties: PropertyValues) {
|
||||||
|
super.firstUpdated(changedProperties);
|
||||||
|
this._fetchUsers();
|
||||||
|
}
|
||||||
|
|
||||||
private _renderLogbookItem(
|
private _renderLogbookItem(
|
||||||
item: LogbookEntry,
|
item: LogbookEntry,
|
||||||
index?: number
|
index?: number
|
||||||
@ -67,6 +85,8 @@ class HaLogbook extends LitElement {
|
|||||||
}
|
}
|
||||||
const previous = this.entries[index - 1];
|
const previous = this.entries[index - 1];
|
||||||
const state = item.entity_id ? this.hass.states[item.entity_id] : undefined;
|
const state = item.entity_id ? this.hass.states[item.entity_id] : undefined;
|
||||||
|
const item_username =
|
||||||
|
item.context_user_id && this._userid_to_name[item.context_user_id];
|
||||||
return html`
|
return html`
|
||||||
<div>
|
<div>
|
||||||
${index === 0 ||
|
${index === 0 ||
|
||||||
@ -101,7 +121,11 @@ class HaLogbook extends LitElement {
|
|||||||
${item.name}
|
${item.name}
|
||||||
</a>
|
</a>
|
||||||
`}
|
`}
|
||||||
<span>${item.message}</span>
|
<span
|
||||||
|
>${item.message}${item_username
|
||||||
|
? ` (${item_username})`
|
||||||
|
: ``}</span
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user