Manual sorting of HasMany children list
Dear all
The evolutions in the way Administrate handle sorting within the dashboards makes the gem flexible and super useful. However, there is still a particular case which is not managed and which prevents me from having an administration tool entirely based on the configuration files of Administrator. : being able to reorder manually the list of children within a HasMany relation, based on a specific position attribute.
use case : I have an album template that contains many images. These images must be ordered manually by the person in charge of the album, according to his artistic touch, the story he wishes to tell.
I feel that this feature is probably cumbersome to implement, since it would likely impact pagination and other well-established features and add specific behavior regarding the existing/non existing positions when children's data are imported. Acts_as_list had a bunch of methods allowing things like this I guess.
However, I have the intuition that such an ordering solution, which corresponds well to a data administration action, would be useful for the management of many data models.
In the case of a "simple" HasMany relationship, it would suffice to pass two pieces of information to the dashboard: specify the classification mode and specify the name of the attribute that contains the position of each child.
ATTRIBUTE_TYPES = {
pictures: Field::HasMany.with_options(sortable: true, sortable_index_position: :position),
}.freeze
A last option could allow to specify the method of interaction allowing to modify the classification if there were several.
I hope this idea will interest some of you :)