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

Fixes #38024 - Add ordering by virtual columns #10381

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ofedoren
Copy link
Member

@ofedoren ofedoren commented Nov 20, 2024

This is an alternative for #10368, tries to make ordering by columns, which are not part of actual table, possible.

This PR enables it for roles model, making possible to click on locked column in roles index page and see the ordering, as well as doing so via API.

Added an entry for developer_docs saying how to use it within plugins.

Thanks, @adamruzicka, for the idea!

@MariaAga, what do you think?

P.S. The only issue I see is that we'd need to update https://github.com/theforeman/foreman-tasks/blob/master/app/controllers/foreman_tasks/api/tasks_controller.rb#L195 to be compatible. Could be done as part of removal deprecated stuff.

@MariaAga
Copy link
Member

It seems to work as expected in ui and api, the code makes sense but I think we need a Ruby person to verify it, @adamruzicka ?

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, left two comments. Could we also get a related patch in one of the plugins where its needed?

if virt_column.blank? || model_of_controller.columns_hash[virt_column] || !base_scope.respond_to?(select_method)
base_scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page], :per_page => params[:per_page])
else
base_scope.send(select_method).search_for(params[:search]).order(params[:order]).paginate(:page => params[:page], :per_page => params[:per_page])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI does not accept per_page being set to all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, thinking out loud, from the name I wouldn't really expect it to deal with pagination and so on, but that might be just me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI does not accept per_page being set to all?

Nope, otherwise we'd have a button suggesting that.

Also, thinking out loud, from the name I wouldn't really expect it to deal with pagination and so on, but that might be just me

Naming is hard, any suggestion is more than welcome 🍪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break per_page=all for api?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break per_page=all for api?

wrap_for_virt_column_select method is only for UI controllers, thus no.

API controllers most (if not all) of the time use resource_scope_for_index method, which is overridden in this PR:
https://github.com/theforeman/foreman/pull/10381/files#diff-f97adc72a387ed049f1b789f93f9d5c592f481e9e37c6fb75eabfcc2f36d467eR172

This override should not affect per_page=all, since it's either uses super to use old behavior or explicitly deals with it in https://github.com/theforeman/foreman/pull/10381/files#diff-f97adc72a387ed049f1b789f93f9d5c592f481e9e37c6fb75eabfcc2f36d467eR181.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants