mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 12:56:37 +00:00
Convert home-assistant-main to ES6 class (#424)
* Convert home-assistant-main to ES6 class * Add arrow functions to ensure this is bound * Add missed parameter * Picky linter
This commit is contained in:
parent
684ac8fe69
commit
3912347f3d
@ -1,4 +1,4 @@
|
|||||||
<link rel='import' href='../../bower_components/polymer/polymer.html'>
|
<link rel='import' href='../../bower_components/polymer/polymer-element.html'>
|
||||||
<link rel='import' href='../../bower_components/paper-drawer-panel/paper-drawer-panel.html'>
|
<link rel='import' href='../../bower_components/paper-drawer-panel/paper-drawer-panel.html'>
|
||||||
<link rel='import' href='../../bower_components/iron-media-query/iron-media-query.html'>
|
<link rel='import' href='../../bower_components/iron-media-query/iron-media-query.html'>
|
||||||
<link rel='import' href='../../bower_components/iron-pages/iron-pages.html'>
|
<link rel='import' href='../../bower_components/iron-pages/iron-pages.html'>
|
||||||
@ -14,6 +14,7 @@
|
|||||||
<link rel='import' href='../util/ha-url-sync.html'>
|
<link rel='import' href='../util/ha-url-sync.html'>
|
||||||
|
|
||||||
<link rel='import' href='../components/ha-sidebar.html'>
|
<link rel='import' href='../components/ha-sidebar.html'>
|
||||||
|
<link rel='import' href='../util/hass-mixins.html'>
|
||||||
<link rel='import' href='../util/hass-util.html'>
|
<link rel='import' href='../util/hass-util.html'>
|
||||||
|
|
||||||
<dom-module id='home-assistant-main'>
|
<dom-module id='home-assistant-main'>
|
||||||
@ -87,11 +88,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
var NON_SWIPABLE_PANELS = ['kiosk', 'map'];
|
const NON_SWIPABLE_PANELS = ['kiosk', 'map'];
|
||||||
Polymer({
|
|
||||||
is: 'home-assistant-main',
|
|
||||||
|
|
||||||
properties: {
|
class HomeAssistantMain extends window.hassMixins.EventsMixin(Polymer.Element) {
|
||||||
|
static get is() { return 'home-assistant-main'; }
|
||||||
|
|
||||||
|
static get properties() {
|
||||||
|
return {
|
||||||
hass: Object,
|
hass: Object,
|
||||||
|
|
||||||
narrow: Boolean,
|
narrow: Boolean,
|
||||||
@ -108,62 +111,66 @@
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
computed: 'computeDockedSidebar(hass)',
|
computed: 'computeDockedSidebar(hass)',
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
|
}
|
||||||
|
|
||||||
listeners: {
|
ready() {
|
||||||
'hass-open-menu': 'handleOpenMenu',
|
super.ready();
|
||||||
'hass-close-menu': 'handleCloseMenu',
|
this.addEventListener('hass-open-menu', () => this.handleOpenMenu());
|
||||||
'hass-start-voice': 'handleStartVoice',
|
this.addEventListener('hass-close-menu', () => this.handleCloseMenu());
|
||||||
},
|
this.addEventListener('hass-start-voice', ev => this.handleStartVoice(ev));
|
||||||
|
}
|
||||||
|
|
||||||
_routeChanged: function () {
|
_routeChanged() {
|
||||||
if (this.narrow) {
|
if (this.narrow) {
|
||||||
this.$.drawer.closeDrawer();
|
this.$.drawer.closeDrawer();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
handleStartVoice: function (ev) {
|
handleStartVoice(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this.$.voiceDialog.dialogOpen = true;
|
this.$.voiceDialog.dialogOpen = true;
|
||||||
},
|
}
|
||||||
|
|
||||||
handleOpenMenu: function () {
|
handleOpenMenu() {
|
||||||
if (this.narrow) {
|
if (this.narrow) {
|
||||||
this.$.drawer.openDrawer();
|
this.$.drawer.openDrawer();
|
||||||
} else {
|
} else {
|
||||||
this.fire('hass-dock-sidebar', { dock: true });
|
this.fire('hass-dock-sidebar', { dock: true });
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
handleCloseMenu: function () {
|
handleCloseMenu() {
|
||||||
this.$.drawer.closeDrawer();
|
this.$.drawer.closeDrawer();
|
||||||
if (this.dockedSidebar) {
|
if (this.dockedSidebar) {
|
||||||
this.fire('hass-dock-sidebar', { dock: false });
|
this.fire('hass-dock-sidebar', { dock: false });
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
attached: function () {
|
attached() {
|
||||||
window.removeInitMsg();
|
window.removeInitMsg();
|
||||||
if (document.location.pathname === '/') {
|
if (document.location.pathname === '/') {
|
||||||
history.replaceState(null, null, '/states');
|
history.replaceState(null, null, '/states');
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
computeForceNarrow: function (narrow, dockedSidebar) {
|
computeForceNarrow(narrow, dockedSidebar) {
|
||||||
return narrow || !dockedSidebar;
|
return narrow || !dockedSidebar;
|
||||||
},
|
}
|
||||||
|
|
||||||
computeDockedSidebar: function (hass) {
|
computeDockedSidebar(hass) {
|
||||||
return hass.dockedSidebar;
|
return hass.dockedSidebar;
|
||||||
},
|
}
|
||||||
|
|
||||||
_computeSelected: function (routeData) {
|
_computeSelected(routeData) {
|
||||||
return routeData.panel || 'states';
|
return routeData.panel || 'states';
|
||||||
},
|
}
|
||||||
|
|
||||||
_computeDisableSwipe: function (routeData) {
|
_computeDisableSwipe(routeData) {
|
||||||
return NON_SWIPABLE_PANELS.indexOf(routeData.panel) !== -1;
|
return NON_SWIPABLE_PANELS.indexOf(routeData.panel) !== -1;
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
customElements.define(HomeAssistantMain.is, HomeAssistantMain);
|
||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user