module OrbitApp module Module module Registration 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 attr_reader :name,:key,:base_path,:module_label,:data_count, :has_tag 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' @data_count = 1..15 # as default @has_tag = nil block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? setup_module_app end def get_module_app ModuleApp.first(conditions: {:key=>@key,:title=>name}) 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) 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_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 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 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 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(@name,@key,&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,@key,@base_path,params) end def widgets(&block) #setter for widget from init # @widgets = WidgetRegisition::WidgetSet.new(&block) @widget_set = WidgetUtility::WidgetSet.new(@name,@key,&block) # @widgets = widget_set.widgets # @default_widget = widget_set.default_widget end %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 def taggable @has_tag = true end def get_has_tags @has_tag.nil? ? false : true end end # of class DataSheet end end end