-
Notifications
You must be signed in to change notification settings - Fork 356
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
module Menu | ||
Section = Struct.new(:id, :name, :icon, :items, :placement, :before, :type, :href) do | ||
extend ActiveModel::Naming | ||
|
||
def self.base_class | ||
Menu::Section | ||
end | ||
|
||
def self.base_model | ||
model_name | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To the mixin 😉 |
||
|
||
def initialize(an_id, name, icon, *args) | ||
super | ||
self.items ||= [] | ||
|
@@ -17,7 +27,7 @@ def features | |
end | ||
|
||
def features_recursive | ||
Array(items).collect { |el| el.try(:feature) || el.try(:features) }.flatten.compact | ||
Array(items).flat_map { |el| el.try(:feature) || el.try(:features) }.compact | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AND ooh. This often gets rid of the Array(items).flat_map { |el| el.try(:feature) || el.try(:features) || [] } |
||
end | ||
|
||
def visible? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,9 +261,16 @@ def x_build_node(object, pid, options) | |
node = x_build_single_node(object, pid, options) | ||
|
||
# Process the node's children | ||
load_children = if object.kind_of?(Struct) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just use hash here, like every other tree? We are in the process of getting rid of hash nodes, but we should be doing that systematically for all the trees... This looks too much like an exception for a signle tree... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So now you want me to go back to hashes for Menu::Item, Menu::Section, etc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, that was definitely not my intention :) However, all the trees dealing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Withdrawing my objection here, I looked into it, it seems like that So adding another branch for structs ..sounds about right :). |
||
# Load children for Sections, don't for other Menu Structs. | ||
object.kind_of?(Menu::Section) | ||
else | ||
object[:load_children] | ||
end | ||
|
||
node[:expand] = Array(@tree_state.x_tree(@name)[:open_nodes]).include?(node[:key]) || !!options[:open_all] || node[:expand] | ||
if ancestry_kids || | ||
object[:load_children] || | ||
load_children || | ||
node[:expand] || | ||
@options[:lazy] == false | ||
|
||
|
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 see that we have this piece of code multiple times, can you extract it to a mixin?
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 agree, but maybe in a different PR? Changing these menu classes much more seems out of scope.
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 don't think that creating a mixin with 6 lines is out of scope here, especially when you're introducing something new...