added support for context links

This commit is contained in:
Saurabh Bhatia 2014-04-11 18:44:45 +08:00
parent b611ffcae3
commit e07026545f
4 changed files with 92 additions and 3 deletions

View File

@ -1,5 +1,6 @@
require 'orbit_app/helper/renderer'
require 'orbit_app/helper/side_bar_renderer'
require "orbit_app/helper/context_link_renderer"
require 'orbit_app/register_module'
require 'orbit_app/module/registration'
require 'orbit_app/module/side_bar'

View File

@ -0,0 +1,12 @@
module ContextLinkRenderer
include Renderer
def render(request,params,current_module_app,belong_module_app)
@current_module_app = current_module_app
@belong_module_app = belong_module_app
@request = request
@params = params
content_tag :li, link_to(content_tag(:span, I18n.t(@label_i18n)), eval(@path)), :class => (active? ? 'active' : nil)
end
end

View File

@ -10,7 +10,9 @@ module SideBarRenderer
content_tag :div, class: "sub-nav-block #{@icon_class}" do
concat content_tag :h4, I18n.t(@head_label)
concat (content_tag :ul, class: "nav nav-list" do
@context_links.sort_by {| obj | obj.priority}.map{ |link|
link.render(request, params, @current_module_app, @belong_module_app)
}.join.html_safe
end)
end
end

View File

@ -43,6 +43,7 @@ module OrbitApp
def initialize(name = '',key,get_module_app,&block)
@head_label = name
@context_links = []
@head_link = ""
@app_base_path = ''
@active_for_controllers = []
@ -83,17 +84,90 @@ module OrbitApp
@active_for_controllers = var
end
def context_link(*var)
var[1].merge!({:module_app_key=>@module_app_key,:get_module_app=>@get_module_app}) unless @module_app_key.nil?
new_context_link = ContextLink.new(*var)
@context_links << new_context_link
end
def finalize!
set_controllers_scope
# set_default_active_app_auth
current_priority = @context_links.count
@context_links.each do |t|
# t.set_module_app = @module_app
t.finalize!
end
end
protected
def set_controllers_scope
var = @active_for_controllers
@active_for_controllers = []
var[:private].each do |controller|
@active_for_controllers << "admin/"+controller
@active_for_controllers << "#{locale}/admin/"+controller
end unless var[:private].nil?
var[:public].each do |controller|
@active_for_controllers << controller
end unless var[:public].nil?
end
end
class ContextLink
include ContextLinkRenderer
attr_reader :label_i18n,:available_for,:priority,:path,:active_for_action
def initialize(label_i18n="NoNameLink",options={})
@label_i18n = label_i18n
@priority = options[:priority] || 0
@path = options[:link_path] || ""
set_available_for_avoiding_sensitive_links(options[:available_for] )
@active_for_action = options[:active_for_action] || []
@module_app_key = options[:module_app_key]
@get_module_app = options[:get_module_app]
end
def set_available_for_avoiding_sensitive_links(available_for)
sensitive_list = {}
sensitive_list[:module_app] =/.*manager_auth_proc.*/
sensitive_list[:object_auth] = /.*object_auth.*/
sensitive_list.each do |index,regx|
if @path.match(regx)
@available_for = case index
when :module_app
[:admin]
when :object_auth
[:manager,:admin]
end #of case
end #of if
end #of each
@available_for = available_for if @available_for.nil?
end #of def
def get_module_app
@get_module_app.call
end
def active?
for_action = @active_for_action.blank? ? false : active_for_action?
for_action
end
def active_for_action?
@active_for_action[controller] == action
end
def finalize!
set_active_actions
end
protected
def set_active_actions
controller_action_hash = @active_for_action
@active_for_action = Hash[controller_action_hash.map{|controller,action| ["#{locale}/admin/"+controller.to_s,action.to_s]}]
end
end
end