Update: Sort values are now automatically generated from Plex

pull/51/head
Juraj Nyíri 3 years ago
parent 047dbe2d73
commit 0b481e6e96

@ -20817,12 +20817,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
} }
this.libraryName.disabled = false; this.libraryName.disabled = false;
this.libraryName.value = this.config.libraryName; this.libraryName.value = this.config.libraryName;
let libraryType = '';
let libraryKey = ''; let libraryKey = '';
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
lodash.forEach(this.sections, section => { lodash.forEach(this.sections, section => {
if (lodash.isEqual(section.title, this.libraryName.value)) { if (lodash.isEqual(section.title, this.libraryName.value)) {
libraryType = section.type;
libraryKey = section.key; libraryKey = section.key;
return false; return false;
} }
@ -20864,42 +20862,20 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.displayType = ''; this.config.displayType = '';
this.displayType.value = ''; this.displayType.value = '';
} }
let displayTypeIndex = 0;
if (this.config.displayType) {
lodash.forEach(types, (sectionType, sectionKey) => {
const key = sectionType.key.split('type=')[1];
if (key === parseInt(this.config.displayType, 10)) {
displayTypeIndex = parseInt(sectionKey, 10);
} }
else { });
this.displayType.style.display = 'none';
this.config.displayType = '';
this.displayType.value = '';
}
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')) { const sortFields = lodash.get(libraryData, `[0].Meta.Type[${displayTypeIndex}].Sort`);
sortItems.appendChild(addDropdownItem('titleSort')); if (!lodash.isNil(sortFields) && sortFields.length > 0) {
sortItems.appendChild(addDropdownItem('title')); lodash.forEach(sortFields, (sortField) => {
sortItems.appendChild(addDropdownItem('originallyAvailableAt')); sortItems.appendChild(addDropdownItem(sortField.key));
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.sort.style.display = 'block';
this.sortOrder.style.display = 'block'; this.sortOrder.style.display = 'block';
} }
@ -20908,6 +20884,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.sortOrder.style.display = 'none'; this.sortOrder.style.display = 'none';
this.config.sort = ''; this.config.sort = '';
} }
}
else {
this.displayType.style.display = 'none';
this.config.displayType = '';
this.displayType.value = '';
}
if (lodash.isEmpty(this.config.sort)) { if (lodash.isEmpty(this.config.sort)) {
this.sort.value = ''; this.sort.value = '';
this.sortOrder.value = ''; this.sortOrder.value = '';

@ -781,12 +781,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.libraryName.disabled = false; this.libraryName.disabled = false;
this.libraryName.value = this.config.libraryName; this.libraryName.value = this.config.libraryName;
let libraryType = '';
let libraryKey = ''; let libraryKey = '';
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
_.forEach(this.sections, section => { _.forEach(this.sections, section => {
if (_.isEqual(section.title, this.libraryName.value)) { if (_.isEqual(section.title, this.libraryName.value)) {
libraryType = section.type;
libraryKey = section.key; libraryKey = section.key;
return false; return false;
} }
@ -826,41 +824,21 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.displayType = ''; this.config.displayType = '';
this.displayType.value = ''; this.displayType.value = '';
} }
} else {
this.displayType.style.display = 'none';
this.config.displayType = '';
this.displayType.value = '';
}
if (_.isEqual(libraryType, 'show')) { let displayTypeIndex = 0;
sortItems.appendChild(addDropdownItem('titleSort')); if (this.config.displayType) {
sortItems.appendChild(addDropdownItem('title')); _.forEach(types, (sectionType: Record<string, any>, sectionKey) => {
sortItems.appendChild(addDropdownItem('year')); const key = sectionType.key.split('type=')[1];
sortItems.appendChild(addDropdownItem('originallyAvailableAt')); if (key === parseInt(this.config.displayType, 10)) {
sortItems.appendChild(addDropdownItem('rating')); displayTypeIndex = parseInt(sectionKey, 10);
sortItems.appendChild(addDropdownItem('audienceRating')); }
sortItems.appendChild(addDropdownItem('userRating')); });
sortItems.appendChild(addDropdownItem('contentRating')); }
sortItems.appendChild(addDropdownItem('unviewedLeafCount')); const sortFields = _.get(libraryData, `[0].Meta.Type[${displayTypeIndex}].Sort`);
sortItems.appendChild(addDropdownItem('episode.addedAt')); if (!_.isNil(sortFields) && sortFields.length > 0) {
sortItems.appendChild(addDropdownItem('addedAt')); _.forEach(sortFields, (sortField: Record<string, any>) => {
sortItems.appendChild(addDropdownItem('lastViewedAt')); sortItems.appendChild(addDropdownItem(sortField.key));
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.sort.style.display = 'block';
this.sortOrder.style.display = 'block'; this.sortOrder.style.display = 'block';
} else { } else {
@ -868,6 +846,11 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.sortOrder.style.display = 'none'; this.sortOrder.style.display = 'none';
this.config.sort = ''; this.config.sort = '';
} }
} else {
this.displayType.style.display = 'none';
this.config.displayType = '';
this.displayType.value = '';
}
if (_.isEmpty(this.config.sort)) { if (_.isEmpty(this.config.sort)) {
this.sort.value = ''; this.sort.value = '';

Loading…
Cancel
Save