deliver API

This commit is contained in:
Fu Matthew 2013-03-22 14:19:10 +08:00 committed by Matt K. Fu
parent 6af375efa4
commit f6b600df59
9 changed files with 36 additions and 26 deletions

View File

@ -24,7 +24,7 @@ class Admin::PagePartsController < OrbitBackendController
def edit def edit
@part = PagePart.find(params[:id]) @part = PagePart.find(params[:id])
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) @module_apps = ModuleApp.where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc)
@module_app = @part.module_app ? @part.module_app : nil @module_app = @part.module_app ? @part.module_app : nil
@user_choose = @part.widget_path @user_choose = @part.widget_path
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag @r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag

View File

@ -13,7 +13,7 @@ helper Admin::PagePartsHelper
def new def new
@item = Page.new @item = Page.new
@item.parent = Item.find(params[:parent_id]) rescue nil @item.parent = Item.find(params[:parent_id]) rescue nil
@apps = ModuleApp.excludes(app_pages: nil).entries @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
@designs = Design.all.entries @designs = Design.all.entries
@design = Design.first @design = Design.first
end end
@ -21,7 +21,7 @@ helper Admin::PagePartsHelper
def edit def edit
@item = Page.find(params[:id]) @item = Page.find(params[:id])
@user_choose = @item.app_frontend_url @user_choose = @item.app_frontend_url
@apps = ModuleApp.excludes(app_pages: nil).entries @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
@designs = Design.all.entries @designs = Design.all.entries
@ -62,7 +62,7 @@ helper Admin::PagePartsHelper
end end
else else
flash.now[:error] = t('create.error.page') flash.now[:error] = t('create.error.page')
@apps = ModuleApp.all @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
@designs = Design.all.entries @designs = Design.all.entries
@design = Design.first @design = Design.first
render :action => "new" render :action => "new"

View File

@ -42,7 +42,7 @@
<div class="control-group" id="module_app_list"> <div class="control-group" id="module_app_list">
<%= f.label '',t("default_widget.select_module_app"), :class => 'control-label' %> <%= f.label '',t("default_widget.select_module_app"), :class => 'control-label' %>
<div class="controls"> <div class="controls">
<%= render :partial => "app_selector", :locals => { :f => f } %> <%= render :partial => "app_selector", :locals => { :f => f } %>
</div> </div>
</div> </div>

View File

@ -1,20 +1,27 @@
module OrbitApp module OrbitApp
module Module module Module
module FrontendUtility module FrontendUtility
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@frontend_pages = [] @@frontend_pages = {}
#Record all frontend pages of orbit #Record all frontend pages of orbit
def add(var) #build @@frontend_pages def add(key,var) #build @@frontend_pages
@@frontend_pages << var if @@frontend_pages[key].nil?
@@frontend_pages[key]= {"frontend"=>var}
else
@@frontend_pages[key]["frontend"]= var
end
end
def add_default_widget(key,var)
@@frontend_pages[key]["default_widget"]= var
end end
def all #return all frontend_pages of orbit def all #return all frontend_pages of orbit
return @@frontend_pages return @@frontend_pages
end end
end end
extend ClassMethods extend ClassMethods
@ -23,9 +30,10 @@ module OrbitApp
end end
class AppPageSet # From Registration class AppPageSet # From Registration
def initialize(&block) def initialize(name,key,&block)
@frontend_pages = [] @frontend_pages = []
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
OrbitApp::Module::FrontendUtility.add(key,@frontend_pages)
end end
def app_page(name,&block) def app_page(name,&block)

View File

