More layout fixes. Also fix thermostat not rendering

This commit is contained in:
Thomas Lovén 2018-11-07 12:48:31 +01:00
parent 3acbf0896f
commit c8847a1a3f

View File

@ -3,10 +3,6 @@ class LayoutCard extends Polymer.Element {
static get template() {
return Polymer.html`
<style>
:host {
padding: 4px 4px 0;
display: block;
}
#columns {
display: flex;
flex-direction: row;
@ -18,6 +14,9 @@ class LayoutCard extends Polymer.Element {
max-width: 500px;
overflow-x: hidden;
}
.column > *:first-child {
margin-top: 0;
}
.column > * {
display: block;
margin: 4px 4px 8px;
@ -46,13 +45,6 @@ class LayoutCard extends Polymer.Element {
this.config.column_width = this.config.column_width || 300;
this.config.layout = this.config.layout || 'auto';
this._cards = config.cards.map((c) => {
if (typeof c === 'string') return c;
let el = this.makeCard(c);
if (this.hass) el.hass = this.hass;
return el;
});
window.addEventListener('resize', () => this._updateColumns());
window.addEventListener('hass-open-menu', () => setTimeout(() => this._updateColumns(), 10));
window.addEventListener('hass-close-menu', () => setTimeout(() => this._updateColumns(), 10));
@ -60,6 +52,14 @@ class LayoutCard extends Polymer.Element {
}
_updateColumns() {
if (this.parentElement.id === "view")
{
this.style.padding = "8px 4px 0";
this.style.display = "block";
} else {
this.style.marginRight = "0";
this.style.marginLeft = "0";
}
let numcols = 0;
if (this.config.column_num) {
numcols = this.config.column_num;
@ -68,7 +68,6 @@ class LayoutCard extends Polymer.Element {
numcols = Math.max(1,
Math.floor(this.$.columns.clientWidth/this.config.column_width));
}
console.log(numcols);
if(numcols != this.colnum) {
this.colnum = numcols;
this._build();
@ -79,6 +78,13 @@ class LayoutCard extends Polymer.Element {
const root = this.$.columns;
while(root.lastChild) root.removeChild(root.lastChild);
this._cards = this.config.cards.map((c) => {
if (typeof c === 'string') return c;
let el = this.makeCard(c);
if (this._hass) el.hass = this._hass;
return el;
});
let cols = [];
let colLen = [];
for(let i = 0; i < this.colnum; i++) {
@ -148,6 +154,8 @@ class LayoutCard extends Polymer.Element {
}
set hass(hass) {
this._hass = hass;
if(this._cards)
this._cards.filter(c => typeof c !== 'string').forEach(c => c.hass = hass);
}