mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Add current user to hass object (#1451)
* Add current user to hass object * Add enter key support to login form
This commit is contained in:
parent
5c5a7e50da
commit
229d167f89
@ -118,10 +118,18 @@ class HaSidebar extends
|
|||||||
</paper-icon-item>
|
</paper-icon-item>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template is='dom-if' if='[[!hass.user]]'>
|
||||||
<paper-icon-item on-click="menuClicked" data-panel="logout" class="logout">
|
<paper-icon-item on-click="menuClicked" data-panel="logout" class="logout">
|
||||||
<ha-icon slot="item-icon" icon="hass:exit-to-app"></ha-icon>
|
<ha-icon slot="item-icon" icon="hass:exit-to-app"></ha-icon>
|
||||||
<span class="item-text">[[localize('ui.sidebar.log_out')]]</span>
|
<span class="item-text">[[localize('ui.sidebar.log_out')]]</span>
|
||||||
</paper-icon-item>
|
</paper-icon-item>
|
||||||
|
</template>
|
||||||
|
<template is='dom-if' if='[[hass.user]]'>
|
||||||
|
<paper-icon-item on-click="menuClicked" data-panel="profile">
|
||||||
|
<ha-icon slot="item-icon" icon="hass:account"></ha-icon>
|
||||||
|
<span class="item-text">[[hass.user.name]]</span>
|
||||||
|
</paper-icon-item>
|
||||||
|
</template>
|
||||||
</paper-listbox>
|
</paper-listbox>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -175,6 +175,7 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
|
|||||||
callApi: null,
|
callApi: null,
|
||||||
sendWS: null,
|
sendWS: null,
|
||||||
callWS: null,
|
callWS: null,
|
||||||
|
user: null,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -320,18 +321,22 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
|
|||||||
|
|
||||||
let unsubThemes;
|
let unsubThemes;
|
||||||
|
|
||||||
this.hass.connection.sendMessagePromise({
|
this.hass.callWS({
|
||||||
type: 'frontend/get_themes',
|
type: 'frontend/get_themes',
|
||||||
}).then((resp) => {
|
}).then((themes) => {
|
||||||
this._updateHass({ themes: resp.result });
|
this._updateHass({ themes });
|
||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
document.documentElement,
|
document.documentElement,
|
||||||
resp.result,
|
themes,
|
||||||
this.hass.selectedTheme,
|
this.hass.selectedTheme,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.hass.callWS({
|
||||||
|
type: 'auth/current_user',
|
||||||
|
}).then(user => this._updateHass({ user }), () => {});
|
||||||
|
|
||||||
conn.subscribeEvents((event) => {
|
conn.subscribeEvents((event) => {
|
||||||
this._updateHass({ themes: event.data });
|
this._updateHass({ themes: event.data });
|
||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
|
@ -78,6 +78,10 @@ function ensureLoaded(panel) {
|
|||||||
imported = import(/* webpackChunkName: "panel-map" */ '../panels/map/ha-panel-map.js');
|
imported = import(/* webpackChunkName: "panel-map" */ '../panels/map/ha-panel-map.js');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'profile':
|
||||||
|
imported = import(/* webpackChunkName: "panel-profile" */ '../panels/profile/ha-panel-profile.js');
|
||||||
|
break;
|
||||||
|
|
||||||
case 'shopping-list':
|
case 'shopping-list':
|
||||||
imported = import(/* webpackChunkName: "panel-shopping-list" */ '../panels/shopping-list/ha-panel-shopping-list.js');
|
imported = import(/* webpackChunkName: "panel-shopping-list" */ '../panels/shopping-list/ha-panel-shopping-list.js');
|
||||||
break;
|
break;
|
||||||
|
@ -48,7 +48,7 @@ class HaConfigDashboard extends LocalizeMixin(PolymerElement) {
|
|||||||
<ha-config-entries-menu hass="[[hass]]"></ha-config-entries-menu>
|
<ha-config-entries-menu hass="[[hass]]"></ha-config-entries-menu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template is="dom-if" if="[[computeIsLoaded(hass, 'config.auth_provider_homeassistant')]]">
|
<template is="dom-if" if="[[hass.user.is_owner]]">
|
||||||
<ha-config-users-menu hass="[[hass]]"></ha-config-users-menu>
|
<ha-config-users-menu hass="[[hass]]"></ha-config-users-menu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
72
src/panels/profile/ha-panel-profile.js
Normal file
72
src/panels/profile/ha-panel-profile.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import '@polymer/app-layout/app-header-layout/app-header-layout.js';
|
||||||
|
import '@polymer/app-layout/app-header/app-header.js';
|
||||||
|
import '@polymer/paper-card/paper-card.js';
|
||||||
|
import '@polymer/paper-button/paper-button.js';
|
||||||
|
import '@polymer/app-layout/app-toolbar/app-toolbar.js';
|
||||||
|
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||||
|
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||||
|
|
||||||
|
import '../../components/ha-menu-button.js';
|
||||||
|
import '../../resources/ha-style.js';
|
||||||
|
import EventsMixin from '../../mixins/events-mixin.js';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @appliesMixin EventsMixin
|
||||||
|
*/
|
||||||
|
class HaPanelProfile extends EventsMixin(PolymerElement) {
|
||||||
|
static get template() {
|
||||||
|
return html`
|
||||||
|
<style include="ha-style">
|
||||||
|
:host {
|
||||||
|
-ms-user-select: initial;
|
||||||
|
-webkit-user-select: initial;
|
||||||
|
-moz-user-select: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
paper-card {
|
||||||
|
display: block;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 16px auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<app-header-layout has-scrolling-region>
|
||||||
|
<app-header slot="header" fixed>
|
||||||
|
<app-toolbar>
|
||||||
|
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
|
||||||
|
<div main-title>Profile</div>
|
||||||
|
</app-toolbar>
|
||||||
|
</app-header>
|
||||||
|
|
||||||
|
<div class='content'>
|
||||||
|
<paper-card heading='[[hass.user.name]]'>
|
||||||
|
<div class='card-content'>
|
||||||
|
You are currently logged in as [[hass.user.name]].
|
||||||
|
<template is='dom-if' if='[[hass.user.is_owner]]'>You are an owner.</template>
|
||||||
|
</div>
|
||||||
|
<div class='card-actions'>
|
||||||
|
<paper-button
|
||||||
|
class='warning'
|
||||||
|
on-click='_handleLogOut'
|
||||||
|
>Log out</paper-button>
|
||||||
|
</div>
|
||||||
|
</paper-card>
|
||||||
|
</div>
|
||||||
|
</app-header-layout>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get properties() {
|
||||||
|
return {
|
||||||
|
hass: Object,
|
||||||
|
narrow: Boolean,
|
||||||
|
showMenu: Boolean,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleLogOut() {
|
||||||
|
this.fire('hass-logout');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define('ha-panel-profile', HaPanelProfile);
|
Loading…
x
Reference in New Issue
Block a user