Skip to content

Commit 44c6d31

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

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
</div>
3636
</f7-toolbar>
3737

38-
<f7-list class="searchbar-not-found">
39-
<f7-list-item title="Nothing found" />
40-
</f7-list>
41-
4238
<f7-block class="block-narrow margin-top-half">
4339
<f7-col>
4440
<div>
@@ -72,12 +68,15 @@
7268

7369
<f7-col v-show="ready && items.length > 0">
7470
<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">
71+
<span>{{ listTitle }}</span>
72+
<template v-if="showCheckboxes && filteredItemsCount > 0">
7773
-
78-
<f7-link @click="selectDeselectAll" :text="areAllSelected() ? 'Deselect all' : 'Select all'" />
74+
<f7-link @click="selectDeselectAll" :text="allSelected ? 'Deselect all' : 'Select all'" />
7975
</template>
8076
</f7-block-title>
77+
<f7-list class="searchbar-not-found">
78+
<f7-list-item title="Nothing found" />
79+
</f7-list>
8180
<f7-list
8281
v-show="items.length > 0"
8382
class="searchbar-found col"
@@ -171,6 +170,7 @@ export default {
171170
renderExternal: this.renderExternal,
172171
height: this.height
173172
},
173+
searchQuery: '',
174174
selectedItems: [],
175175
showCheckboxes: false,
176176
eventSource: null
@@ -228,7 +228,8 @@ export default {
228228
this.$oh.sse.close(this.eventSource)
229229
this.eventSource = null
230230
},
231-
filterSelectedItems (query) {
231+
filterSelectedItems (event) {
232+
this.searchQuery = event?.query
232233
if (!this.$refs.itemsList.f7VirtualList.filteredItems) {
233234
return
234235
}
@@ -251,12 +252,6 @@ export default {
251252
renderExternal (vl, vlData) {
252253
this.vlData = vlData
253254
},
254-
getListSize () {
255-
if (this.$refs.searchbar?.f7Searchbar.query) {
256-
return this.$refs.itemsList.f7VirtualList.filteredItems.length
257-
}
258-
return this.items.length
259-
},
260255
height (item) {
261256
let vlHeight
262257
if (this.$theme.ios) vlHeight = 78
@@ -299,11 +294,8 @@ export default {
299294
this.selectedItems.push(item)
300295
}
301296
},
302-
areAllSelected () {
303-
return this.selectedItems.length >= this.getListSize()
304-
},
305297
selectDeselectAll () {
306-
if (this.areAllSelected()) {
298+
if (this.allSelected) {
307299
this.selectedItems = []
308300
} else if (this.$refs.itemsList.f7VirtualList.filteredItems?.length > 0) {
309301
this.selectedItems = this.$refs.itemsList.f7VirtualList.filteredItems.map((i) => i.name)
@@ -366,6 +358,27 @@ export default {
366358
computed: {
367359
searchPlaceholder () {
368360
return window.innerWidth >= 1280 ? 'Search (for advanced search, use the developer sidebar (Shift+Alt+D))' : 'Search'
361+
},
362+
filteredItemsCount () {
363+
if (this.searchQuery) {
364+
return this.$refs.itemsList.f7VirtualList.filteredItems.length
365+
}
366+
return this.items.length
367+
},
368+
allSelected () {
369+
return this.selectedItems.length >= this.filteredItemsCount
370+
},
371+
listTitle () {
372+
let title = this.filteredItemsCount
373+
if (this.searchQuery !== '') {
374+
title += ` of ${this.items.length} Items found`
375+
} else {
376+
title += ' Items'
377+
}
378+
if (this.selectedItems.length > 0) {
379+
title += `, ${this.selectedItems.length} selected`
380+
}
381+
return title
369382
}
370383
}
371384
}

0 commit comments

Comments
 (0)