2.0
Juraj Nyíri 3 years ago
parent f76c4c054b
commit e5d16ab46c

@ -19454,6 +19454,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.libraryName = document.createElement('paper-dropdown-menu'); this.libraryName = document.createElement('paper-dropdown-menu');
this.protocol = document.createElement('paper-dropdown-menu'); this.protocol = document.createElement('paper-dropdown-menu');
this.tabs = document.createElement('paper-tabs'); this.tabs = document.createElement('paper-tabs');
this.sort = document.createElement('paper-dropdown-menu');
this.sortOrder = document.createElement('paper-dropdown-menu');
this.devicesTabs = 0; this.devicesTabs = 0;
this.entities = []; this.entities = [];
this.sections = []; this.sections = [];
@ -19472,6 +19474,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
return event; return event;
}; };
this.valueUpdated = () => { this.valueUpdated = () => {
console.log('valueUpdated');
if (!lodash.isEmpty(this.libraryName.value)) { if (!lodash.isEmpty(this.libraryName.value)) {
const originalConfig = lodash.clone(this.config); const originalConfig = lodash.clone(this.config);
this.config.ip = this.ip.value; this.config.ip = this.ip.value;
@ -19479,21 +19482,24 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.port = this.port.value; this.config.port = this.port.value;
this.config.libraryName = this.libraryName.value; this.config.libraryName = this.libraryName.value;
this.config.protocol = this.protocol.value; this.config.protocol = this.protocol.value;
this.config.sort = `${this.sort.value}:${this.sortOrder.value}`;
if (lodash.isEmpty(this.maxCount.value)) { if (lodash.isEmpty(this.maxCount.value)) {
this.config.maxCount = ''; this.config.maxCount = '';
} }
else { else {
this.config.maxCount = parseInt(this.maxCount.value, 10); this.config.maxCount = this.maxCount.value;
} }
if (!lodash.isEmpty(this.entities)) { if (!lodash.isEmpty(this.entities)) {
this.config.entity = []; this.config.entity = [];
lodash.forEach(this.entities, entity => { lodash.forEach(this.entities, entity => {
if (!lodash.isEmpty(entity.value)) { if (!lodash.isEmpty(entity.value) && !lodash.includes(this.config.entity, entity.value)) {
this.config.entity.push(entity.value); this.config.entity.push(entity.value);
} }
}); });
} }
if (!lodash.isEqual(this.config, originalConfig)) { if (!lodash.isEqual(this.config, originalConfig)) {
console.log(this.config);
console.log(originalConfig);
this.fireEvent(this, 'config-changed', { config: this.config }); this.fireEvent(this, 'config-changed', { config: this.config });
} }
} }
@ -19569,11 +19575,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.port.type = 'number'; this.port.type = 'number';
this.port.addEventListener('change', this.valueUpdated); this.port.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.port); this.content.appendChild(this.port);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.maxCount);
this.libraryName.innerHTML = ''; this.libraryName.innerHTML = '';
const libraryItems = document.createElement('paper-listbox'); const libraryItems = document.createElement('paper-listbox');
libraryItems.appendChild(addDropdownItem('Continue Watching')); libraryItems.appendChild(addDropdownItem('Continue Watching'));
@ -19599,6 +19600,67 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
} }
} }
this.plexValidSection.style.display = 'none'; this.plexValidSection.style.display = 'none';
this.plexValidSection.innerHTML = '';
const viewTitle = document.createElement('h2');
viewTitle.innerHTML = `View Configuration`;
viewTitle.style.lineHeight = '29px';
viewTitle.style.marginBottom = '0px';
viewTitle.style.marginTop = '20px';
this.plexValidSection.appendChild(viewTitle);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
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');
sortOrderItems.appendChild(addDropdownItem('asc'));
sortOrderItems.appendChild(addDropdownItem('desc'));
sortOrderItems.slot = 'dropdown-content';
this.sortOrder.label = 'Sort Order';
this.sortOrder.appendChild(sortOrderItems);
this.sortOrder.style.width = '100%';
this.sortOrder.addEventListener('value-changed', this.valueUpdated);
if (lodash.isEmpty(this.config.sort)) {
this.sortOrder.value = 'asc';
}
else {
const sortOrder = this.config.sort.split(':')[1];
if (lodash.isEmpty(sortOrder)) {
this.sortOrder.value = 'asc';
}
else {
this.sortOrder.value = sortOrder;
}
}
this.plexValidSection.appendChild(this.sortOrder);
const devicesTitle = document.createElement('h2'); const devicesTitle = document.createElement('h2');
devicesTitle.innerHTML = `Devices Configuration`; devicesTitle.innerHTML = `Devices Configuration`;
devicesTitle.style.lineHeight = '29px'; devicesTitle.style.lineHeight = '29px';
@ -19616,7 +19678,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
} }
}); });
devicesTitle.appendChild(addDeviceButton); devicesTitle.appendChild(addDeviceButton);
this.plexValidSection.innerHTML = '';
this.plexValidSection.appendChild(devicesTitle); this.plexValidSection.appendChild(devicesTitle);
if (lodash.isString(this.config.entity)) { if (lodash.isString(this.config.entity)) {
this.config.entity = [this.config.entity]; this.config.entity = [this.config.entity];
@ -19652,6 +19713,9 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
else { else {
this.config.protocol = 'http'; this.config.protocol = 'http';
} }
if (!config.sort) {
this.config.sort = 'titleSort:asc';
}
this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
this.render(); this.render();
}; };
@ -20618,6 +20682,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.render(); this.render();
} }
else { else {
console.log('RETRY');
setTimeout(() => { setTimeout(() => {
this.renderInitialData(); this.renderInitialData();
}, 250); }, 250);

@ -30,6 +30,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
tabs: any = document.createElement('paper-tabs'); tabs: any = document.createElement('paper-tabs');
sort: any = document.createElement('paper-dropdown-menu');
sortOrder: any = document.createElement('paper-dropdown-menu');
devicesTabs = 0; devicesTabs = 0;
hassObj: HomeAssistant | undefined; hassObj: HomeAssistant | undefined;
@ -61,6 +65,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
}; };
valueUpdated = (): void => { valueUpdated = (): void => {
console.log('valueUpdated');
if (!_.isEmpty(this.libraryName.value)) { if (!_.isEmpty(this.libraryName.value)) {
const originalConfig = _.clone(this.config); const originalConfig = _.clone(this.config);
this.config.ip = this.ip.value; this.config.ip = this.ip.value;
@ -69,21 +74,24 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.libraryName = this.libraryName.value; this.config.libraryName = this.libraryName.value;
this.config.protocol = this.protocol.value; this.config.protocol = this.protocol.value;
this.config.sort = `${this.sort.value}:${this.sortOrder.value}`;
if (_.isEmpty(this.maxCount.value)) { if (_.isEmpty(this.maxCount.value)) {
this.config.maxCount = ''; this.config.maxCount = '';
} else { } else {
this.config.maxCount = parseInt(this.maxCount.value, 10); this.config.maxCount = this.maxCount.value;
} }
if (!_.isEmpty(this.entities)) { if (!_.isEmpty(this.entities)) {
this.config.entity = []; this.config.entity = [];
_.forEach(this.entities, entity => { _.forEach(this.entities, entity => {
if (!_.isEmpty(entity.value)) { if (!_.isEmpty(entity.value) && !_.includes(this.config.entity, entity.value)) {
this.config.entity.push(entity.value); this.config.entity.push(entity.value);
} }
}); });
} }
if (!_.isEqual(this.config, originalConfig)) { if (!_.isEqual(this.config, originalConfig)) {
console.log(this.config);
console.log(originalConfig);
this.fireEvent(this, 'config-changed', { config: this.config }); this.fireEvent(this, 'config-changed', { config: this.config });
} }
} }
@ -168,12 +176,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.port.addEventListener('change', this.valueUpdated); this.port.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.port); this.content.appendChild(this.port);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.maxCount);
this.libraryName.innerHTML = ''; this.libraryName.innerHTML = '';
const libraryItems: any = document.createElement('paper-listbox'); const libraryItems: any = document.createElement('paper-listbox');
libraryItems.appendChild(addDropdownItem('Continue Watching')); libraryItems.appendChild(addDropdownItem('Continue Watching'));
@ -201,6 +203,69 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
} }
this.plexValidSection.style.display = 'none'; this.plexValidSection.style.display = 'none';
this.plexValidSection.innerHTML = '';
const viewTitle = document.createElement('h2');
viewTitle.innerHTML = `View Configuration`;
viewTitle.style.lineHeight = '29px';
viewTitle.style.marginBottom = '0px';
viewTitle.style.marginTop = '20px';
this.plexValidSection.appendChild(viewTitle);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
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 = '';
const sortOrderItems: any = document.createElement('paper-listbox');
sortOrderItems.appendChild(addDropdownItem('asc'));
sortOrderItems.appendChild(addDropdownItem('desc'));
sortOrderItems.slot = 'dropdown-content';
this.sortOrder.label = 'Sort Order';
this.sortOrder.appendChild(sortOrderItems);
this.sortOrder.style.width = '100%';
this.sortOrder.addEventListener('value-changed', this.valueUpdated);
if (_.isEmpty(this.config.sort)) {
this.sortOrder.value = 'asc';
} else {
const sortOrder = this.config.sort.split(':')[1];
if (_.isEmpty(sortOrder)) {
this.sortOrder.value = 'asc';
} else {
this.sortOrder.value = sortOrder;
}
}
this.plexValidSection.appendChild(this.sortOrder);
const devicesTitle = document.createElement('h2'); const devicesTitle = document.createElement('h2');
devicesTitle.innerHTML = `Devices Configuration`; devicesTitle.innerHTML = `Devices Configuration`;
devicesTitle.style.lineHeight = '29px'; devicesTitle.style.lineHeight = '29px';
@ -220,7 +285,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
}); });
devicesTitle.appendChild(addDeviceButton); devicesTitle.appendChild(addDeviceButton);
this.plexValidSection.innerHTML = '';
this.plexValidSection.appendChild(devicesTitle); this.plexValidSection.appendChild(devicesTitle);
if (_.isString(this.config.entity)) { if (_.isString(this.config.entity)) {
this.config.entity = [this.config.entity]; this.config.entity = [this.config.entity];
@ -259,6 +323,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.protocol = 'http'; this.config.protocol = 'http';
} }
if (!config.sort) {
this.config.sort = 'titleSort:asc';
}
this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
this.render(); this.render();
}; };

@ -353,6 +353,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.loading = false; this.loading = false;
this.render(); this.render();
} else { } else {
console.log('RETRY');
setTimeout(() => { setTimeout(() => {
this.renderInitialData(); this.renderInitialData();
}, 250); }, 250);

Loading…
Cancel
Save