Skip to content

Commit de44738

Browse files
committed
Code improvements
Signed-off-by: Florian Hotze <[email protected]>
1 parent bcfbb3b commit de44738

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

bundles/org.openhab.ui/web/src/pages/settings/items/items-list-vlist.vue

+30-14
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@
7272

7373
<f7-col v-show="ready && items.length > 0">
7474
<f7-block-title class="no-margin-top">
75-
<span>{{ getListSize() }} <template v-if="$refs.searchbar?.f7Searchbar.query">of {{ items.length }} </template>Items<template v-if="$refs.searchbar?.f7Searchbar.query"> found</template></span>
76-
<template v-if="showCheckboxes && getListSize() > 0">
75+
<span>
76+
{{ listTitle }}
77+
</span>
78+
<template v-if="showCheckboxes && filteredItemsCount > 0">
7779
-
78-
<f7-link @click="selectDeselectAll" :text="areAllSelected() ? 'Deselect all' : 'Select all'" />
80+
<f7-link @click="selectDeselectAll" :text="allSelected ? 'Deselect all' : 'Select all'" />
7981
</template>
8082
</f7-block-title>
8183
<f7-list
@@ -171,6 +173,7 @@ export default {
171173
renderExternal: this.renderExternal,
172174
height: this.height
173175
},
176+
searchQuery: '',
174177
selectedItems: [],
175178
showCheckboxes: false,
176179
eventSource: null
@@ -228,7 +231,8 @@ export default {
228231
this.$oh.sse.close(this.eventSource)
229232
this.eventSource = null
230233
},
231-
filterSelectedItems (query) {
234+
filterSelectedItems (event) {
235+
this.searchQuery = event?.query
232236
if (!this.$refs.itemsList.f7VirtualList.filteredItems) {
233237
return
234238
}
@@ -251,12 +255,6 @@ export default {
251255
renderExternal (vl, vlData) {
252256
this.vlData = vlData
253257
},
254-
getListSize () {
255-
if (this.$refs.searchbar?.f7Searchbar.query) {
256-
return this.$refs.itemsList.f7VirtualList.filteredItems.length
257-
}
258-
return this.items.length
259-
},
260258
height (item) {
261259
let vlHeight
262260
if (this.$theme.ios) vlHeight = 78
@@ -299,11 +297,8 @@ export default {
299297
this.selectedItems.push(item)
300298
}
301299
},
302-
areAllSelected () {
303-
return this.selectedItems.length >= this.getListSize()
304-
},
305300
selectDeselectAll () {
306-
if (this.areAllSelected()) {
301+
if (this.allSelected) {
307302
this.selectedItems = []
308303
} else if (this.$refs.itemsList.f7VirtualList.filteredItems?.length > 0) {
309304
this.selectedItems = this.$refs.itemsList.f7VirtualList.filteredItems.map((i) => i.name)
@@ -366,6 +361,27 @@ export default {
366361
computed: {
367362
searchPlaceholder () {
368363
return window.innerWidth >= 1280 ? 'Search (for advanced search, use the developer sidebar (Shift+Alt+D))' : 'Search'
364+
},
365+
filteredItemsCount () {
366+
if (this.searchQuery) {
367+
return this.$refs.itemsList.f7VirtualList.filteredItems.length
368+
}
369+
return this.items.length
370+
},
371+
allSelected () {
372+
return this.selectedItems.length >= this.filteredItemsCount
373+
},
374+
listTitle () {
375+
let title = this.filteredItemsCount
376+
if (this.searchQuery !== '') {
377+
title += ` of ${this.items.length} Items found`
378+
} else {
379+
title += ' Items'
380+
}
381+
if (this.selectedItems.length > 0) {
382+
title += `, ${this.selectedItems.length} selected`
383+
}
384+
return title
369385
}
370386
}
371387
}

0 commit comments

Comments
 (0)