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

Convert RBAC Features Tree to use TreeBuilder (2) #137

Merged
merged 4 commits into from
May 2, 2017

Conversation

hayesr
Copy link
Contributor

@hayesr hayesr commented Jan 12, 2017

This is an alternative to #56 that makes more typical use of x_get_*_kids methods.
Heads-up: this way is 7x slower Performance isn't bad using feature cache in MiqProductFeature

Still to figure out:

  • Sync keys with what controller is expecting so tree can be saved
  • Find an uncached way to send the editable state to nodes from builder
  • Solve a check-state bubble up problem with Menu::Sections

Addresses:
https://bugzilla.redhat.com/show_bug.cgi?id=1348623
https://bugzilla.redhat.com/show_bug.cgi?id=1411831
https://www.pivotaltracker.com/story/show/129518309

Related:
ManageIQ/manageiq#13577
ManageIQ/manageiq#13592

Go to Configuration > Access Control > Roles, pick a role - the tree is on the right, in the role detail.

/cc @zimdel @skateman

@hayesr hayesr force-pushed the convert_rbac_menu_tree_2 branch from 7856bfc to 2f476e2 Compare January 12, 2017 06:41
@ghost
Copy link

ghost commented Jan 12, 2017

Summoning @ZitaNemeckova and @himdel

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

Looks great, just a few minor comments ...

end

def x_get_tree_section_kids(parent, count_only = false)
kids = parent.items.select do |item|
Copy link
Member

Choose a reason for hiding this comment

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

Isn't possible to write this as a one-liner with reject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shorter, but one line is awkward with the if kind_of?(Menu::Item).

count_only_or_objects(count_only, kids)
end

# FIXME: This is inefficient, but done to use MiqProductFeature objects rather than hashes
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@@ -10,7 +10,8 @@ class Hash < Node

set_attribute(:hide_checkbox) { @object.key?(:hideCheckbox) && @object[:hideCheckbox] ? true : nil }

set_attribute(:selected) { @object.key?(:select) && @object[:select] ? true : nil }
# set_attribute(:selected) { @object.key?(:select) && @object[:select] ? true : nil }
set_attribute(:selected) { @object[:select] if @object.key?(:select) }
Copy link
Member

Choose a reason for hiding this comment

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

This definitely needs to be tested against other trees using hash nodes & checkboxes ...

module TreeNode
module Menu
class Item < Node
set_attribute(:key) { "#{@options[:node_id_prefix]}__#{@object.feature}" }
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for the __ instead of _?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Legacy. I still need to look into the keys that the controller expects to make updating work.

class Item < Node
set_attribute(:key) { "#{@options[:node_id_prefix]}__#{@object.feature}" }

set_attribute(:title) { _(details[:name]) }
Copy link
Member

Choose a reason for hiding this comment

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

I think it's way too dynamic for gettext - ping @mzazrivec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, using _(details[:name]) here is correct.

self_selected? || select_by_kids_selected
end

set_attribute(:no_click, true)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this setting, clicking on a node will expand that part of the tree, without it clicking will try and load a page (I guess based on the key). Is there another setting I'm supposed to use for that?

Copy link
Member

Choose a reason for hiding this comment

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

Set :onclick => nil in set_locals_for_render 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems to prevent it from trying to load a page, but it highlights the node instead of expanding it.

Copy link
Member

Choose a reason for hiding this comment

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

OK


set_attribute(:no_click, true)

set_attribute(:hide_checkbox, false)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this default? I mean if there are checkboxes, they're displayed if not said othetwise.

module Menu
class Section < Node
set_attribute(:key) do
"#{@options[:node_id_prefix]}___tab_#{@object.id}"
Copy link
Contributor

@himdel himdel Jan 12, 2017

Choose a reason for hiding this comment

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

If you can add tab as a prefix for this kind of object, then it'd be better to have that, use full_ids and not override the key in any of the nodes..

(that should give you xx-10r2_tab-net)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to full ids, but forms from users, groups, and roles all seem to go through the same method. Probably should be fixed in a subsequent PR.

@hayesr hayesr force-pushed the convert_rbac_menu_tree_2 branch 3 times, most recently from 2e993cf to 8419eb4 Compare January 13, 2017 04:52
# Make sure tree_state doesn't hold on to old data between requests
#
unless @sb.fetch_path('trees', 'features_tree').nil?
@sb['trees'].delete('features_tree')
Copy link
Contributor Author

@hayesr hayesr Jan 13, 2017

Choose a reason for hiding this comment

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

@himdel @skateman I'm guessing this isn't normal, but otherwise too much state is carried over between show and edit and back.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayesr Maybe something like TreeState.new(sandbox).remove_tree(name) in the constructor?

