From 0dc051fac11543dc39b6d9d1d2f06da845303d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Mon, 12 Jul 2021 14:18:17 +0200 Subject: [PATCH] no message --- dist/plex-meets-homeassistant.js | 67 +++++++++++++++++------------ src/editor.ts | 72 +++++++++++++++++++------------- 2 files changed, 85 insertions(+), 54 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 6dd180c..70affd5 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19659,37 +19659,52 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } } this.plexValidSection.appendChild(this.sortOrder); - const devicesTitle = document.createElement('h2'); - devicesTitle.innerHTML = `Devices Configuration`; - devicesTitle.style.lineHeight = '29px'; - devicesTitle.style.marginBottom = '0px'; - devicesTitle.style.marginTop = '20px'; - const addDeviceButton = document.createElement('button'); - addDeviceButton.style.float = 'right'; - addDeviceButton.style.fontSize = '20px'; - addDeviceButton.style.cursor = 'pointer'; - addDeviceButton.innerHTML = '+'; - addDeviceButton.addEventListener('click', () => { - const entitiesDropdown = createEntitiesDropdown('', this.valueUpdated); - if (entitiesDropdown) { - this.content.appendChild(entitiesDropdown); - } - }); - devicesTitle.appendChild(addDeviceButton); - this.plexValidSection.appendChild(devicesTitle); - if (lodash.isString(this.config.entity)) { - this.config.entity = [this.config.entity]; - } + let hasUIConfig = true; if (lodash.isArray(this.config.entity)) { + // eslint-disable-next-line consistent-return lodash.forEach(this.config.entity, entity => { - if (lodash.isString(entity)) { - const entitiesDropdown = createEntitiesDropdown(entity, this.valueUpdated); - if (entitiesDropdown) { - this.plexValidSection.appendChild(entitiesDropdown); - } + if (lodash.isObjectLike(entity)) { + hasUIConfig = false; + return false; } }); } + else if (lodash.isObjectLike(this.config.entity)) { + hasUIConfig = false; + } + if (hasUIConfig) { + const devicesTitle = document.createElement('h2'); + devicesTitle.innerHTML = `Devices Configuration`; + devicesTitle.style.lineHeight = '29px'; + devicesTitle.style.marginBottom = '0px'; + devicesTitle.style.marginTop = '20px'; + const addDeviceButton = document.createElement('button'); + addDeviceButton.style.float = 'right'; + addDeviceButton.style.fontSize = '20px'; + addDeviceButton.style.cursor = 'pointer'; + addDeviceButton.innerHTML = '+'; + addDeviceButton.addEventListener('click', () => { + const entitiesDropdown = createEntitiesDropdown('', this.valueUpdated); + if (entitiesDropdown) { + this.content.appendChild(entitiesDropdown); + } + }); + devicesTitle.appendChild(addDeviceButton); + this.plexValidSection.appendChild(devicesTitle); + if (lodash.isString(this.config.entity)) { + this.config.entity = [this.config.entity]; + } + if (lodash.isArray(this.config.entity)) { + lodash.forEach(this.config.entity, entity => { + if (lodash.isString(entity)) { + const entitiesDropdown = createEntitiesDropdown(entity, this.valueUpdated); + if (entitiesDropdown) { + this.plexValidSection.appendChild(entitiesDropdown); + } + } + }); + } + } if (!lodash.isEmpty(this.sections)) { lodash.forEach(this.sections, (section) => { libraryItems.appendChild(addDropdownItem(section.title)); diff --git a/src/editor.ts b/src/editor.ts index 1b1f25d..fe214ee 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -266,39 +266,55 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } this.plexValidSection.appendChild(this.sortOrder); - const devicesTitle = document.createElement('h2'); - devicesTitle.innerHTML = `Devices Configuration`; - devicesTitle.style.lineHeight = '29px'; - devicesTitle.style.marginBottom = '0px'; - devicesTitle.style.marginTop = '20px'; - - const addDeviceButton = document.createElement('button'); - addDeviceButton.style.float = 'right'; - addDeviceButton.style.fontSize = '20px'; - addDeviceButton.style.cursor = 'pointer'; - addDeviceButton.innerHTML = '+'; - addDeviceButton.addEventListener('click', () => { - const entitiesDropdown = createEntitiesDropdown('', this.valueUpdated); - if (entitiesDropdown) { - this.content.appendChild(entitiesDropdown); - } - }); - devicesTitle.appendChild(addDeviceButton); - - this.plexValidSection.appendChild(devicesTitle); - if (_.isString(this.config.entity)) { - this.config.entity = [this.config.entity]; - } + let hasUIConfig = true; if (_.isArray(this.config.entity)) { + // eslint-disable-next-line consistent-return _.forEach(this.config.entity, entity => { - if (_.isString(entity)) { - const entitiesDropdown = createEntitiesDropdown(entity, this.valueUpdated); - if (entitiesDropdown) { - this.plexValidSection.appendChild(entitiesDropdown); - } + if (_.isObjectLike(entity)) { + hasUIConfig = false; + return false; } }); + } else if (_.isObjectLike(this.config.entity)) { + hasUIConfig = false; } + + if (hasUIConfig) { + const devicesTitle = document.createElement('h2'); + devicesTitle.innerHTML = `Devices Configuration`; + devicesTitle.style.lineHeight = '29px'; + devicesTitle.style.marginBottom = '0px'; + devicesTitle.style.marginTop = '20px'; + + const addDeviceButton = document.createElement('button'); + addDeviceButton.style.float = 'right'; + addDeviceButton.style.fontSize = '20px'; + addDeviceButton.style.cursor = 'pointer'; + addDeviceButton.innerHTML = '+'; + addDeviceButton.addEventListener('click', () => { + const entitiesDropdown = createEntitiesDropdown('', this.valueUpdated); + if (entitiesDropdown) { + this.content.appendChild(entitiesDropdown); + } + }); + devicesTitle.appendChild(addDeviceButton); + + this.plexValidSection.appendChild(devicesTitle); + if (_.isString(this.config.entity)) { + this.config.entity = [this.config.entity]; + } + if (_.isArray(this.config.entity)) { + _.forEach(this.config.entity, entity => { + if (_.isString(entity)) { + const entitiesDropdown = createEntitiesDropdown(entity, this.valueUpdated); + if (entitiesDropdown) { + this.plexValidSection.appendChild(entitiesDropdown); + } + } + }); + } + } + if (!_.isEmpty(this.sections)) { _.forEach(this.sections, (section: Record) => { libraryItems.appendChild(addDropdownItem(section.title));