<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
On 08/23/2011 07:58 AM, Ivan Nečas wrote:
<blockquote cite="mid:4E5395E7.3070906@redhat.com" type="cite">Hello
<br>
<br>
On 08/19/2011 09:25 PM, Partha Aji wrote:
<br>
<blockquote type="cite">Issue:
<br>
At the end of our roles-ui rewrite, we realized that we need to
add rules to navigation.rb to acl things off. So based on rules
in the controllers I came up with the following rules based
navigation rb.
<br>
<a class="moz-txt-link-freetext" href="http://git.fedorahosted.org/git/?p=katello.git;a=blob;f=src/config/navigation.rb;h=5d48039d1ce90cacf1f5b0e936715ff5f3adefff;hb=bea1d8c6d253cb79430586c5f92c4bc8ead6e9b9">http://git.fedorahosted.org/git/?p=katello.git;a=blob;f=src/config/navigation.rb;h=5d48039d1ce90cacf1f5b0e936715ff5f3adefff;hb=bea1d8c6d253cb79430586c5f92c4bc8ead6e9b9</a>
<br>
<br>
I notice a couple of problems here and need suggestions on way
to refactor this.
<br>
1) Rules are on every line causing confusion and ugliness. For
example
<br>
<br>
providers_sub.item :edit, _("Basics"), (@provider.nil? ||
@provider.new_record?) ? "" : edit_provider_path(@provider.id),
:class => 'navigation_element', :if => Proc.new {
!@provider.nil?&& @provider.readable?&&
!@provider.new_record? }
<br>
</blockquote>
How about using rules we've defined in the controller, so instead
of the Proc.new there would be something like
ProvidersController.rules_for(:index).
<br>
</blockquote>
<a data-display-url="pic.twitter.com/dlDa9oD"
href="http://t.co/dlDa9oD"
data-expanded-url="http://twitter.com/OnLive/status/106065819099873281/photo/1"
title="http://twitter.com/OnLive/status/106065819099873281/photo/1"
target="" rel="nofollow" class="twitter-timeline-link"
data-twitter-media-url="true"></a><br>
Would this work properly since in many cases the rules rely on
specific instance variables? <br>
<br>
<blockquote cite="mid:4E5395E7.3070906@redhat.com" type="cite">
<br>
<blockquote type="cite">
<br>
2) The top level block always needs to know if the bottom level
ones are going to all be hidden so that it can hide itself.
<br>
For example look at Content management
<br>
<br>
<br>
top_level.item :content, _("Content
Management"),<snip> do |content_sub|
<br>
content_sub.item :providers,<snip> do
|providers_sub|
<br>
providers_sub.item :edit, _("Basics"),<snip>
:if => Proc.new { !@provider.nil?&&
@provider.readable?&& !@provider.new_record? }
<br>
<snip>
<br>
end if Provider.any_readable?(current_organization)
<br>
<snip>
<br>
content_sub.item :promotions,<snip> do
|package_sub|
<br>
<snip>
<br>
end if current_organization.readable_for_promotions?
<br>
content_sub.item(:changeset,<snip> if
current_organization.any_changesets_readable?
<br>
end if current_organization()&&
(Provider.any_readable?(current_organization)||
current_organization.readable_for_promotions?&&
current_organization.any_changesets_readable?) #end content
<br>
<br>
notice that the last condition has to include the rules for the
sub items again to not show up.
<br>
<br>
I was not sure what a good way to refactor this would be so as
to make this file a little more readable. I started with an idea
of creating a navigation_rules, that would embed the rules and
some how we have line refer to that rules file and figure out.
<br>
Any suggestions. May be there is some ruby magic that will make
this file totally readable :).. Or may be its perfect as it is
now.
<br>
</blockquote>
Maybe using custom renderer for navigation, that would check,
whether an item has some visible children.
<br>
<br>
There should be some info on renderers in the wiki for
simple-navigation.
<br>
github.com/andi/simple-navigation/wiki/Registering-Renderers
<br>
<br>
<br>
I think it's worth of refactoring since there are those
duplications.
<br>
<br>
-- Ivan
<br>
<blockquote type="cite">
<br>
Partha
<br>
<br>
<br>
_______________________________________________
<br>
katello-devel mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:katello-devel@redhat.com">katello-devel@redhat.com</a>
<br>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/katello-devel">https://www.redhat.com/mailman/listinfo/katello-devel</a>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</body>
</html>