(mostly because we have the same thing here https://github.com/ManageIQ/manageiq-ui-classic/pull/15/files#diff-d10de31acbab60b307f4c0ea86b158c0R22 )

@hayesr hayesr changed the title [WIP] Convert Menu Features Tree to use TreeBuilder (2) [WIP] Convert RBAC Features Tree to use TreeBuilder (2) Jan 13, 2017
@mzazrivec mzazrivec added the wip label Jan 13, 2017
@hayesr hayesr force-pushed the convert_rbac_menu_tree_2 branch 3 times, most recently from 97c51bd to 87fbe37 Compare January 16, 2017 19:43
@hayesr hayesr changed the title [WIP] Convert RBAC Features Tree to use TreeBuilder (2) Convert RBAC Features Tree to use TreeBuilder (2) Jan 16, 2017
@hayesr hayesr closed this Jan 16, 2017
@hayesr hayesr reopened this Jan 16, 2017
@hayesr hayesr changed the title Convert RBAC Features Tree to use TreeBuilder (2) [WIP] Convert RBAC Features Tree to use TreeBuilder (2) Jan 18, 2017
@hayesr hayesr force-pushed the convert_rbac_menu_tree_2 branch from 87fbe37 to c7ca1d5 Compare January 18, 2017 01:07
@hayesr hayesr changed the title [WIP] Convert RBAC Features Tree to use TreeBuilder (2) Convert RBAC Features Tree to use TreeBuilder (2) Jan 18, 2017
@hayesr hayesr closed this Jan 19, 2017
@hayesr hayesr reopened this Jan 19, 2017

set_attribute(:tooltip) { _(details[:description]) || _(details[:name]) }

set_attribute(:image, "100/feature_node")
Copy link
Contributor

Choose a reason for hiding this comment

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

missing .png


set_attribute(:title) { _(@object.name) }

set_attribute(:image) { "100/feature_node" }
Copy link
Contributor

Choose a reason for hiding this comment

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

missing .png

Copy link
Contributor Author

Choose a reason for hiding this comment

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

— but it works 🤷‍♂️

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hehe, yeah, that's the magic of rails :-) which usually only breaks in production.. By making the first access to such an icon take about 2 minutes on a new appliance, became its not in the index and rails tries really hard to search for it :-)

@@ -129,7 +129,7 @@ def to_h
:checkable => checkable ? nil : false,
}

node[:image] = if !image
node[:image] = if !respond_to?(:image) || !image
Copy link
Contributor

@himdel himdel Jan 19, 2017

Choose a reason for hiding this comment

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

no longer needed, Node has a default image implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This shouldn't be a change from my code. How'd this get here?

@himdel himdel removed the wip label Jan 20, 2017
@skateman
Copy link
Member

@hayesr could you please fix the red rubocop issues?

@hayesr
Copy link
Contributor Author

hayesr commented Apr 21, 2017

Removed the child-counting methods from node builders and it seems to work well with post_check. This might finally be ready to go when green 🤞 @skateman @himdel @martinpovolny

@skateman
Copy link
Member

skateman commented Apr 21, 2017

@hayesr please rebase to fix bower issues in travis & there are still things that weren't fixed...

@hayesr
Copy link
Contributor Author

hayesr commented Apr 21, 2017

Restart CI

@hayesr hayesr closed this Apr 21, 2017
@hayesr hayesr reopened this Apr 21, 2017
@hayesr
Copy link
Contributor Author

hayesr commented Apr 21, 2017

Bower hates me.

@hayesr hayesr closed this Apr 21, 2017
@hayesr hayesr reopened this Apr 21, 2017
@hayesr hayesr closed this Apr 21, 2017
@hayesr hayesr reopened this Apr 21, 2017
@hayesr
Copy link
Contributor Author

hayesr commented Apr 21, 2017

Finally green! (Codeclimate doesn't like so many parameters in initialize, we should fix that later)

@skateman
Copy link
Member

As I mentioned earlier there are still some unresolved issues:

Please fix them, and we can merge this 👍

@miq-bot
Copy link
Member

miq-bot commented Apr 27, 2017

This pull request is not mergeable. Please rebase and repush.

@kbrock
Copy link
Member

kbrock commented Apr 29, 2017

Codeclimate doesn't like so many parameters in initialize, we should fix that later

the operative word here is "later" aka someday/maybe/never

@hayesr hayesr force-pushed the convert_rbac_menu_tree_2 branch from 6ad047c to c495821 Compare May 1, 2017 23:06
@miq-bot
Copy link
Member

miq-bot commented May 1, 2017

Checked commits hayesr/manageiq-ui-classic@4f46dae~...a90e7a0 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
12 files checked, 2 offenses detected

app/presenters/menu/manager.rb

  • ❗ - Line 9, Col 16 - Style/AlignHash - Align the elements of a hash literal if they span more than one line.

app/presenters/tree_builder_ops_rbac_features.rb

@hayesr
Copy link
Contributor Author

hayesr commented May 2, 2017

Ready for another look.

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

LGTM

@martinpovolny martinpovolny merged commit a07cd16 into ManageIQ:master May 2, 2017
@martinpovolny
Copy link
Member

🥇

@martinpovolny martinpovolny added this to the Sprint 60 Ending May 8, 2017 milestone May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants