first version of confined sidebar render
This commit is contained in:
1 parent
194b42c1e4
commit
36f6a6fdd6
17 files changed
+352
-119
No files matched your search
@@ -0,0 +1,12 @@
|
||||
module ContextLinkRenderer
|
||||
include Renderer
|
||||
|
||||
def render(request,params)
|
||||
@request = request
|
||||
@params = params
|
||||
if display?
|
||||
content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
module Renderer
|
||||
include Rails.application.routes.url_helpers
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include ActionView::Helpers::RenderingHelper
|
||||
include ActionView::Context
|
||||
include OrbitBasis::RenderAnywhere
|
||||
|
||||
protected
|
||||
def active_for_app_auth?
|
||||
@module_app.id.to_s == @params[:module_app_id] ? true : false
|
||||
end
|
||||
|
||||
def active_for_ob_auths?
|
||||
if @params.has_key? :object_auth_id
|
||||
oa = ObjectAuth.find @params[:object_auth_id]
|
||||
check_controller = @params[:controller] == 'admin/object_auths_new_interface'
|
||||
check_object_class = @active_for_object_auth.include? oa.obj_authable_type
|
||||
return (check_controller and check_object_class)
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def current_user
|
||||
current_or_guest_user
|
||||
end
|
||||
|
||||
def current_or_guest_user
|
||||
@current_user
|
||||
end
|
||||
|
||||
def request
|
||||
@request
|
||||
end
|
||||
|
||||
def default_url_options
|
||||
_routes.default_url_options
|
||||
end
|
||||
|
||||
def _routes
|
||||
@request.env["action_dispatch.routes"]
|
||||
end
|
||||
|
||||
def controller
|
||||
@params[:controller]
|
||||
end
|
||||
|
||||
def action
|
||||
@params[:action]
|
||||
end
|
||||
|
||||
def check_user_available_for
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
def display?
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
module SideBarRenderer
|
||||
include Renderer
|
||||
include AdminHelper
|
||||
|
||||
def render(request,params,user)
|
||||
@request = request
|
||||
@params = params
|
||||
@current_user = user
|
||||
if display?
|
||||
content_tag :li, :class => (module_sidebar_active? ? 'active' : nil) do
|
||||
buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link))
|
||||
buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))
|
||||
@context_links.sort_by! {| obj | obj.priority}.collect do |link|
|
||||
link.render(request,params)
|
||||
end.join.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def display? #控制sidebar 要不要算圖
|
||||
if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員
|
||||
true
|
||||
elsif (@module_app.open rescue false) # 如果app 被設定成 開放
|
||||
true
|
||||
elsif is_member? #如果app 是封閉 那至少需要是 member
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def module_sidebar_active?
|
||||
active_for_controller? or active_for_app_auth? or active_for_ob_auths?
|
||||
end
|
||||
|
||||
def active_for_controller?
|
||||
@active_for_controllers.include? controller
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,17 +0,0 @@
|
||||
module OrbitApp
|
||||
module Module
|
||||
class BackendSideBar
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name, &block)
|
||||
@name = name
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
end
|
||||
|
||||
# def personal_plugin(*args)
|
||||
# binding.pry
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -33,11 +33,15 @@ module OrbitApp
|
||||
|
||||
def initialize(name, &block)
|
||||
@name = name
|
||||
@side_bar = nil
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
end
|
||||
|
||||
def plugin
|
||||
|
||||
def side_bar(&block)
|
||||
@side_bar = SideBarRegisition::SideBar.new(&block)
|
||||
@side_bar.module_app_key = @name
|
||||
@side_bar.finalize!
|
||||
OrbitApp::Module::SideBarRegisition.add(@side_bar)
|
||||
end
|
||||
|
||||
def personal_plugin(params)
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
module OrbitApp
|
||||
module Module
|
||||
module SideBarRegisition
|
||||
Version = "0.1"
|
||||
|
||||
module ClassMethods
|
||||
@@side_bars = []
|
||||
|
||||
def add(var)
|
||||
@@side_bars << var
|
||||
end
|
||||
|
||||
def find_by_key(key)
|
||||
@@side_bars.each{|t|
|
||||
return t if t.name == key
|
||||
}
|
||||
return nil
|
||||
end
|
||||
|
||||
def all
|
||||
return @@side_bars
|
||||
end
|
||||
end
|
||||
|
||||
extend ClassMethods
|
||||
def self.included( other )
|
||||
other.extend( ClassMethods )
|
||||
end
|
||||
|
||||
class SideBar
|
||||
# include ApplicationHelper
|
||||
# include AdminHelper
|
||||
include SideBarRenderer
|
||||
# def is_admin?
|
||||
# binding.pry
|
||||
# end
|
||||
# def is_manager?
|
||||
# binding.pry
|
||||
# end
|
||||
def initialize( &block)
|
||||
name = ''
|
||||
@head_label = name
|
||||
@context_links = []
|
||||
@available_for = []
|
||||
@active_for_controllers = []
|
||||
@active_for_object_auth = []
|
||||
@active_for_app_auth = []
|
||||
@head_link = ""
|
||||
@app_base_path = ''
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
end
|
||||
|
||||
|
||||
def module_app_key=(var)
|
||||
@module_app_title = var
|
||||
@module_app = ModuleApp.where(:title=>var).desc(:create_date).first
|
||||
@module_app_key = @module_app.key
|
||||
end
|
||||
|
||||
def head_label_i18n(var,optoins =nil)
|
||||
@head_label = var
|
||||
@icon_class = optoins[:icon_class]
|
||||
end
|
||||
|
||||
def available_for(var)
|
||||
@available_for = var
|
||||
end
|
||||
|
||||
def active_for_controllers(var)
|
||||
@active_for_controllers = var
|
||||
end
|
||||
|
||||
def active_for_object_auth(var)
|
||||
@active_for_object_auth = var
|
||||
end
|
||||
|
||||
def head_link_path(var)
|
||||
@head_link = var
|
||||
end
|
||||
|
||||
def context_link(*var)
|
||||
new_context_link = ContextLink.new(*var)
|
||||
@context_links << new_context_link
|
||||
end
|
||||
|
||||
def finalize!
|
||||
set_controllers_scope
|
||||
set_default_active_app_auth
|
||||
@context_links.each do |t|
|
||||
t.set_module_app = @module_app
|
||||
t.finalize!
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def set_default_active_app_auth
|
||||
@active_for_app_auth = @module_app.title
|
||||
end
|
||||
|
||||
def set_controllers_scope
|
||||
var = @active_for_controllers
|
||||
@active_for_controllers = []
|
||||
var[:private].each do |controller|
|
||||
@active_for_controllers << "panel/#{@module_app_key}/back_end/"+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
|
||||
@available_for = options[:available_for]
|
||||
@priority = options[:priority] || 0
|
||||
@path = options[:link_path] || ""
|
||||
@active_for_action = options[:active_for_action] || []
|
||||
@active_for_object_auth = options[:active_for_object_auth] || []
|
||||
@active_for_app_auth = options[:active_for_app_auth] || []
|
||||
end
|
||||
|
||||
def active?
|
||||
active_for_action? || active_for_app_auth? || active_for_ob_auths?
|
||||
end
|
||||
|
||||
def active_for_action?
|
||||
@active_for_action[controller] == action
|
||||
end
|
||||
|
||||
def set_module_app=(var)
|
||||
@module_app = var
|
||||
@module_app_key = var.key
|
||||
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| ["panel/#{@module_app_key}/back_end/"+controller.to_s,action.to_s]}]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,8 +10,8 @@ module OrbitApp
|
||||
@@registrations << DataSheet.new(name,&block)
|
||||
end
|
||||
|
||||
def new_from_module_app(name,base_path,arg)
|
||||
@@registrations << DataSheet.new(name,arg,:base_path=>base_path)
|
||||
def new_from_module_app(name,base_path,*args)
|
||||
@@registrations << DataSheet.new(name,args,:base_path=>base_path)
|
||||
end
|
||||
|
||||
def find_by_key(key)
|
||||
@@ -35,14 +35,21 @@ module OrbitApp
|
||||
attr_reader :name
|
||||
attr_reader :base_path
|
||||
|
||||
def name
|
||||
if @name.is_a? Proc
|
||||
@name.call
|
||||
else
|
||||
@name
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(name,partial=nil,*args ,&block)
|
||||
@base_path = args[0][:base_path]
|
||||
@name = name
|
||||
@name = partial[0][:i18n].nil? ? name : lambda{ I18n.t(partial[0][:i18n]) }
|
||||
@partial_path = ''
|
||||
|
||||
unless partial.nil?
|
||||
@partial_path = partial[:path]
|
||||
@partial_path = partial[0][:path]
|
||||
end
|
||||
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
|
||||
@@ -7,7 +7,7 @@ module OrbitApp
|
||||
|
||||
def new( name ,&block)
|
||||
@@summaries << Item.new(name,&block)
|
||||
binding.pry
|
||||
# binding.pry
|
||||
end
|
||||
|
||||
def all
|
||||
|
||||
Reference in new issue
Block a user