From 3b0adffaa0c14d14165583c878ed4d7fd2f73309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Mon, 12 Jul 2021 16:56:38 +0200 Subject: [PATCH] no message --- dist/plex-meets-homeassistant.js | 97 ++++++++++++++++++++++++-------- src/editor.ts | 94 ++++++++++++++++++++++++------- 2 files changed, 148 insertions(+), 43 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 4d82fc2..ca55557 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19491,11 +19491,19 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } if (!lodash.isEmpty(this.libraryName.value)) { this.config.libraryName = this.libraryName.value; - let sortOrderValue = 'asc'; - if (lodash.isEqual(this.sortOrder.value, 'Descending')) { + let sortOrderValue = ''; + if (lodash.isEqual(this.sortOrder.value, 'Ascending')) { + sortOrderValue = 'asc'; + } + else if (lodash.isEqual(this.sortOrder.value, 'Descending')) { sortOrderValue = 'desc'; } - this.config.sort = `${this.sort.value}:${sortOrderValue}`; + if (!lodash.isEmpty(sortOrderValue) && !lodash.isEmpty(this.sort.value)) { + this.config.sort = `${this.sort.value}:${sortOrderValue}`; + } + else { + this.config.sort = ``; + } if (lodash.isEmpty(this.maxCount.value)) { this.config.maxCount = ''; } @@ -19724,30 +19732,11 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.plexValidSection.appendChild(this.maxCount); this.sort.innerHTML = ''; const sortItems = document.createElement('paper-listbox'); - sortItems.appendChild(addDropdownItem('titleSort')); - sortItems.appendChild(addDropdownItem('title')); - sortItems.appendChild(addDropdownItem('year')); - sortItems.appendChild(addDropdownItem('originallyAvailableAt')); - sortItems.appendChild(addDropdownItem('rating')); - sortItems.appendChild(addDropdownItem('audienceRating')); - sortItems.appendChild(addDropdownItem('userRating')); - sortItems.appendChild(addDropdownItem('contentRating')); - sortItems.appendChild(addDropdownItem('unviewedLeafCount')); - sortItems.appendChild(addDropdownItem('episode.addedAt')); - sortItems.appendChild(addDropdownItem('addedAt')); - sortItems.appendChild(addDropdownItem('lastViewedAt')); sortItems.slot = 'dropdown-content'; this.sort.label = 'Sort'; this.sort.appendChild(sortItems); this.sort.style.width = '100%'; this.sort.addEventListener('value-changed', this.valueUpdated); - if (lodash.isEmpty(this.config.sort)) { - this.sort.value = 'title'; - } - else { - // eslint-disable-next-line prefer-destructuring - this.sort.value = this.config.sort.split(':')[0]; - } this.plexValidSection.appendChild(this.sort); this.sortOrder.innerHTML = ''; const sortOrderItems = document.createElement('paper-listbox'); @@ -19855,6 +19844,70 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { }); this.libraryName.disabled = false; this.libraryName.value = this.config.libraryName; + let libraryType = ''; + lodash.forEach(this.sections, section => { + if (lodash.isEqual(section.title, this.libraryName.value)) { + libraryType = section.type; + return false; + } + }); + console.log(libraryType); + if (lodash.isEqual(libraryType, 'show')) { + sortItems.appendChild(addDropdownItem('titleSort')); + sortItems.appendChild(addDropdownItem('title')); + sortItems.appendChild(addDropdownItem('year')); + sortItems.appendChild(addDropdownItem('originallyAvailableAt')); + sortItems.appendChild(addDropdownItem('rating')); + sortItems.appendChild(addDropdownItem('audienceRating')); + sortItems.appendChild(addDropdownItem('userRating')); + sortItems.appendChild(addDropdownItem('contentRating')); + sortItems.appendChild(addDropdownItem('unviewedLeafCount')); + sortItems.appendChild(addDropdownItem('episode.addedAt')); + sortItems.appendChild(addDropdownItem('addedAt')); + sortItems.appendChild(addDropdownItem('lastViewedAt')); + this.sort.style.display = 'block'; + this.sortOrder.style.display = 'block'; + } + else if (lodash.isEqual(libraryType, 'movie')) { + sortItems.appendChild(addDropdownItem('titleSort')); + sortItems.appendChild(addDropdownItem('title')); + sortItems.appendChild(addDropdownItem('originallyAvailableAt')); + sortItems.appendChild(addDropdownItem('rating')); + sortItems.appendChild(addDropdownItem('audienceRating')); + sortItems.appendChild(addDropdownItem('userRating')); + sortItems.appendChild(addDropdownItem('duration')); + sortItems.appendChild(addDropdownItem('viewOffset')); + sortItems.appendChild(addDropdownItem('viewCount')); + sortItems.appendChild(addDropdownItem('addedAt')); + sortItems.appendChild(addDropdownItem('lastViewedAt')); + sortItems.appendChild(addDropdownItem('mediaHeight')); + sortItems.appendChild(addDropdownItem('mediaBitrate')); + this.sort.style.display = 'block'; + this.sortOrder.style.display = 'block'; + } + else { + this.sort.style.display = 'none'; + this.sortOrder.style.display = 'none'; + this.config.sort = ''; + } + if (lodash.isEmpty(this.config.sort)) { + this.sort.value = ''; + this.sortOrder.value = ''; + } + else { + // eslint-disable-next-line prefer-destructuring + this.sort.value = this.config.sort.split(':')[0]; + const sortOrder = this.config.sort.split(':')[1]; + if (lodash.isEmpty(sortOrder)) { + this.sortOrder.value = 'Ascending'; + } + else if (lodash.isEqual(sortOrder, 'asc')) { + this.sortOrder.value = 'Ascending'; + } + else if (lodash.isEqual(sortOrder, 'desc')) { + this.sortOrder.value = 'Descending'; + } + } this.plexValidSection.style.display = 'block'; } this.content.appendChild(this.plexValidSection); diff --git a/src/editor.ts b/src/editor.ts index f57a95d..c0952ed 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -90,11 +90,18 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { if (!_.isEmpty(this.libraryName.value)) { this.config.libraryName = this.libraryName.value; - let sortOrderValue = 'asc'; - if (_.isEqual(this.sortOrder.value, 'Descending')) { + let sortOrderValue = ''; + if (_.isEqual(this.sortOrder.value, 'Ascending')) { + sortOrderValue = 'asc'; + } else if (_.isEqual(this.sortOrder.value, 'Descending')) { sortOrderValue = 'desc'; } - this.config.sort = `${this.sort.value}:${sortOrderValue}`; + if (!_.isEmpty(sortOrderValue) && !_.isEmpty(this.sort.value)) { + this.config.sort = `${this.sort.value}:${sortOrderValue}`; + } else { + this.config.sort = ``; + } + if (_.isEmpty(this.maxCount.value)) { this.config.maxCount = ''; } else { @@ -334,30 +341,13 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.plexValidSection.appendChild(this.maxCount); this.sort.innerHTML = ''; + const sortItems: any = document.createElement('paper-listbox'); - sortItems.appendChild(addDropdownItem('titleSort')); - sortItems.appendChild(addDropdownItem('title')); - sortItems.appendChild(addDropdownItem('year')); - sortItems.appendChild(addDropdownItem('originallyAvailableAt')); - sortItems.appendChild(addDropdownItem('rating')); - sortItems.appendChild(addDropdownItem('audienceRating')); - sortItems.appendChild(addDropdownItem('userRating')); - sortItems.appendChild(addDropdownItem('contentRating')); - sortItems.appendChild(addDropdownItem('unviewedLeafCount')); - sortItems.appendChild(addDropdownItem('episode.addedAt')); - sortItems.appendChild(addDropdownItem('addedAt')); - sortItems.appendChild(addDropdownItem('lastViewedAt')); sortItems.slot = 'dropdown-content'; this.sort.label = 'Sort'; this.sort.appendChild(sortItems); this.sort.style.width = '100%'; this.sort.addEventListener('value-changed', this.valueUpdated); - if (_.isEmpty(this.config.sort)) { - this.sort.value = 'title'; - } else { - // eslint-disable-next-line prefer-destructuring - this.sort.value = this.config.sort.split(':')[0]; - } this.plexValidSection.appendChild(this.sort); this.sortOrder.innerHTML = ''; @@ -468,6 +458,68 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { }); this.libraryName.disabled = false; this.libraryName.value = this.config.libraryName; + + let libraryType = ''; + _.forEach(this.sections, section => { + if (_.isEqual(section.title, this.libraryName.value)) { + libraryType = section.type; + return false; + } + }); + console.log(libraryType); + if (_.isEqual(libraryType, 'show')) { + sortItems.appendChild(addDropdownItem('titleSort')); + sortItems.appendChild(addDropdownItem('title')); + sortItems.appendChild(addDropdownItem('year')); + sortItems.appendChild(addDropdownItem('originallyAvailableAt')); + sortItems.appendChild(addDropdownItem('rating')); + sortItems.appendChild(addDropdownItem('audienceRating')); + sortItems.appendChild(addDropdownItem('userRating')); + sortItems.appendChild(addDropdownItem('contentRating')); + sortItems.appendChild(addDropdownItem('unviewedLeafCount')); + sortItems.appendChild(addDropdownItem('episode.addedAt')); + sortItems.appendChild(addDropdownItem('addedAt')); + sortItems.appendChild(addDropdownItem('lastViewedAt')); + this.sort.style.display = 'block'; + this.sortOrder.style.display = 'block'; + } else if (_.isEqual(libraryType, 'movie')) { + sortItems.appendChild(addDropdownItem('titleSort')); + sortItems.appendChild(addDropdownItem('title')); + sortItems.appendChild(addDropdownItem('originallyAvailableAt')); + sortItems.appendChild(addDropdownItem('rating')); + sortItems.appendChild(addDropdownItem('audienceRating')); + sortItems.appendChild(addDropdownItem('userRating')); + sortItems.appendChild(addDropdownItem('duration')); + sortItems.appendChild(addDropdownItem('viewOffset')); + sortItems.appendChild(addDropdownItem('viewCount')); + sortItems.appendChild(addDropdownItem('addedAt')); + sortItems.appendChild(addDropdownItem('lastViewedAt')); + sortItems.appendChild(addDropdownItem('mediaHeight')); + sortItems.appendChild(addDropdownItem('mediaBitrate')); + this.sort.style.display = 'block'; + this.sortOrder.style.display = 'block'; + } else { + this.sort.style.display = 'none'; + this.sortOrder.style.display = 'none'; + this.config.sort = ''; + } + + if (_.isEmpty(this.config.sort)) { + this.sort.value = ''; + this.sortOrder.value = ''; + } else { + // eslint-disable-next-line prefer-destructuring + this.sort.value = this.config.sort.split(':')[0]; + const sortOrder = this.config.sort.split(':')[1]; + if (_.isEmpty(sortOrder)) { + this.sortOrder.value = 'Ascending'; + } else if (_.isEqual(sortOrder, 'asc')) { + this.sortOrder.value = 'Ascending'; + } else if (_.isEqual(sortOrder, 'desc')) { + this.sortOrder.value = 'Descending'; + } + } + this.plexValidSection.style.display = 'block'; } this.content.appendChild(this.plexValidSection);