Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Commit 38f6a1d

Browse files
committed
fix hiding of settings, restore default header on template fail
1 parent e8b6426 commit 38f6a1d

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

.devcontainer/ui-lovelace.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ custom_header:
44
tab: 1to3
55
config:
66
background: green
7-
test_template: '{{ viewIndex }}'
87
# split_mode: true
98
template_variables: '{% set clock = (now().strftime("%I")|int)~now().strftime(":%M") %}'
109
background: '{{ states.input_text.background.state }}'
@@ -32,7 +31,14 @@ custom_header:
3231
button_icons:
3332
menu: '{% if states.input_boolean.icon_changes.state == "on" %}mdi:xbox-controller-menu{% endif %}'
3433
voice: '{% if states.input_boolean.icon_changes.state == "on" %}mdi:microphone-variant{%else%}mdi:comment-processing{% endif %}'
35-
options: '{% if states.input_boolean.icon_changes.state == "on" %}mdi:dots-horizontal{% endif %}'
34+
options: >-
35+
{%- set mapper = {'1':'one','2':'two','3':'three','4':'four','5':'five','6':'six',
36+
'7':'seven','8':'eight','9':'nine','10':'ten','11':'eleven','12':'twelve'} -%}
37+
{% set digit = now().strftime('%-I') %}
38+
{%- set word = mapper[digit] -%}
39+
{%- if states('sun.sun') == 'above_horizon' -%}mdi:clock-time-{{word}}
40+
{%- else -%}mdi:clock-time-{{word}}-outline
41+
{% endif %}
3642
button_text:
3743
menu: '{% if states.input_boolean.text_changes.state == "on" %}Menu{% endif %}'
3844
options: '{% if states.input_boolean.text_changes.state == "on" %}{{dayNameLong}}<br>{{date}}{% endif %}'

src/config.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class CustomHeaderConfig {
3535
}
3636

3737
this.renderTemplate(ch, ha_elements(), lovelace);
38-
this.catchTemplate(lovelace);
38+
this.catchTemplate(lovelace, haElem, ch);
3939
}
4040

4141
static renderTemplate(ch, haElem, lovelace) {
@@ -53,6 +53,8 @@ export class CustomHeaderConfig {
5353
} catch (e) {
5454
this.template_failed = true;
5555
this.helpfulTempError(result, e);
56+
this.config = { disabled_mode: true };
57+
this.processAndContinue(ch, haElem);
5658
}
5759
if (JSON.stringify(window.last_template_result) == JSON.stringify(this.config)) {
5860
this.changed = false;
@@ -92,7 +94,7 @@ export class CustomHeaderConfig {
9294
else return;
9395
}
9496

95-
static async catchTemplate(lovelace) {
97+
static async catchTemplate(lovelace, haElem, ch) {
9698
try {
9799
const unsub = await this.unsub;
98100
if (this.changed) {
@@ -107,6 +109,8 @@ export class CustomHeaderConfig {
107109
if (this.disabled || !lovelace.config.custom_header) return;
108110
console.log('[CUSTOM-HEADER] There was an error with one or more of your templates:');
109111
console.log(`${e.message.substring(0, e.message.indexOf(')'))})`);
112+
haElem.appHeader.style.display = '';
113+
insertSettings(ch.header, {}, haElem, haElem.hass.user);
110114
}
111115
}
112116

src/custom-header.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { ha_elements, hass } from './ha-elements';
33
import { CustomHeader } from './build-header';
44
import { CustomHeaderConfig } from './config';
55

6+
const hideHeader = haElem => {
7+
if (!haElem || !haElem.appHeader) return;
8+
haElem.appHeader.style.display = 'none';
9+
};
10+
11+
if (!window.location.href.includes('disable_ch')) hideHeader(ha_elements());
12+
613
const conInfo = {
714
header: `%c☰ CUSTOM HEADER *DEV `,
815
user: `%cUser's Name: ${hass.user.name}`,
@@ -44,13 +51,6 @@ console.info(
4451
`${header} ${info} padding-bottom:6px; border-width: 0px 1px 1px 1px;`,
4552
);
4653

47-
const hideHeader = haElem => {
48-
if (!haElem || !haElem.appHeader) return;
49-
haElem.appHeader.style.display = 'none';
50-
};
51-
52-
if (!window.location.href.includes('disable_ch')) hideHeader(ha_elements());
53-
5454
export const rebuild = () => {
5555
const haElem = ha_elements();
5656
if (

src/overflow-menu.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ const showEditor = haElem => {
8686
}
8787
};
8888

89-
export const insertSettings = (header, config, haElem) => {
89+
export const insertSettings = (header, config, haElem, user) => {
90+
if (config.hide_ch_settings || (user && !user.is_admin && !user.is_owner && config.restrict_users)) {
91+
return;
92+
}
9093
if (haElem.lovelace.mode === 'storage') {
9194
let chSettings = document.createElement('paper-item');
9295
if (header.options.querySelector('mwc-list-item')) {

src/style-header.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export const styleHeader = (config, ch, haElem = ha_elements()) => {
1414
const user = haElem.hass.user;
1515
if (!user.is_admin && !user.is_owner && config.restrict_users) {
1616
config.disabled_mode = false;
17-
} else if (!config.hide_ch_settings) {
18-
insertSettings(ch.header, config, haElem);
1917
}
2018

19+
insertSettings(ch.header, config, haElem, user);
20+
2121
if (config.disabled_mode) {
2222
window.customHeaderDisabled = true;
2323
removeKioskMode(haElem);

0 commit comments

Comments
 (0)