2012-09-24 03:43:48 +00:00
|
|
|
module OrbitApp
|
|
|
|
module Module
|
|
|
|
module Registration
|
2013-03-22 06:19:10 +00:00
|
|
|
Version = "0.2"
|
2012-09-24 03:43:48 +00:00
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
@@registrations = []
|
|
|
|
|
|
|
|
def new( name ,&block)
|
|
|
|
@@registrations << DataSheet.new(name,&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_key(key)
|
|
|
|
@@registrations.each{|t|
|
2012-11-29 06:21:46 +00:00
|
|
|
return t if t.key == key
|
2012-09-24 03:43:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
return @@registrations
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
extend ClassMethods
|
|
|
|
def self.included( other )
|
|
|
|
other.extend( ClassMethods )
|
|
|
|
end
|
|
|
|
|
|
|
|
class DataSheet
|
2013-12-12 04:49:20 +00:00
|
|
|
attr_reader :name,:key,:base_path,:module_label,:data_count, :has_category, :has_tag, :approvable_models, :authorizable_models, :is_approvable, :is_authorizable, :enable_widget_data_count, :enable_page_data_count
|
2012-09-24 03:43:48 +00:00
|
|
|
|
|
|
|
def initialize(name, &block)
|
|
|
|
@name = name
|
2012-11-29 06:21:46 +00:00
|
|
|
@key = name.underscore.singularize
|
2012-11-20 07:56:52 +00:00
|
|
|
@side_bar = nil
|
2012-11-29 06:21:46 +00:00
|
|
|
@front_end_app_pages = nil
|
2013-01-29 12:33:40 +00:00
|
|
|
@module_label = 'rulingcom.errors.init.module_app_noname'
|
2013-02-25 04:49:06 +00:00
|
|
|
@data_count = 1..15 # as default
|
2013-07-02 08:46:44 +00:00
|
|
|
@has_category = nil
|
2013-05-24 10:42:01 +00:00
|
|
|
@has_tag = nil
|
2013-08-19 10:54:35 +00:00
|
|
|
@approvable_models = []
|
2013-07-10 08:42:25 +00:00
|
|
|
@authorizable_models = []
|
|
|
|
@is_approvable = nil
|
2013-07-02 08:46:44 +00:00
|
|
|
@is_authorizable = nil
|
2013-12-10 08:55:47 +00:00
|
|
|
@enable_widget_data_count = true
|
2013-12-12 04:49:20 +00:00
|
|
|
@enable_page_data_count = true
|
2012-09-24 03:43:48 +00:00
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
2012-11-29 06:21:46 +00:00
|
|
|
setup_module_app
|
|
|
|
end
|
|
|
|
|
2012-12-05 10:35:58 +00:00
|
|
|
def get_module_app
|
|
|
|
ModuleApp.first(conditions: {:key=>@key,:title=>name})
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def setup_module_app
|
2012-12-05 10:35:58 +00:00
|
|
|
module_app = get_module_app
|
2012-11-29 06:21:46 +00:00
|
|
|
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
|
2013-01-29 12:33:40 +00:00
|
|
|
module_app.refetch_setting!(self)
|
2012-11-29 06:21:46 +00:00
|
|
|
begin
|
|
|
|
module_app.save(:validate=>false)
|
|
|
|
rescue
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-12-10 08:55:47 +00:00
|
|
|
def get_enable_widget_data_count
|
|
|
|
@enable_widget_data_count
|
|
|
|
end
|
|
|
|
|
2013-12-12 04:49:20 +00:00
|
|
|
def get_enable_page_data_count
|
|
|
|
@enable_page_data_count
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def get_label_i18n
|
|
|
|
@module_label
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def get_default_widget_fields
|
|
|
|
return @widget_set.get_fields
|
|
|
|
end
|
|
|
|
|
2013-02-18 09:03:18 +00:00
|
|
|
def get_link_methods
|
|
|
|
return @widget_set.get_link_methods
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
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
|
|
|
|
|
2013-02-23 10:29:50 +00:00
|
|
|
def get_data_count
|
|
|
|
@data_count
|
|
|
|
end
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
def get_icon_class
|
|
|
|
@side_bar.get_icon_class
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def get_widget_by_path(path)
|
|
|
|
if @widget_set
|
|
|
|
@widget_set.find_by_path(path)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-23 10:29:50 +00:00
|
|
|
def default_widget_setting
|
|
|
|
@widget_set.default_widget_setting
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget_setting
|
|
|
|
@widget_set
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def get_widgets
|
|
|
|
@widget_set.nil? ? {} : @widget_set.to_module_app_format
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def front_end(&block) #setter for front_end from init
|
2013-03-22 06:19:10 +00:00
|
|
|
@front_end_app_pages = FrontendUtility::AppPageSet.new(@name,@key,&block)
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def side_bar(&block) #setter for side_bar from init
|
2013-07-10 08:42:25 +00:00
|
|
|
@side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app), is_approvable_with_link?, is_authorizable_with_link?, &block)
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def personal_plugin(params) #setter for personal_plugin from init
|
2012-09-24 03:43:48 +00:00
|
|
|
# TODO 這裡要看是一些檔案是不是都有
|
2013-03-22 06:19:10 +00:00
|
|
|
Plugin::Registration.new_from_module_app(@name,@key,@base_path,params)
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def widgets(&block) #setter for widget from init
|
2012-11-29 06:21:46 +00:00
|
|
|
# @widgets = WidgetRegisition::WidgetSet.new(&block)
|
2013-03-22 06:19:10 +00:00
|
|
|
@widget_set = WidgetUtility::WidgetSet.new(@name,@key,&block)
|
2012-11-29 06:21:46 +00:00
|
|
|
|
|
|
|
# @widgets = widget_set.widgets
|
|
|
|
# @default_widget = widget_set.default_widget
|
|
|
|
end
|
|
|
|
|
2013-02-23 10:29:50 +00:00
|
|
|
%w{data_count module_label category base_url version organization author intro update_info}.each do |field|
|
2012-11-29 06:21:46 +00:00
|
|
|
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
2012-11-29 06:21:46 +00:00
|
|
|
|
2013-08-19 10:54:35 +00:00
|
|
|
def approvable(link=true, &block)
|
2013-07-10 08:42:25 +00:00
|
|
|
@is_approvable = {:with_link => link}
|
2013-08-19 10:54:35 +00:00
|
|
|
if block
|
|
|
|
block.call
|
|
|
|
else
|
|
|
|
approvable_on
|
|
|
|
end
|
2013-07-10 08:42:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorizable(link=true, &block)
|
|
|
|
@is_authorizable = {:with_link => link}
|
|
|
|
if block
|
|
|
|
block.call
|
|
|
|
else
|
|
|
|
authorizable_on
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-10 08:55:47 +00:00
|
|
|
def enable_widget_data_count(enable = true)
|
|
|
|
@enable_widget_data_count = enable
|
|
|
|
end
|
|
|
|
|
2013-12-12 04:49:20 +00:00
|
|
|
def enable_page_data_count(enable = true)
|
|
|
|
@enable_page_data_count = enable
|
|
|
|
end
|
|
|
|
|
2013-08-19 10:54:35 +00:00
|
|
|
def approvable_on(klass = 'Category')
|
|
|
|
@approvable_models << klass
|
|
|
|
end
|
|
|
|
|
2013-07-10 08:42:25 +00:00
|
|
|
def authorizable_on(klass = 'Category')
|
|
|
|
@authorizable_models << klass
|
2013-07-02 08:46:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def categorizable
|
|
|
|
@has_category = true
|
|
|
|
end
|
|
|
|
|
2013-05-24 10:42:01 +00:00
|
|
|
def taggable
|
|
|
|
@has_tag = true
|
|
|
|
end
|
|
|
|
|
2013-08-19 10:54:35 +00:00
|
|
|
def get_approvable_models
|
|
|
|
@approvable_models
|
|
|
|
end
|
|
|
|
|
2013-07-10 08:42:25 +00:00
|
|
|
def get_authorizable_models
|
|
|
|
@authorizable_models
|
|
|
|
end
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
def get_has_category
|
2013-07-10 08:42:25 +00:00
|
|
|
@has_category == true
|
2013-07-02 08:46:44 +00:00
|
|
|
end
|
|
|
|
|
2013-05-24 10:42:01 +00:00
|
|
|
def get_has_tags
|
2013-07-10 08:42:25 +00:00
|
|
|
@has_tag == true
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_is_approvable
|
|
|
|
!@is_approvable.blank?
|
2013-05-24 10:42:01 +00:00
|
|
|
end
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
def get_is_authorizable
|
2013-07-10 08:42:25 +00:00
|
|
|
!@is_authorizable.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_approvable_with_link?
|
|
|
|
@is_approvable && @is_approvable[:with_link]
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_authorizable_with_link?
|
|
|
|
@is_authorizable && @is_authorizable[:with_link]
|
2013-07-02 08:46:44 +00:00
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
end # of class DataSheet
|
|
|
|
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|