Closed martinpovolny closed 3 years ago
from ./app/controllers/application_controller.rb:433
def process_params_options(params)
options = {}
@explorer = params[:explorer] == "true" if params[:explorer]
if params[:active_tree] && defined? get_node_info
node_info = get_node_info(x_node, false)
options.merge!(node_info) if node_info.kind_of?(Hash)
end
if params[:model] && %w(miq_requests).include?(params[:model])
options = page_params
end
if params[:model] && %w(miq_tasks).include?(params[:model])
options = jobs_info
end
if params[:model] && %w(cloud_networks).include?(params[:model])
options = rbac_params
end
end
...
there are 3 exceptions but each one for the different reason.
I think we need to catch all exceptions, classificate them to the categories and determine why we have it and how we can solve the category.
for example, rbac related things can be inlcuded in rbac(I believe) we don't need any params,
but for example jobs_info
has the different reason.
This is @karelhala 's PR: https://github.com/ManageIQ/manageiq-ui-classic/pull/592
I hoped to clean this up as we move to an API. But we have no input about API creation from the core team https://github.com/ManageIQ/manageiq/issues/14924 . So I guess to make sure that things work we shall start cleaning up the exceptions w/o an API.
readability fix https://github.com/ManageIQ/manageiq-ui-classic/pull/2098
@Ladas to use nested lists as shown by your comment, I created PR https://github.com/ManageIQ/manageiq-ui-classic/pull/1835 (looking at it now, it is not good, fetch of record is wrong) which will call such function.
However it would be much better if we could somehow define what properties has to be used for specific models. Let's say for displaying hosts under ems we need just the model (Hosts
), but for storage_managers
we need model and parent_method
. So my guess is to create some structure where you could define for each controller some specific behavior for specific models:
module EmsCommon
#...
nested_models = {
"block_storage_manager" => {
:model => ManageIQ::Providers::StorageManager,
:options => {:parent_method => :block_storage_managers},
}
"storage_manager" => {
:model => ManageIQ::Providers::StorageManager,
:options => {:parent_method => :storage_managers}
},
"host" => {
:model => Hosts
}
}.freeze
#...
end
To use this, you can do this:
module ReportData
def get_report_data
#...
current_model, options = nested_models[params[:model_name]]
if params[:parent_id]
options[:parent] = #logic to find parent for model from params[:model_name]
end
view, pages = get_view(current_model, options)
end
end
No need to use hash, but it's convenient to show it (we could use something more generic or some better structure).
The most important part for generating report data is part of get_view
method application_controller.rb#L1590-L1608 so the ultimate goal is to move this part to it's own method, and somehow figure out where to fetch all these additional properties.
@karelhala @martinpovolny I think what we are trying to solve here is already solved by Rails for some time, it's called nested resources, i.e. shallow nesting (to avoid nesting hell) http://guides.rubyonrails.org/routing.html#shallow-nesting
But since we do not use routes like that, do we want to mimic the behavior? (I fine with jumping on using routes the right way :-)) I think for the nesting, there should be exact rules of what can be displayed under each entity type. With the generic_show_mixin, those rules were for each controller and each controller could contain a specific params for the nested call if needed (where we would like to get rid of the specific behavior if possible)
Another way is to define just nested_models
but I am not sure if I like that we allow that nested call for every model (comparing to strict route schema)? So I think it should be somehow structured.
@Ladas: you might have noticed that with nested routes route A/B/ is handled by the controller for B. While in our case it's the other way round. A/B/ in handled by A.
I see no easy way of reverting that.
Any way, to revert it or not, we have a piece of information that is currently hidden in the display_methods
. That information is used in GenericShowMixin::show
. We need the very same information in the ../report_data
.
We have generally 2 options:
../report_data
.display_methods
and report_data
.If we clean up the code enough so that just the definition and some generic code remain we might be able to convert our codebase to use the normal Rails nested routes.
@martinpovolny @karelhala I think the option 2 is the way for now, since we are passing things like SQL conditions(we should not do that but we do), we can't easily expose that.
@martinpovolny is this still a valid issue? If yes, lease remove the stale label. If not can you close. If there's no update by next week, I'll be closing this issue.
Closing issue. If you feel the issue needs to remain open, please either reopen or let me know and it will be reopened. @miq-bot close_issue
@miq-bot remove_label stale
Closing because the removal of grid and tile and move ot the list view to react
2 paths, 2 calls for the first display of a GTL list
exceptions e.g. in
process_params_options
several different types exception for foreman inreport_data
report_data, process_params_options
model.association
2 main ways to display nested list in the UI:
In Explorer screens get_view in
ExplorerShow
keys::parent :association :conditions :dbname
and in non-explorer screens get_view in
GenericShowMixin
:parent :association :parent_method :where_clause
ping @Ladas, @karelhala, @lpichler