ecamp3 icon indicating copy to clipboard operation
ecamp3 copied to clipboard

Materiallist API endpoint return results sorted by activity per default

Open DeNic0la opened this issue 2 years ago • 3 comments

By default, the MaterialList endpoint should return the entries sorted based on their first occurrence in the Picasso. Which in technical terms is the first ScheduleEntry of the Activity of the MaterialList. This leads to MaterialItem grouped and sorted consistent sequence as a default for the overview in the UI.

DeNic0la avatar Sep 30 '23 18:09 DeNic0la

A schedule entry can belong only to one activity, but an activity can have multiple schedule entries. Did you mix up the terms in this issue description?

carlobeltrame avatar Oct 02 '23 09:10 carlobeltrame

Did you mix up the terms in this issue description?

I did, which led me to believe there is a better way to phrase this and maybe there is.

DeNic0la avatar Oct 02 '23 19:10 DeNic0la

I had a look at this, and it's nontrivial to set this up.

Doctrine cannot order relations by nested fields at all: https://www.doctrine-project.org/projects/doctrine-orm/en/3.1/tutorials/ordered-associations.html

Previously we removed the database connection from root content node to activity, for simplicity and for performance reasons. To order material items by schedule entries (e.g. via API Platform's OrderFilter) would require to add back this connection somehow.

We could write a custom order filter, which adds the necessary joins and order statements, when some query parameter is passed (and pass the query parameter by default). Or we could write a database extension which adds these extra steps on every query. But I am hesitant to do so, because we have recently tried to reduce the complexity of our queries.

We could instead order the items in the frontend. This would be easy to set up, but might lead to some UI jumping or longer load times of the material lists.

In print, the ordering proposed in this issue isn't really helpful at all, there we usually only display material items together which are already in the same activity. Client print already orders the material items by material list name within the activity (on the client side).

carlobeltrame avatar Mar 26 '24 01:03 carlobeltrame