@ -1,7 +1,7 @@
module OrbitApp module OrbitApp
module Module module Module
module Registration module Registration
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@registrations = [] @@registrations = []
@ -120,7 +120,7 @@ module OrbitApp
end end
def front_end(&block) #setter for front_end from init def front_end(&block) #setter for front_end from init
@front_end_app_pages = FrontendUtility::AppPageSet.new(&block) @front_end_app_pages = FrontendUtility::AppPageSet.new(@name,@key,&block)
end end
def side_bar(&block) #setter for side_bar from init def side_bar(&block) #setter for side_bar from init
@ -129,12 +129,12 @@ module OrbitApp
def personal_plugin(params) #setter for personal_plugin from init def personal_plugin(params) #setter for personal_plugin from init
# TODO 這裡要看是一些檔案是不是都有 # TODO 這裡要看是一些檔案是不是都有
Plugin::Registration.new_from_module_app(@name,@base_path,params) Plugin::Registration.new_from_module_app(@name,@key,@base_path,params)
end end
def widgets(&block) #setter for widget from init def widgets(&block) #setter for widget from init
# @widgets = WidgetRegisition::WidgetSet.new(&block) # @widgets = WidgetRegisition::WidgetSet.new(&block)
@widget_set = WidgetUtility::WidgetSet.new(&block) @widget_set = WidgetUtility::WidgetSet.new(@name,@key,&block)
# @widgets = widget_set.widgets # @widgets = widget_set.widgets
# @default_widget = widget_set.default_widget # @default_widget = widget_set.default_widget

View File

@ -1,7 +1,7 @@
module OrbitApp module OrbitApp
module Module module Module
module SideBarRegisition module SideBarRegisition
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@side_bars = [] @@side_bars = []

View File

@ -1,13 +1,14 @@
module OrbitApp module OrbitApp
module Module module Module
module WidgetUtility module WidgetUtility
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@widgets = [] @@widgets = {}
def add(var) def add(name,default_widget,customize_widget)
@@widgets << var @@widgets[name] = {:default_widget=>default_widget,:customize_widget=>customize_widget}
Hash[@@widgets.sort]
end end
def all def all
@ -22,12 +23,13 @@ module OrbitApp
class WidgetSet class WidgetSet
attr_reader :widgets,:categories_query,:tags_query attr_reader :widgets,:categories_query,:tags_query
def initialize(&block) def initialize(name,key,&block)
@widgets = [] @widgets = []
@default_widget = nil @default_widget = nil
@categories_query = '' @categories_query = ''
@tags_query = '' @tags_query = ''
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
OrbitApp::Module::WidgetUtility.add(key,@default_widget,@widgets)
end end
%w{categories_query tags_query}.each do |field| %w{categories_query tags_query}.each do |field|
@ -58,6 +60,7 @@ module OrbitApp
def default_widget(&block) def default_widget(&block)
@default_widget = DefaultWidget.new(&block) @default_widget = DefaultWidget.new(&block)
# OrbitApp::Module::FrontendUtility.add()
end end
def customize_widget(name,&block) def customize_widget(name,&block)
@ -72,7 +75,7 @@ module OrbitApp
# @customize_widget_options_fields_i18n = settings # @customize_widget_options_fields_i18n = settings
# end # end
def to_module_app_format def to_module_app_format
hash = {} hash = {}
@widgets.collect{|t| hash[t.name] = t.to_hash} @widgets.collect{|t| hash[t.name] = t.to_hash}
hash["default_widget"]= DefaultWidget.get_interface_args unless @default_widget.blank? hash["default_widget"]= DefaultWidget.get_interface_args unless @default_widget.blank?
@ -115,7 +118,6 @@ module OrbitApp
end end
def self.get_interface_args def self.get_interface_args
#will need to work with design
{:name=>"default_widget",:field=>@fields,:style=>@enabled_styles,:i18n=>'default_widget.default_widget'} {:name=>"default_widget",:field=>@fields,:style=>@enabled_styles,:i18n=>'default_widget.default_widget'}
end end

View File

@ -1,7 +1,7 @@
module OrbitApp module OrbitApp
module Plugin module Plugin
module Registration module Registration
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@registrations = [] @@registrations = []
@ -10,7 +10,7 @@ module OrbitApp
@@registrations << DataSheet.new(name,&block) @@registrations << DataSheet.new(name,&block)
end end
def new_from_module_app(name,base_path,*args) def new_from_module_app(name,key,base_path,*args)
@@registrations << DataSheet.new(name,args,:base_path=>base_path) @@registrations << DataSheet.new(name,args,:base_path=>base_path)
end end

View File

@ -1,6 +1,6 @@
module OrbitApp module OrbitApp
module Summary module Summary
Version = "0.1" Version = "0.2"
module ClassMethods module ClassMethods
@@summaries = [] @@summaries = []