put module app json into init,making orbit app work with module app.
This commit is contained in:
parent
36f6a6fdd6
commit
6995bb1622
|
@ -31,9 +31,9 @@ class Admin::PagePartsController < ApplicationController
|
|||
|
||||
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
|
||||
|
||||
if @module_app.widgets.any?{|b| b.class == Array}
|
||||
@widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
|
||||
end
|
||||
# if @module_app.widgets.any?{|b| b.class == Array}
|
||||
# @widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
|
||||
# end
|
||||
|
||||
case @module_app.key
|
||||
when 'announcement'
|
||||
|
@ -119,7 +119,6 @@ class Admin::PagePartsController < ApplicationController
|
|||
|
||||
def reload_widget_styles
|
||||
@module_app = ModuleApp.find(params[:module_app_id])
|
||||
|
||||
@widget_style = @module_app.widgets[params[:id]]
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -4,6 +4,7 @@ class Item
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::Tree
|
||||
include Mongoid::Tree::Ordering
|
||||
LIST = YAML.load(File.read('config/list.yml'))
|
||||
|
||||
field :name
|
||||
field :path
|
||||
|
@ -15,7 +16,7 @@ class Item
|
|||
|
||||
|
||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
|
||||
# validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
|
||||
validates_uniqueness_of :name, :scope => :parent_id
|
||||
validates_presence_of :name
|
||||
validates_associated :parent, :children
|
||||
|
|
|
@ -5,23 +5,11 @@ class ModuleApp
|
|||
|
||||
field :key
|
||||
field :title
|
||||
field :version
|
||||
field :organization
|
||||
field :author
|
||||
field :intro
|
||||
field :update_info
|
||||
field :create_date
|
||||
field :enable_frontend, type: Boolean, :default => true
|
||||
|
||||
field :app_pages ,type: Array
|
||||
# field :widgets ,type: Array
|
||||
field :widgets ,type: Hash
|
||||
field :widget_fields ,type: Array
|
||||
|
||||
has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app
|
||||
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
|
||||
|
||||
has_many :tags
|
||||
# has_many :tags
|
||||
has_many :page_parts
|
||||
has_many :pages
|
||||
|
||||
|
@ -29,6 +17,33 @@ class ModuleApp
|
|||
|
||||
before_save :set_key
|
||||
|
||||
def get_registration
|
||||
OrbitApp::Module::Registration.find_by_key(key)
|
||||
end
|
||||
|
||||
# %w{label_i18n }.each do |field|
|
||||
# define_method(field){|var| get_registration.send("get_#{m}") }
|
||||
# end
|
||||
|
||||
def label_i18n
|
||||
reg = get_registration
|
||||
reg.nil? ? 'Init is not defined completely' : get_registration.get_label_i18n
|
||||
end
|
||||
|
||||
# def method_missing(m, *args, &block)
|
||||
# # get_registration.send("get_#{m}")
|
||||
# end
|
||||
|
||||
def using_default_widget?
|
||||
!get_registration.get_default_widget.blank?
|
||||
end
|
||||
|
||||
def get_widget_for_select
|
||||
widgets = get_registration.get_widgets
|
||||
ary = widgets.collect{|k,v| [I18n.t(v["label"]),k]}
|
||||
ary << [I18n.t('widget.default_widget'),'default_widget']if using_default_widget?
|
||||
end
|
||||
|
||||
def is_manager?(user)
|
||||
managing_users.include?(user)
|
||||
end
|
||||
|
@ -79,6 +94,10 @@ class ModuleApp
|
|||
end
|
||||
end
|
||||
|
||||
def label
|
||||
I18n.t(label_i18n)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_key
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
</div>
|
||||
|
||||
<span id='module_app_list'>
|
||||
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => @module_app.id), {}, {:rel => admin_page_parts_path} %>
|
||||
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :label, :selected => @module_app.id), {}, {:rel => admin_page_parts_path} %>
|
||||
</span>
|
||||
|
||||
<span id='widget_list'>
|
||||
<%#= f.select :widget_path, @module_app.widgets.collect{|widget| [widget.humanize, widget]}, :selected => @part.widget_path %>
|
||||
<%= f.select :widget_path, @module_app.widgets.collect{|k,v| [k.humanize, k]}, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
|
||||
<%= f.select :widget_path, @module_app.get_widget_for_select, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
|
||||
</span>
|
||||
|
||||
<span id='widget_style_list'>
|
||||
|
@ -34,18 +34,10 @@
|
|||
</span>
|
||||
|
||||
<span id='widget_field'>
|
||||
|
||||
<%= render 'widget_fields' %>
|
||||
|
||||
<%#= f.label :widget_field %>
|
||||
<%# @module_app.widget_fields.each_with_index do |widget_field, i| %>
|
||||
<%#= i+1 %>
|
||||
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part.widget_field ? @part.widget_field[i] : nil) ), :include_blank => true %> <br />
|
||||
<%# end %>
|
||||
|
||||
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, @part.widget_field.collect{|widget_field| widget_field}), {:multiple => :multiple, :size => 6} %>
|
||||
</span>
|
||||
|
||||
|
||||
<div id="widget_data_count">
|
||||
<%= f.label :widget_data_count %>
|
||||
<%= f.text_field :widget_data_count %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>");
|
||||
$('#widget_list select').html("<%= j options_for_select(@module_app.get_widget_for_select) %>");
|
||||
$('#widget_style_list').html("<%= escape_javascript(select 'page_part', 'widget_style', @module_app.widgets[@widget_path]) if !@widget_path.blank? %>");
|
||||
$('#widget_field').html("<%= j render 'widget_fields' %>");
|
||||
$('#widget_category').html("<%= j render 'widget_categories' %>");
|
||||
|
|
|
@ -70,3 +70,10 @@ widget_field_type:
|
|||
- tag
|
||||
- viewcount
|
||||
- poster
|
||||
|
||||
default_widget_style:
|
||||
- style1
|
||||
- style2
|
||||
- style3
|
||||
- style4
|
||||
- style5
|
File diff suppressed because it is too large
Load Diff
|
@ -4,6 +4,8 @@ require "orbit_app/helper/renderer"
|
|||
require "orbit_app/helper/side_bar_renderer"
|
||||
require "orbit_app/helper/context_link_renderer"
|
||||
require "orbit_app/module/side_bar"
|
||||
require "orbit_app/module/widget"
|
||||
require "orbit_app/module/front_end"
|
||||
require "orbit_app/plugin/summary"
|
||||
require "orbit_app/plugin/registration"
|
||||
require "orbit_app/module/summary"
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
module OrbitApp
|
||||
module Module
|
||||
module FrontendUtility
|
||||
Version = "0.1"
|
||||
|
||||
module ClassMethods
|
||||
@@frontend_pages = []
|
||||
|
||||
def add(var)
|
||||
@@frontend_pages << var
|
||||
end
|
||||
|
||||
def all
|
||||
return @@frontend_pages
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
extend ClassMethods
|
||||
def self.included( other )
|
||||
other.extend( ClassMethods )
|
||||
end
|
||||
|
||||
class AppPageSet
|
||||
def initialize(&block)
|
||||
@frontend_pages = []
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
end
|
||||
|
||||
def app_page(name,options ={})
|
||||
@frontend_pages << AppPage.new(name,options)
|
||||
end
|
||||
|
||||
def to_module_app_format
|
||||
@frontend_pages.collect{|t| t.name}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class AppPage
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name,options ={})
|
||||
@name = name
|
||||
end
|
||||
|
||||
def finalize!
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
end# of AppPage
|
||||
end # of FrontendUtility
|
||||
end # of Module
|
||||
end # of OrbitApp
|
|
@ -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,20 +28,69 @@ 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
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
setup_module_app
|
||||
end
|
||||
|
||||
def setup_module_app
|
||||
module_app = ModuleApp.first(conditions: {:key=>@key,:title=>name})
|
||||
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
|
||||
|
||||
begin
|
||||
module_app.save(:validate=>false)
|
||||
rescue
|
||||
retry
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def get_label_i18n
|
||||
@module_label
|
||||
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_widgets
|
||||
@widget_set.nil? ? {} : @widget_set.to_module_app_format
|
||||
end
|
||||
|
||||
def get_categories
|
||||
eval(@widget_set.categories_query) rescue nil
|
||||
end
|
||||
|
||||
def get_tags
|
||||
eval(@widget_set.tags_query) rescue nil
|
||||
end
|
||||
|
||||
def front_end(&block)
|
||||
@front_end_app_pages = FrontendUtility::AppPageSet.new(&block)
|
||||
end
|
||||
|
||||
def side_bar(&block)
|
||||
@side_bar = SideBarRegisition::SideBar.new(&block)
|
||||
@side_bar.module_app_key = @name
|
||||
@side_bar.finalize!
|
||||
OrbitApp::Module::SideBarRegisition.add(@side_bar)
|
||||
@side_bar = SideBarRegisition::SideBar.new(@name,@key,&block)
|
||||
end
|
||||
|
||||
def personal_plugin(params)
|
||||
|
@ -49,10 +98,20 @@ module OrbitApp
|
|||
Plugin::Registration.new_from_module_app(@name,@base_path,params)
|
||||
end
|
||||
|
||||
def base_url(var)
|
||||
@base_path = var
|
||||
def widgets(&block)
|
||||
# @widgets = WidgetRegisition::WidgetSet.new(&block)
|
||||
@widget_set = WidgetUtility::WidgetSet.new(&block)
|
||||
|
||||
# @widgets = widget_set.widgets
|
||||
# @default_widget = widget_set.default_widget
|
||||
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
|
|
@ -37,8 +37,7 @@ module OrbitApp
|
|||
# def is_manager?
|
||||
# binding.pry
|
||||
# end
|
||||
def initialize( &block)
|
||||
name = ''
|
||||
def initialize(name = '',key,&block)
|
||||
@head_label = name
|
||||
@context_links = []
|
||||
@available_for = []
|
||||
|
@ -48,18 +47,16 @@ module OrbitApp
|
|||
@head_link = ""
|
||||
@app_base_path = ''
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
# setup_module_app(module_app_key)
|
||||
@module_app_key = key
|
||||
finalize!
|
||||
SideBarRegisition.add(self)
|
||||
end
|
||||
|
||||
|
||||
def module_app_key=(var)
|
||||
@module_app_title = var
|
||||
@module_app = ModuleApp.where(:title=>var).desc(:create_date).first
|
||||
@module_app_key = @module_app.key
|
||||
end
|
||||
|
||||
def head_label_i18n(var,optoins =nil)
|
||||
def head_label_i18n(var,options ={})
|
||||
@head_label = var
|
||||
@icon_class = optoins[:icon_class]
|
||||
@icon_class = options[:icon_class]
|
||||
end
|
||||
|
||||
def available_for(var)
|
||||
|
@ -85,17 +82,23 @@ module OrbitApp
|
|||
|
||||
def finalize!
|
||||
set_controllers_scope
|
||||
set_default_active_app_auth
|
||||
# set_default_active_app_auth
|
||||
@context_links.each do |t|
|
||||
t.set_module_app = @module_app
|
||||
# t.set_module_app = @module_app
|
||||
t.finalize!
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def set_default_active_app_auth
|
||||
@active_for_app_auth = @module_app.title
|
||||
end
|
||||
# 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
|
||||
|
@ -131,10 +134,10 @@ module OrbitApp
|
|||
@active_for_action[controller] == action
|
||||
end
|
||||
|
||||
def set_module_app=(var)
|
||||
@module_app = var
|
||||
@module_app_key = var.key
|
||||
end
|
||||
# def set_module_app=(var)
|
||||
# @module_app = var
|
||||
# @module_app_key = var.key
|
||||
# end
|
||||
|
||||
def finalize!
|
||||
set_active_actions
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
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 get_categories
|
||||
@categories_query
|
||||
end
|
||||
|
||||
def get_tags
|
||||
@tags_query
|
||||
end
|
||||
|
||||
def default_widget(&block)
|
||||
@default_widget = DefaultWidget.new(&block)
|
||||
end
|
||||
|
||||
def customize_widget(name,label,options ={})
|
||||
@widgets << Widget.new(name,label,options)
|
||||
end
|
||||
|
||||
def to_module_app_format
|
||||
hash = {}
|
||||
@widgets.collect{|t| hash[t.name] = t.to_hash}
|
||||
hash
|
||||
end
|
||||
|
||||
def get_default_widget
|
||||
return @default_widget
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class DefaultWidget
|
||||
def initialize(&block)
|
||||
@query = nil
|
||||
@image = nil
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
end
|
||||
|
||||
def to_module_app_format
|
||||
{:query=>@query,:image=>@image} rescue nil
|
||||
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,label,options ={})
|
||||
@name = name
|
||||
@fields = options[:fields]
|
||||
@label = label
|
||||
end
|
||||
|
||||
def to_hash
|
||||
{:name => @name,:fields=>@fields,:label=>@label}
|
||||
end
|
||||
|
||||
def finalize!
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
end# of widget
|
||||
end # of WidgetRegisition
|
||||
end # of Module
|
||||
end # of OrbitApp
|
|
@ -15,3 +15,6 @@ zh_tw:
|
|||
search: 搜尋公告
|
||||
update_bulletin_success: 公告已成功更新
|
||||
update_bulletin_category_success: 公告類別已成功更新
|
||||
widget:
|
||||
index: 目錄Widget
|
||||
bulletins_and_web_links: 公告與連結並排Widget
|
|
@ -1,9 +1,36 @@
|
|||
module Announcement
|
||||
OrbitApp.registration "Announcement",:type=> 'ModuleApp' do
|
||||
|
||||
module_label 'announcement.announcement'
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
personal_plugin :enable => true,:path=>"panel/announcement/plugin/profile",:i18n=>'admin.announcement'
|
||||
|
||||
version "0.1"
|
||||
organization "Rulingcom"
|
||||
author "RD dep"
|
||||
intro "I am intro"
|
||||
update_info 'some update_info'
|
||||
|
||||
front_end do
|
||||
app_page 'bulletins'
|
||||
end
|
||||
|
||||
category ["BulletinCategory"]
|
||||
|
||||
widgets do
|
||||
default_widget do
|
||||
query 'Bulletin.all'
|
||||
image :image
|
||||
end
|
||||
|
||||
categories_query 'BulletinCategory.all'
|
||||
tags_query 'AnnouncementTag.all'
|
||||
|
||||
customize_widget "index","announcement.widget.index",:fields=>["title","category","postdate"]
|
||||
customize_widget "bulletins_and_web_links","announcement.widget.bulletins_and_web_links"
|
||||
# item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"]
|
||||
# item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links"
|
||||
end
|
||||
|
||||
side_bar do
|
||||
head_label_i18n 'admin.announcement',:icon_class=>"icons-announcement"
|
||||
available_for [:admin,:guest,:manager,:sub_manager]
|
||||
|
|
Loading…
Reference in New Issue