openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

Add feature to sort group members with metadata configuration

Open cweitkamp opened this issue 2 years ago • 6 comments

  • Added feature to sort group members with metadata configuration

See https://github.com/openhab/openhab-core/pull/2123#issuecomment-765904668

This is an initial draft on sorting group members with metadata configuration. Items in groups can be sorted by name, label or state. Default ordering is ascending.

demo.items

Group:Number testGroup "Test Group" {
    sortBy="STATE" [ ordering="DESCENDING" ]
}

Allowed values for sortBy: LABEL, NAME and STATE. Allowed values for ordering: DESCENDING, otherwise ascending ordering will be used. Configuration of ordering is optional.

Sort members by state picks up a Comparator from items, which can be implemented individually for each item type. Item class provides a default Comparator to sort states in alphabetically order by applying toFullString() on the state first.

UIs and other services have to be changed afterwards to benefit from this feature.

@openhab/core-maintainers wdyt? // CC @ghys @rkoshak

Signed-off-by: Christoph Weitkamp [email protected]

cweitkamp avatar Nov 01 '21 16:11 cweitkamp

Thanks for looking into this. From my POV we at least need to tweak the REST API to make use of this feature or add a special method for retrieving sorted groups / member of groups.

cweitkamp avatar Dec 02 '21 21:12 cweitkamp

The UI has its own sorting function which will consider the index put in the widgetOrder metadata namespace first, then will sort labels (or fallback to the name if the item has no label) alphabetically. It was because in many cases the order of items in API responses seemed random and indeterminate. When you use features like the "group popup" action, the home page cards, the "add from model" function in pages, or the oh-repeater component with a itemsInGroup source, that function will be used instead of the order of the API. So there would be a need to figure out that in some cases the order of the API is the correct one.

ghys avatar Dec 02 '21 23:12 ghys

The feature to order based on widgetOrder can be integrated in this implementation too.

Would it make sense to add an orderIndex field to the EnrichedItemDTO which carries the previously determined ordering? This can be used by consumers to ensure correct ordering.

cweitkamp avatar Dec 04 '21 10:12 cweitkamp

Holy cow, there's been a lot of stuff going on on GitHub I've simply missed. Playing catchup.

All I have to add is this is something that has been asked for many times by sitemap users. I could see it potentially being useful in rules too, though there are already ways to sort members of a Group there.

I can't comment on MainUI concerns.

rkoshak avatar Jan 11 '22 16:01 rkoshak

@cweitkamp What is the status here? Judging from your last comment I assume there's still work to do before we can merge?

J-N-K avatar May 14 '22 21:05 J-N-K

@cweitkamp Are you still around and could comment on the status here?

kaikreuzer avatar Dec 16 '23 10:12 kaikreuzer