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
Display Generic Object Associations correctly (Post /report_data
related GTL fixes)
#2596
Display Generic Object Associations correctly (Post /report_data
related GTL fixes)
#2596
Conversation
/cc @martinpovolny |
@miq_bot add_label gaprindashvili/yes,bug |
@@ -2,6 +2,8 @@ class GenericObjectController < ApplicationController | |||
before_action :check_privileges | |||
before_action :get_session_data | |||
|
|||
before_action :create_display_methods, :only => [:show] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, do not use before_action
. Just call the method where it is needed. I believe we already discussed this. It really makes the code far less readable than it could be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just a personal preference to declare the method this way.
I somehow prefer to keep it concealed, the intention being - not to add too many things in show
But if you prefer an explicit show
, I can change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AparnaKarve before_action
adds extra complexity and non-linearity to the code that is hard to follow. Especially if you're using it for just a single controller method, it doesn't even make sense, just complicates the life of anyone who wants to understand it later.
@@ -27,6 +29,13 @@ def self.populate_display_methods(record) | |||
end | |||
end | |||
|
|||
def create_display_methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read this right, this will define a method for each and any value of display
that the browser sends. Is that the intended behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intended behavior is to create a "display_#{key}"
method on-the-fly.
key
can be any value in the generic_object_definition.properties[:associations][key]
that is associated with a valid Model Name.
To give you an example, I have a generic_object_definition
record with the following keys/associations -
{"vms"=>"Vm", "services"=>"Service", "cp"=>"ManageIQ::Providers::CloudManager"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key cp
in the above case (which is a good example of a non-standard display
parameter) would be sent via the display
parameter to the show
method
/report_data
related GTL fixes)/report_data
related GTL fixes)
695321d
to
5b6f26a
Compare
@@ -256,6 +256,9 @@ def get_node_info(treenodeid, _show_list = true) | |||
@nodetype, id = parse_nodetype_and_id(valid_active_node(treenodeid)) | |||
# resetting action that was stored during edit to determine what is being edited | |||
@sb[:action] = nil | |||
|
|||
@nodetype, id = parse_nodetype_and_id(params[:id]) if params[:id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AparnaKarve : I understand you need this behavior added here, but it creates another hidden data path in the code.
What I mean: now the input to get_node_info
can be passed as an argument treenodeid
or (newly) through params[:id]
.
That is a bad design and it's going to be hard to fix in the future.
Can you move this logic to show
? That is where you get with the click, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this logic to show? That is where you get with the click, right?
@martinpovolny I understand, that is the most logical thing to do -- only if it worked.
If you check the Service explorer code, you will notice that show
redirects to explorer
and then you get this -
F, [2017-11-03T07:54:49.876401 #79870] FATAL -- : Error caught: [NoMethodError] undefined method `name' for nil:NilClass
~/manageiq/plugins/manageiq-ui-classic/app/controllers/service_controller.rb:292:in `get_node_info'
~/manageiq/plugins/manageiq-ui-classic/app/controllers/application_controller.rb:2365:in `set_active_elements'
~/manageiq/plugins/manageiq-ui-classic/app/controllers/application_controller.rb:2383:in `build_accordions_and_trees'
~/manageiq/plugins/manageiq-ui-classic/app/controllers/service_controller.rb:70:in `explorer'
The whole show
method looks really questionable to me.
The nodetype
evaluation happens in get_node_info
- where the above check that I have added really matters - since show
is going to eventually end up there via explorer
Unfortunately, most explorers are just poor quality code, full of bad surprises - precisely the reason why I wanted to stay away from Explorer in Generic Objects.
Without agitating the Service Explorer code too much (as in , a refactor), I think what I have here is our best bet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, most explorers are just poor quality code, full of bad surprises - precisely the reason why I wanted to stay away from Explorer in Generic Objects.
Well unless people actually start fixing it, it will shay poor quality code.
Adding functionality is an opportunity to cleanup stuff and remove exceptions. Because to add functionality you read the code and see what is bad. Well unless you use try-test-fail approach that actually leads to even worse code ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding functionality is an opportunity to cleanup stuff and remove exceptions.
Sure, but not at this given time.
It's an upstream effort.
A refactor going in for the Release, is just plain risky and not a good idea.
@AparnaKarve : removing the comments that are no longer valid. The only valid bit is in-line above. |
@AparnaKarve : linking your GIST so that other people can test/review. GIST to create necessary GO: https://gist.github.com/martinpovolny/b08a799e2174551a4d7fc6f4bac85ad2 Feel free to replace this comment with your newer/better version. |
Let me see what I can do with that one ugly line.... |
Well @AparnaKarve : look at 57ae873 where @lgalis added a call to Turns out The commit comes from ManageIQ/manageiq@9281a96 and that is from ManageIQ/manageiq#9809 and there seems to be no spec for that change so I am pretty dammed if I try to fix it. Now you are suggesting that INSIDE So you are adding a hack on top of already ugly hack. In that context your remark about:
sounds like a joke. I am sorry @AparnaKarve but I will not merge this. You are complaining about a situation that you are actively creating :-( Also
Basically means: "We created so much mess in the explorers that we are going to start over in another place." I don't see how this will fix the situation. |
@lgalis : Can you, please, show me where the requests that you where fixing in ManageIQ/manageiq#9809 come from? Where should I click to make such request? I need to help @AparnaKarve fix this BZ and doing that I am likely to break your fix so I need to make sure I handle that situation too. Thank you! |
@martinpovolny Do what you got to do. |
@martinpovolny - If I recall correctly, the problem was selecting a node in the foreman tree - then browsing to a different controller then returning to the foreman controller. |
@AparnaKarve : I don't want to do a refactoring. I want to fix the BZ w/o introducing new technical debt ;-) |
@martinpovolny Fixing/Refactoring the Do take into consideration all the above before making major changes. |
@AparnaKarve : can you take a look how other places link to Services? Seems to me other places might use |
Btw: there seem to be issues with this PR. The services tree seems broken after you come to it from the generic_objects. It seems that the |
@AparnaKarve : it's actually |
@martinpovolny Glad you did this research and now we are finally on the same page! This was my very first finding and in fact I even discussed with you on gitter (check your Nov 2 gitter) |
It is disturbing how many times you have used the word "hack" in the context of Trees/Explorers.
Before I do that, please explain to me why does the Navigation to VM Explorer from the GO tree works just fine? Why are we using the session-based The use of |
@martinpovolny We need to move forward with this BZ/PR - It has taken too long for various reasons -- the GTL fixes that came in so late have really prolonged the whole process :-( My suggested approach works and currently I am not in the camp of changing the Service Explorer code too much, because it's too close to the release. Let me know if I should remove the last commit from this PR, which has been the main topic of discussion really. |
Yes @AparnaKarve, to do the review of your PR I have to do all this research and as a reward instead of an answer I get another question from you. 2 or the 4 patches in his PR are the result of me spending time on this task figuring out how to do things properly where you hacked your way through! It's so much faster for me to so the things myself than to do these lengthy reviews and rewrites. An elementary respect that I would like to see would have the form of you actually answering my question so that I don't have to do more research. But no. I get another question instead and then a complaint about ugly code.
Why should I know that? I have not written that hack there! You tell me, this is your PR! You are adding that here. I have not YET rewritten the explorers. I have not. I cannot rewrite everything at once. You can do that instead of these discussions. Come up with a design, do a WIP, have it reviewed, fix it. As to your question: yes, remove the last commit, lets merge the 3. The last commit is a hack on top of a hack. If you are not willing to spend time fixing the problem I will try in another PR. |
Correction. The research was already done by me - you did not have to do it again.
Not true.
Thanks. I will remove the last commit. A different PR for Service Explorer is a good idea - no reason to keep the other working implementation blocked here. |
To answer your remaning questions here:
I don't know. That code was there before I started contributing to this project. I worked on unifying that (all the x_(active|)_(tree|accortion|node) comes from my work. I see such unification as a step towards removal. Help in this area is welcome.
I don't know. That code was there before I started contributing to this project. I have done a lot of work to cleanup and unify the various routes used by various controllers so that we can normalize it. There's a lot of teamwork happening in that area. The unificafion of the nested lists was started by @Ladas and is continued by me, @karelhala, @tumido and others. It's a long way but cleaning up the nested views is pre-requisite for using normal Rails routes. Should you have a better plan or idea on how to "use the routing system that rails offers us out-of-the-box" I'd love to hear your suggestions and plans. Can I get my answer regarding the the other places that link to Services? I can use your research here so that I don't have to redo it. You corrected me:
Well I need the results of your research if I don't have to do it again ;-) Please, share. |
Created `display_methods` and `display_nested_generic` to be able to whitelist GOD associations and create nested lists for those associations
5b6f26a
to
9d9789d
Compare
First things first - so here's an update to the PR which excludes the last commit. |
Checked commits AparnaKarve/manageiq-ui-classic@d1f5b65~...9d9789d with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 |
Cool, I guess you can remove the WIP and add the necessary labels. From my perspective this is ok. It removes the redefinition of the static class method on instance method call plus it adds a nice test. I like it 👍 Ready to merge then? Then, please, share your findings so that I can have a look at the loose end about link to Services. |
/report_data
related GTL fixes)/report_data
related GTL fixes)
Thanks.
Sounds good. Ready to merge now. |
@martinpovolny The VM Explorer is probably even worse than Services Explorer. This is what I have so far -- A single show call -
On the positive side, it does not rely on the session-based @record = identify_record(id || params[:id], VmOrTemplate) Followed by - tree_node_id = TreeBuilder.build_node_id(@record) I think that's the main differentiator between these 2 explorers, and the reason why navigating to VM Explorer works and navigating to Service Explorer doesn't The overall
|
Thanks @AparnaKarve. However my main question was about:
We want to fix a situation here where linking to Services won't work, right? So I am asking still the same question, because I want to fix it while unifying things. I assumed that you would know, because you where adding such place. If you don't know, just tell me, I am ok with that. In the context of your earlier statement:
I wanted to prevent my own research if you already did that. |
I am really not aware of other places that link to Services. So by extrapolating all the observations so far -
|
Ok, let me add the labels for you. |
…ce_associations_after_gtl_fixes Display Generic Object Associations correctly (Post `/report_data` related GTL fixes) (cherry picked from commit d5d7f4f)
Gaprindashvili backport details:
|
PR #2420 was cleaned up here, post
/report_data
related GTL fixes.The only GTL change retained from #2420 is the dynamic creation of
create_display_methods
, which requires anassociation
value to be passed in order to render the List successfully.https://bugzilla.redhat.com/show_bug.cgi?id=1500829