Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetical sort of dataset templates in pull-down menu #4848

Closed
philippconzett opened this issue Jul 14, 2018 · 4 comments
Closed

Alphabetical sort of dataset templates in pull-down menu #4848

philippconzett opened this issue Jul 14, 2018 · 4 comments
Assignees

Comments

@philippconzett
Copy link
Contributor

For user convenience, please apply alphabetical sort of dataset templates in pull-down menus; cf. screenshot:

image

Best,
Philipp (DataverseNO)

@landreev
Copy link
Contributor

landreev commented Jul 31, 2018

This is what I was talking about during the standup:
The templates pulldown has this custom converter attribute defined:

<p:selectOneMenu value="#{DatasetPage.selectedTemplate}" onchange="updateTemplate()"
                                                 converter="templateConverter"

This converter is implemented as this java class: src/main/java/edu/harvard/iq/dataverse/TemplateConverter.java

I suspect that, because it uses the database id of the template, PrimeFaces ends up re-sorting the list automatically by that numeric id (??).
(that would be easy to disprove - are the templates actually appearing in the database order?)
This is a pretty random idea, that may be off - it's just that we are out of any other ideas...
@sekmiller wrote that converter class; Steve do you have any ideas/suggestions? Would it be possible to change the converter to use the name instead (are the template names guaranteed to be unique?)

(once again, the issue is that even though Ben forces Collections.sort(...) on the list of templates, the order never changes...)

@benjamin-martinez
Copy link
Contributor

benjamin-martinez commented Jul 31, 2018

I made a custom sorter that alphabetizes templates, but it is very inefficient. Even if I made it more efficient, I'm not sure if we want to add a custom sorter to our source code. If someone can figure out why the following line doesn't work, that would be ideal.

Collections.sort(dataverseTemplates, (Template t1, Template t2) -> t1.getName().compareToIgnoreCase(t2.getName()));

@sekmiller
Copy link
Contributor

Very strange. And here's an even weirder thing. It's not ordering them by template.id The ordering seems to be related to which one was updated most recently. Whenever you create a dataset with a template we increment a usage count. As near as I can tell if I use a template, the next time I go to create a dataset the most recently used template is pushed to the bottom of the list. And this is even after I try to sort the Collection.

@matthew-a-dunlap
Copy link
Contributor

It looks like the problem was due to the ArrayList being passed back via dataverseService.find(ownerId).getTemplates() . It had no problems adding elements to it but just did not want to be sorted. Adding its elements to a fresh ArrayList allowed sorting via @benjamin-martinez 's 1-liner.

@kcondon kcondon self-assigned this Aug 1, 2018
@kcondon kcondon closed this as completed Aug 1, 2018
@kcondon kcondon removed the Status: QA label Aug 1, 2018
@djbrooke djbrooke added this to the 4.9.2 - Stata Upgrades, etc. milestone Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants