2014-04-01 07:10:21 +00:00
|
|
|
#This is a core class of Orbit Kernel. This class will register a module and set the properties defined in the module's initializer
|
|
|
|
#file.
|
|
|
|
module OrbitApp
|
2014-04-21 02:48:36 +00:00
|
|
|
module Module
|
|
|
|
module Registration
|
|
|
|
module ClassMethods
|
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
#initiate a blank array for registration
|
|
|
|
cattr_accessor :registrations
|
|
|
|
self.registrations = []
|
2014-04-21 02:48:36 +00:00
|
|
|
|
|
|
|
def new(name,&block)
|
2014-05-01 07:14:16 +00:00
|
|
|
self.registrations << RegisteredModule.new(name,&block)
|
2014-04-21 02:48:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_key(key)
|
2014-05-01 07:14:16 +00:00
|
|
|
self.registrations.each{|t|
|
2014-04-21 02:48:36 +00:00
|
|
|
return t if t.key.eql?(key)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2014-05-01 07:14:16 +00:00
|
|
|
return self.registrations
|
2014-04-21 02:48:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
extend ClassMethods
|
|
|
|
def self.included(other)
|
|
|
|
other.extend( ClassMethods )
|
|
|
|
end
|
|
|
|
|
|
|
|
class RegisteredModule
|
2014-06-24 06:07:59 +00:00
|
|
|
attr_reader :name,:key,:base_path, :module_label,:widget_methods,:authorizable_models,:is_authorizable, :data_count, :widget_settings, :icon_class_no_sidebar
|
2014-04-21 02:48:36 +00:00
|
|
|
|
|
|
|
def initialize(name,&block)
|
|
|
|
@name = name
|
|
|
|
@key = @name.underscore.singularize
|
|
|
|
@side_bar = nil
|
|
|
|
@module_label = @name
|
|
|
|
@widget_methods = []
|
2014-05-22 11:19:25 +00:00
|
|
|
@widget_settings = {}
|
2014-04-21 02:48:36 +00:00
|
|
|
@is_taggable = false
|
2014-05-01 07:14:16 +00:00
|
|
|
@authorizable_models = []
|
|
|
|
@is_authorizable = false
|
2014-04-21 02:48:36 +00:00
|
|
|
@taggable_model = nil
|
|
|
|
@is_categorizable = false
|
2014-05-13 10:41:29 +00:00
|
|
|
@is_frontend_enabled = false
|
|
|
|
@data_count = nil
|
2014-06-24 06:07:59 +00:00
|
|
|
@icon_class_no_sidebar = nil
|
2014-04-21 02:48:36 +00:00
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
|
|
setup_module_app
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_module_app
|
|
|
|
ModuleApp.find_by(key: @key, title: name) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
module_app.save(:validate=>false)
|
|
|
|
end
|
|
|
|
|
2014-06-24 06:07:59 +00:00
|
|
|
%w{data_count module_label icon_class_no_sidebar category base_url version organization author intro update_info}.each do |field|
|
2014-04-21 02:48:36 +00:00
|
|
|
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_label(name = @name)
|
|
|
|
@module_label = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget_methods(widgets)
|
|
|
|
@widget_methods = widgets
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_widget_methods
|
|
|
|
@widget_methods
|
|
|
|
end
|
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
def widget_settings(settings)
|
|
|
|
@widget_settings = settings.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_widget_settings
|
|
|
|
@widget_settings
|
|
|
|
end
|
|
|
|
|
2014-04-21 02:48:36 +00:00
|
|
|
def get_icon_class
|
|
|
|
@side_bar.get_icon_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def side_bar(&block) #setter for side_bar from init
|
|
|
|
@side_bar = SideBarRegistration::SideBar.new(@name,@key,method(:get_module_app), &block)
|
|
|
|
end
|
2014-05-22 11:19:25 +00:00
|
|
|
|
2014-04-21 02:48:36 +00:00
|
|
|
def get_side_bar
|
|
|
|
@side_bar
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon_class
|
2014-06-24 06:07:59 +00:00
|
|
|
(@side_bar.get_icon_class rescue nil || @get_icon_class_no_sidebar)
|
2014-04-21 02:48:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def taggable(model)
|
|
|
|
@is_taggable = true
|
|
|
|
@taggable_model = model.classify
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_taggable
|
|
|
|
@is_taggable
|
|
|
|
end
|
|
|
|
|
|
|
|
def taggable_model
|
|
|
|
@taggable_model
|
|
|
|
end
|
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
def authorizable
|
|
|
|
@is_authorizable = true
|
|
|
|
authorizable_on
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_authorizable
|
|
|
|
@is_authorizable
|
|
|
|
end
|
|
|
|
|
2014-04-21 02:48:36 +00:00
|
|
|
def categorizable
|
|
|
|
@is_categorizable = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_categorizable
|
|
|
|
@is_categorizable
|
|
|
|
end
|
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
def authorizable_on(klass = 'Category')
|
|
|
|
@authorizable_models << klass
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_authorizable_models
|
|
|
|
@authorizable_models
|
|
|
|
end
|
2014-05-13 10:41:29 +00:00
|
|
|
|
|
|
|
def frontend_enabled
|
|
|
|
@is_frontend_enabled = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_frontend_enabled
|
|
|
|
@is_frontend_enabled
|
|
|
|
end
|
|
|
|
|
2014-05-22 11:19:25 +00:00
|
|
|
def is_widget_enabled
|
|
|
|
!@widget_methods.blank?
|
|
|
|
end
|
|
|
|
|
2014-05-13 10:41:29 +00:00
|
|
|
def data_count(range)
|
|
|
|
@data_count = range
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_data_count
|
|
|
|
@data_count
|
|
|
|
end
|
2014-06-04 08:46:29 +00:00
|
|
|
|
2014-06-24 06:07:59 +00:00
|
|
|
def icon_class_no_sidebar(icon_class)
|
|
|
|
@icon_class_no_sidebar = icon_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_icon_class_no_sidebar
|
|
|
|
@icon_class_no_sidebar
|
|
|
|
end
|
|
|
|
|
2014-06-04 08:46:29 +00:00
|
|
|
def personal_plugin(params) #setter for personal_plugin from init
|
|
|
|
Plugin::Registration.new_from_module_app(@name,@key,@base_path,params)
|
|
|
|
end
|
2014-04-21 02:48:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|