Skip to content

Commit

Permalink
Things list: Add grouping by location & Display location in list entr…
Browse files Browse the repository at this point in the history
…ies (#2107)

Closes #2099.

Signed-off-by: Dmitry P. (d51x) <dimonich110@gmail.com>
  • Loading branch information
d51x authored Oct 8, 2023
1 parent 27c140a commit a1a3329
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<f7-button :active="groupBy === 'binding'" @click="switchGroupOrder('binding')">
By binding
</f7-button>
<f7-button :active="groupBy === 'location'" @click="switchGroupOrder('location')">
By location
</f7-button>
</f7-segmented>
</div>
<f7-list class="searchbar-found col things-list" :contacts-list="groupBy === 'alphabetical'">
Expand All @@ -101,6 +104,11 @@
{{ thing.UID }}
<clipboard-icon :value="thing.UID" tooltip="Copy UID" />
</div>

<div slot="subtitle" v-if="thing.location && groupBy !== 'location'">
{{ thing.location }}
<f7-icon f7="placemark" color="gray" style="font-size: 16px; width: 16px; height: 16px;" />
</div>
<f7-badge slot="after" :color="thingStatusBadgeColor(thing.statusInfo)" :tooltip="thing.statusInfo.description">
{{ thingStatusBadgeText(thing.statusInfo) }}
</f7-badge>
Expand Down Expand Up @@ -177,7 +185,7 @@ export default {
return prev
}, {})
} else {
} else if (this.groupBy === 'binding') {
const bindingGroups = this.things.reduce((prev, thing, i, things) => {
const binding = thing.thingTypeUID.split(':')[0]
if (!prev[binding]) {
Expand All @@ -191,6 +199,20 @@ export default {
objEntries[key] = bindingGroups[key]
return objEntries
}, {})
} else {
const locationGroups = this.things.reduce((prev, thing, i, things) => {
const location = thing.location || '- No location -'
if (!prev[location]) {
prev[location] = []
}
prev[location].push(thing)
return prev
}, {})
return Object.keys(locationGroups).sort((a, b) => a.localeCompare(b)).reduce((objEntries, key) => {
objEntries[key] = locationGroups[key]
return objEntries
}, {})
}
},
inboxCount () {
Expand Down

0 comments on commit a1a3329

Please sign in to comment.