mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 01:06:35 +00:00
Fix logbook showing user names (#6327)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
370a1f0574
commit
a8a8cafd2b
@ -18,6 +18,7 @@ import {
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
import { fetchUsers } from "../../data/user";
|
import { fetchUsers } from "../../data/user";
|
||||||
|
import { fetchPersons } from "../../data/person";
|
||||||
import {
|
import {
|
||||||
clearLogbookCache,
|
clearLogbookCache,
|
||||||
getLogbookData,
|
getLogbookData,
|
||||||
@ -132,7 +133,7 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this.hass.loadBackendTranslation("title");
|
this.hass.loadBackendTranslation("title");
|
||||||
|
|
||||||
this._fetchUserDone = this._fetchUsers();
|
this._fetchUserDone = this._fetchUserNames();
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
@ -197,13 +198,38 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchUsers() {
|
private async _fetchUserNames() {
|
||||||
const users = await fetchUsers(this.hass);
|
const userIdToName = {};
|
||||||
const userid_to_name = {};
|
|
||||||
users.forEach((user) => {
|
// Start loading all the data
|
||||||
userid_to_name[user.id] = user.name;
|
const personProm = fetchPersons(this.hass);
|
||||||
});
|
const userProm = this.hass.user!.is_admin && fetchUsers(this.hass);
|
||||||
this._userIdToName = userid_to_name;
|
|
||||||
|
// Process persons
|
||||||
|
const persons = await personProm;
|
||||||
|
|
||||||
|
for (const person of persons.storage) {
|
||||||
|
if (person.user_id) {
|
||||||
|
userIdToName[person.user_id] = person.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const person of persons.config) {
|
||||||
|
if (person.user_id) {
|
||||||
|
userIdToName[person.user_id] = person.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process users
|
||||||
|
if (userProm) {
|
||||||
|
const users = await userProm;
|
||||||
|
for (const user of users) {
|
||||||
|
if (!(user.id in userIdToName)) {
|
||||||
|
userIdToName[user.id] = user.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._userIdToName = userIdToName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _dateRangeChanged(ev) {
|
private _dateRangeChanged(ev) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user