member plugin edit

This commit is contained in:
unknown committed 2013-02-20 17:25:20 +08:00
commit bc44d38948
319 files changed
+5405 -2763

No files matched your search

@@ -0,0 +1,33 @@
module ContextLinkRenderer
include Renderer
def render(request,params,current_module_app,current_user,belong_module_app)
@current_module_app = current_module_app
@belong_module_app = belong_module_app
@request = request
@params = params
@current_user = current_user
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
protected
def display?
@available_for.each do |available_for_in_sym|
result = case available_for_in_sym
when :all
true
when :manager
@belong_module_app.is_manager? @current_user
when :sub_manager
@belong_module_app.is_sub_manager? @current_user
else
(eval(available_for_in_sym).include? @current_user rescue false)
end # of case
return true if result || (@current_user.admin? rescue false)
end # of collect
false
end
end
+68
View File
@@ -0,0 +1,68 @@
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 = get_module_app
if module_app.nil?
false
else
module_app.id.to_s == @params[:module_app_id] ? true : false
end
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
+45
View File
@@ -0,0 +1,45 @@
module SideBarRenderer
include Renderer
include AdminHelper
def render(request,params,user,current_module_app)
@belong_module_app = get_module_app
@current_module_app = current_module_app
@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,@current_module_app,@current_user,@belong_module_app)
end.join.html_safe
end
end
end
end
protected
def display? #控制sidebar 要不要算圖
if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員
true
elsif (@current_module_app.open rescue true) # 如果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
-17
View File
@@ -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
+67
View File
@@ -0,0 +1,67 @@
module OrbitApp
module Module
module FrontendUtility
Version = "0.1"
module ClassMethods
@@frontend_pages = []
#Record all frontend pages of orbit
def add(var) #build @@frontend_pages
@@frontend_pages << var
end
def all #return all frontend_pages of orbit
return @@frontend_pages
end
end
extend ClassMethods
def self.included( other )
other.extend( ClassMethods )
end
class AppPageSet # From Registration
def initialize(&block)
@frontend_pages = []
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
def app_page(name,&block)
@frontend_pages << AppPage.new(name,&block)
end
def to_module_app_format #For ModuleApp to fetch data
@frontend_pages.collect{|t| [t.get_i18n,t.name]}
end
end
class AppPage
attr_reader :name
def initialize(name,&block)
@name = name
@frontend_i18n = 'rulingcom.errors.init.app_page_noname'
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
def frontend_i18n(i18n)
@frontend_i18n = i18n
end
def get_i18n
@frontend_i18n
end
def finalize!
end
protected
end# of AppPage
end # of FrontendUtility
end # of Module
end # of OrbitApp
+89 -9
View File
@@ -12,7 +12,7 @@ module OrbitApp
def find_by_key(key)
@@registrations.each{|t|
return t if t.name == key
return t if t.key == key
}
return nil
end
@@ -28,27 +28,107 @@ module OrbitApp
end
class DataSheet
attr_reader :name
attr_reader :base_path
attr_reader :name,:key,:base_path,:module_label
def initialize(name, &block)
@name = name
@key = name.underscore.singularize
@side_bar = nil
@front_end_app_pages = nil
@module_label = 'rulingcom.errors.init.module_app_noname'
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
setup_module_app
end
def plugin
def get_module_app
ModuleApp.first(conditions: {:key=>@key,:title=>name})
end
def personal_plugin(params)
def setup_module_app
module_app = get_module_app
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
module_app.refetch_setting!(self)
begin
module_app.save(:validate=>false)
rescue
retry
end
end
def get_label_i18n
@module_label
end
def get_default_widget_fields
return @widget_set.get_fields
end
def get_default_widget
if @widget_set.nil? # Init not defining widget
return {}
elsif @widget_set.get_default_widget.nil? # Init had defining widget,but say nothing about default_widget
return {}
else
@widget_set.get_default_widget.to_module_app_format
end
end
def get_enable_frontend
(@front_end_app_pages.nil? ? false : true)
end
def get_app_pages
@front_end_app_pages.nil? ? [] : @front_end_app_pages.to_module_app_format
end
def get_widget_by_path(path)
if @widget_set
@widget_set.find_by_path(path)
else
nil
end
end
def get_widgets
@widget_set.nil? ? {} : @widget_set.to_module_app_format
end
def get_categories
@widget_set.get_categories rescue []
end
def get_tags
@widget_set.get_tags rescue []
end
def front_end(&block) #setter for front_end from init
@front_end_app_pages = FrontendUtility::AppPageSet.new(&block)
end
def side_bar(&block) #setter for side_bar from init
@side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app),&block)
end
def personal_plugin(params) #setter for personal_plugin from init
# TODO 這裡要看是一些檔案是不是都有
Plugin::Registration.new_from_module_app(@name,@base_path,params)
end
def base_url(var)
@base_path = var
def widgets(&block) #setter for widget from init
# @widgets = WidgetRegisition::WidgetSet.new(&block)
@widget_set = WidgetUtility::WidgetSet.new(&block)
# @widgets = widget_set.widgets
# @default_widget = widget_set.default_widget
end
end
%w{module_label category base_url version organization author intro update_info}.each do |field|
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
end # of class DataSheet
end
end
end
+172
View File
@@ -0,0 +1,172 @@
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 render_all(request,params,user,current_module_app)
@@side_bars.collect{|t| t.render(request,params,user,current_module_app)}.join.html_safe
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(name = '',key,get_module_app,&block)
@head_label = name
@context_links = []
@available_for = []
@active_for_controllers = []
@active_for_object_auth = []
@active_for_app_auth = []
@head_link = ""
@app_base_path = ''
@module_app_key = key
@get_module_app = get_module_app
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
# setup_module_app(module_app_key)
finalize!
SideBarRegisition.add(self)
end
def get_module_app
@get_module_app.call
end
def head_label_i18n(var,options ={})
@head_label = var
@icon_class = options[: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)
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
@context_links.each do |t|
# t.set_module_app = @module_app
t.finalize!
end
end
protected
# def setup_module_app(var)
# @module_app_title = var
# @module_app = ModuleApp.where(:key=>var).desc(:create_date).first
# @module_app_key = @module_app.key
# end
# 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] || []
@module_app_key = options[:module_app_key]
@get_module_app = options[:get_module_app]
end
def get_module_app
@get_module_app.call
end
def active?
for_action = @active_for_action.blank? ? false : active_for_action?
for_app_auth = @active_for_app_auth.blank? ? false : active_for_app_auth?
for_ob_auth = @active_for_object_auth.blank? ? false : active_for_ob_auths?
for_action || for_app_auth || for_ob_auth
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
+1 -1
View File
@@ -3,7 +3,7 @@ require "orbit_app/summary"
module OrbitApp
module Module
module Summary
module Summary
include OrbitApp::Summary
class Item
+172
View File
@@ -0,0 +1,172 @@
module OrbitApp
module Module
module WidgetUtility
Version = "0.1"
module ClassMethods
@@widgets = []
def add(var)
@@widgets << var
end
def all
return @@widgets
end
end
extend ClassMethods
def self.included( other )
other.extend( ClassMethods )
end
class WidgetSet
attr_reader :widgets,:categories_query,:tags_query
def initialize(&block)
@widgets = []
@default_widget = nil
@categories_query = ''
@tags_query = ''
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
%w{categories_query tags_query}.each do |field|
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
def find_by_path(path)
@widgets.each do |widget|
return widget if widget.name == path
end
end
def get_categories
eval(@categories_query) rescue nil
end
def get_tags
eval(@tags_query) rescue nil
end
def default_widget(&block)
@default_widget = DefaultWidget.new(&block)
end
def customize_widget(name,&block)
@widgets << Widget.new(name,&block)
end
# def customize_widget(name,label,options ={})
# @widgets << Widget.new(name,label,options)
# end
# def customize_widget_options_fields_i18n(settings)
# @customize_widget_options_fields_i18n = settings
# end
def to_module_app_format
hash = {}
@widgets.collect{|t| hash[t.name] = t.to_hash}
hash["default_widget"]= DefaultWidget.get_interface_args unless @default_widget.blank?
hash
end
def get_fields
get_default_widget.get_fields
end
def get_default_widget
return @default_widget
end
end
class DefaultWidget
STYLE = ["typeA","typeB_style2","typeB_style3","typeB_style4","typeC"]
def initialize(&block)
@query = nil
@image = nil
@more_link = {}
@fields = []
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
def more_link_to(label_i18n,path_method)
@more_link[:label_i18n] = label_i18n
@more_link[:path_method] = path_method
end
def self.get_interface_args
#will need to work with design
{:name=>"default_widget",:field=>nil,:label=>'label',:style=>STYLE}
end
def to_module_app_format
{:query=>@query,:image=>@image} rescue nil
end
def link_field(field_name,setting)
@fields << [field_name,setting,:link]
end
def field(field_name)
@fields << [field_name,nil,:field]
end
def get_fields
@fields
end
def query(var)
@query = var
end
def image(var)
@image = var
end
end
class Widget
attr_reader :name,:default_template,:fields
def initialize(name,&block)
@name = name
@options = {}
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
# @fields = options[:fields]
# @label = label
# @style= options[:style]
end
def widget_i18n(str) # "gallery.widget.widget1"
@widget_i18n = str
end
def style(ary)# []
@style = ary
end
def get_options
@options
end
def options(opt_name,*options) # "vertical",
option = options[0]
@options[opt_name] = {:label_i18n=>option[:i18n] , :opts=>option[:options_item]}
# options => :i18n => "gallery.widget_option.vertical",:options_item=>[1, 2]
# :i18n =>"gallery.widget_option.album",:options_item => {"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name}
end
def to_hash
{:name => @name,:fields=>@fields,:label=>@label,:style=>@style,:i18n=>@widget_i18n}
end
protected
end# of widget
end # of WidgetRegisition
end # of Module
end # of OrbitApp
@@ -0,0 +1,73 @@
module OrbitApp
module ModuleAppMembershipTools
def is_manager?(user)
if user.nil?
return false
else
m_users = managing_users
if m_users.blank?
false
else
m_users.include?(user)
end
end
end
def is_sub_manager?(user)
if user.nil?
return false
else # when user is guest
s_m_users = sub_managing_users
result = false
if s_m_users.blank?
result = false
else
result = s_m_users.include?(user)
end
result || is_manager?(user)
end
end
def managing_users
self.managers.collect{ |t| t.user }
end
def sub_managing_users
self.sub_managers.collect{ |t| t.user }
end
def assign_manager(user,assigner)
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
if manager.nil?
manager = self.managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil))
end
manager
end
def assign_sub_manager(user,assigner)
submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil
if submanager.nil? && !self.managing_users.include?(user)
submanager = self.sub_managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil) )
end
submanager
end
def remove_manager(user)
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
if manager
manager.destroy
else
false
end
end
def remove_sub_manager(user)
submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil
if submanager
submanager.destroy
else
false
end
end
end
end
+12 -5
View File
@@ -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,16 +35,23 @@ 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 = ''
@admin_partial_path = ''
unless partial.nil?
@partial_path = partial[:path]
@admin_partial_path = partial[:admin_path]
@partial_path = partial[0][:path]
@admin_partial_path = partial[0][:admin_path]
end
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
+1 -1
View File
@@ -7,7 +7,7 @@ module OrbitApp
def new( name ,&block)
@@summaries << Item.new(name,&block)
binding.pry
# binding.pry
end
def all