forked from platypush/platypush
A more efficient and clean logic for selectedEntities
calculation.
This commit is contained in:
parent
394e27eaf2
commit
2398cac572
1 changed files with 16 additions and 10 deletions
|
@ -89,21 +89,27 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
selectedEntities() {
|
selectedEntities() {
|
||||||
const searchTerm = (this.searchTerm || '').toLowerCase()
|
if (!this.searchTerm?.length)
|
||||||
|
return this.entityGroups.id
|
||||||
|
|
||||||
|
const searchTerm = this.searchTerm.toLowerCase().trim()
|
||||||
return Object.values(this.entityGroups.id).filter((entity) => {
|
return Object.values(this.entityGroups.id).filter((entity) => {
|
||||||
if (!this.selectedGroups[entity[this.value?.grouping]])
|
if (!this.selectedGroups[entity[this.value?.grouping]])
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if (searchTerm?.length) {
|
if (!searchTerm?.length)
|
||||||
return (
|
return true
|
||||||
((entity.name || '').toLowerCase()).indexOf(searchTerm) >= 0 ||
|
|
||||||
((entity.plugin || '').toLowerCase()).indexOf(searchTerm) >= 0 ||
|
for (const attr of ['id', 'external_id', 'name', 'plugin']) {
|
||||||
((entity.external_id || '').toLowerCase()).indexOf(searchTerm) >= 0 ||
|
if (!entity[attr])
|
||||||
(entity.id || 0).toString() == searchTerm
|
continue
|
||||||
)
|
|
||||||
|
const entityValue = entity[attr].toString().toLowerCase()
|
||||||
|
if (entityValue.indexOf(searchTerm) >= 0)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return false
|
||||||
}).reduce((obj, entity) => {
|
}).reduce((obj, entity) => {
|
||||||
obj[entity.id] = entity
|
obj[entity.id] = entity
|
||||||
return obj
|
return obj
|
||||||
|
|
Loading…
Reference in a new issue