This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/lib/orbit_app/module/registration.rb

205 lines
5.6 KiB
Ruby
Raw Normal View History

module OrbitApp
module Module
module Registration
2013-03-22 06:19:10 +00:00
Version = "0.2"
module ClassMethods
@@registrations = []
def new( name ,&block)
@@registrations << DataSheet.new(name,&block)
end
def find_by_key(key)
@@registrations.each{|t|
return t if t.key == key
}
return nil
end
def all
return @@registrations
end
end
extend ClassMethods
def self.included( other )
other.extend( ClassMethods )
end
class DataSheet
2013-07-10 08:42:25 +00:00
attr_reader :name,:key,:base_path,:module_label,:data_count, :has_category, :has_tag, :authorizable_models, :is_approvable, :is_authorizable
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'
2013-02-25 04:49:06 +00:00
@data_count = 1..15 # as default
@has_category = nil
2013-05-24 10:42:01 +00:00
@has_tag = nil
2013-07-10 08:42:25 +00:00
@authorizable_models = []
@is_approvable = nil
@is_authorizable = nil
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
setup_module_app
end
2012-12-05 10:35:58 +00:00
def get_module_app
ModuleApp.first(conditions: {:key=>@key,:title=>name})
end
def setup_module_app
2012-12-05 10:35:58 +00:00
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
2013-02-18 09:03:18 +00:00
def get_link_methods
return @widget_set.get_link_methods
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
2013-02-23 10:29:50 +00:00
def get_data_count
@data_count
end
def get_icon_class
@side_bar.get_icon_class
end
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
def get_widgets
@widget_set.nil? ? {} : @widget_set.to_module_app_format
end
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)
end
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)
end
def personal_plugin(params) #setter for personal_plugin from init
# TODO 這裡要看是一些檔案是不是都有
2013-03-22 06:19:10 +00:00
Plugin::Registration.new_from_module_app(@name,@key,@base_path,params)
end
def widgets(&block) #setter for widget from init
# @widgets = WidgetRegisition::WidgetSet.new(&block)
2013-03-22 06:19:10 +00:00
@widget_set = WidgetUtility::WidgetSet.new(@name,@key,&block)
# @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|
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
2013-07-10 08:42:25 +00:00
def approvable(link=true)
@is_approvable = {:with_link => link}
end
def authorizable(link=true, &block)
@is_authorizable = {:with_link => link}
if block
block.call
else
authorizable_on
end
end
def authorizable_on(klass = 'Category')
@authorizable_models << klass
end
def categorizable
@has_category = true
end
2013-05-24 10:42:01 +00:00
def taggable
@has_tag = true
end
2013-07-10 08:42:25 +00:00
def get_authorizable_models
@authorizable_models
end
def get_has_category
2013-07-10 08:42:25 +00:00
@has_category == true
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
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]
end
end # of class DataSheet
end
end
end