default widget link.
make sure to run rake migrate:make_default_widget_work_config for changing announcement module app
This commit is contained in:
parent
3e8b029c5f
commit
5efbe07fbe
|
@ -11,7 +11,7 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
@default_widget = @page_part.module_app.get_default_widget
|
@default_widget = @page_part.module_app.get_default_widget
|
||||||
@widget_image_field = @default_widget[:image]
|
@widget_image_field = @default_widget[:image]
|
||||||
data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
||||||
@data = eval(@default_widget[:query]).limit(data_limit).includes(@widget_image_field)
|
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field)
|
||||||
@fields = @page_part.widget_field
|
@fields = @page_part.widget_field
|
||||||
|
|
||||||
case params[:type]
|
case params[:type]
|
||||||
|
|
|
@ -8,4 +8,15 @@ module Admin::PagePartsHelper
|
||||||
res.html_safe
|
res.html_safe
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def widget_field_options(i)
|
||||||
|
options = @module_app.widget_fields.collect{|widget_field| [I18n.t(widget_field[1]), widget_field[0]]}
|
||||||
|
options_for_select(options, (@part[:widget_field][i][0] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) )
|
||||||
|
end
|
||||||
|
|
||||||
|
def widget_fiield_type_options(i)
|
||||||
|
options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
|
||||||
|
options_for_select(options, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) )
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -0,0 +1,48 @@
|
||||||
|
module DefaultWidgetHelper
|
||||||
|
def get_field_header(field)
|
||||||
|
I18n.t(@page_part.module_app.widget_fields.select{|t|t[0]==field}[0][1])
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_to_field(row_data,field)
|
||||||
|
method_ary = @page_part.module_app.widget_fields_link_method
|
||||||
|
if method_ary.has_key? field
|
||||||
|
url = case method_ary[field]["args"]
|
||||||
|
when nil # no args
|
||||||
|
eval(method_ary[field]["method"])
|
||||||
|
when :self # passing self
|
||||||
|
eval "#{method_ary[field]['method']}('#{row_data.id}')"
|
||||||
|
else
|
||||||
|
ary = method_ary[field]["args"].clone
|
||||||
|
object_hash = ary.each do |key,val|
|
||||||
|
ary[key]= row_data.send(val[0]).send(val[1]).to_s
|
||||||
|
end
|
||||||
|
binding.pry
|
||||||
|
eval "#{method_ary[field]['method']}(#{object_hash})"
|
||||||
|
end
|
||||||
|
|
||||||
|
link_to row_data.send(field),url
|
||||||
|
else
|
||||||
|
row_data.send(field)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# def get_args_mapping(object,row_hash)
|
||||||
|
# first_hash = row_hash.first
|
||||||
|
|
||||||
|
# # row_data.send(method_ary[field]["args"])
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
def get_row_data(row_data,field)
|
||||||
|
field_is_link = (field[0][1]== 'false' ? false : true )
|
||||||
|
field_setting = {:class=>field[0][1],:method=>field[0][0]}
|
||||||
|
if field_is_link
|
||||||
|
field_link = field[0][1].to_s + '_path'
|
||||||
|
binding.pry
|
||||||
|
link = link_to(row_data.send(field_setting[:method]),field_link.send(row_data))
|
||||||
|
content_tag(:span,link,:class=>field_setting[:class])
|
||||||
|
else
|
||||||
|
content_tag(:span,row_data.send(field_setting[:method]),:class=>field_setting[:class])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,14 +0,0 @@
|
||||||
module DefaultWidgetsHelper
|
|
||||||
def get_row_data(row_data,field)
|
|
||||||
field_is_link = (field[0][1]== 'false' ? false : true )
|
|
||||||
field_setting = {:class=>field[0][1],:method=>field[0][0]}
|
|
||||||
if field_is_link
|
|
||||||
field_link = field[0][1].to_s + '_path'
|
|
||||||
binding.pry
|
|
||||||
link = link_to(row_data.send(field_setting[:method]),field_link.send(row_data))
|
|
||||||
content_tag(:span,link,:class=>field_setting[:class])
|
|
||||||
else
|
|
||||||
content_tag(:span,row_data.send(field_setting[:method]),:class=>field_setting[:class])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -19,6 +19,9 @@ class ModuleApp
|
||||||
field :widget_fields ,type: Array
|
field :widget_fields ,type: Array
|
||||||
field :widget_options,type:Hash
|
field :widget_options,type:Hash
|
||||||
field :widget_options_fields_i18n,type:Hash
|
field :widget_options_fields_i18n,type:Hash
|
||||||
|
field :widget_fields_link_method,type:Hash
|
||||||
|
field :get_default_widget,type:Hash
|
||||||
|
|
||||||
has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app
|
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 :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
|
||||||
|
|
||||||
|
@ -30,13 +33,6 @@ class ModuleApp
|
||||||
|
|
||||||
before_save :set_key
|
before_save :set_key
|
||||||
|
|
||||||
#>>>>>>>>>>>>> remove after app config applied
|
|
||||||
def get_default_widget
|
|
||||||
{:query=>'Bulletin.all',:image=> 'image'}
|
|
||||||
end
|
|
||||||
#<<<<<<<<<<<<@@
|
|
||||||
|
|
||||||
|
|
||||||
def is_manager?(user)
|
def is_manager?(user)
|
||||||
managing_users.include?(user)
|
managing_users.include?(user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
<% @module_app.widget_fields.each_with_index do |widget_field, i| %>
|
<% @module_app.widget_fields.each_with_index do |widget_field, i| %>
|
||||||
<%= i+1 %>
|
<%= 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][i][0] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
|
<%= select_tag "page_part[widget_field][]", widget_field_options(i), :include_blank => true %>
|
||||||
<%= select_tag "page_part[widget_field_type][]", options_for_select(LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %> <br />
|
<%= select_tag "page_part[widget_field_type][]", widget_fiield_type_options(i), :include_blank => true %> <br />
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= label_tag :widget_data_count %>
|
<%= label_tag :widget_data_count %>
|
||||||
|
|
|
@ -4,18 +4,14 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<% @fields.each do |field|%>
|
<% @fields.each do |field|%>
|
||||||
<th><%= content_tag(:span,field[0],:class=>field[1])%></th>
|
<th><%= content_tag(:span,get_field_header(field[0]),:class=>field[1])%></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<% @data.each do |row_data| %>
|
<% @data.each do |row_data| %>
|
||||||
<tr>
|
<tr>
|
||||||
<% @fields.each do |field|%>
|
<% @fields.each do |field|%>
|
||||||
<% if field[0] == "bulletin_category"%>
|
<td><%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%></td>
|
||||||
<td><%= content_tag(:span,row_data.send(field[0]).title,:class=>field[1])%></td>
|
|
||||||
<% else %>
|
|
||||||
<td><%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%></td>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<% @fields.each do |field|%>
|
<% @fields.each do |field|%>
|
||||||
<% if field[0] == "bulletin_category"%>
|
|
||||||
<%= content_tag(:span,row_data.send(field[0]).title,:class=>field[1])%>
|
|
||||||
<% else %>
|
|
||||||
<%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%>
|
<%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%>
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -6,11 +6,7 @@
|
||||||
<% @data.each do |row_data| %>
|
<% @data.each do |row_data| %>
|
||||||
<%= content_tag(:li) do %>
|
<%= content_tag(:li) do %>
|
||||||
<% @fields.each do |field|%>
|
<% @fields.each do |field|%>
|
||||||
<% if field[0] == "bulletin_category"%>
|
|
||||||
<%= content_tag(:span,row_data.send(field[0]).title,:class=>field[1])%>
|
|
||||||
<% else %>
|
|
||||||
<%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%>
|
<%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%>
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -6,8 +6,9 @@ module OrbitApp
|
||||||
def render_module_app_error(exception = nil)
|
def render_module_app_error(exception = nil)
|
||||||
default_message = 'ModuleAppErrorHandler'
|
default_message = 'ModuleAppErrorHandler'
|
||||||
meaasge = ''
|
meaasge = ''
|
||||||
|
|
||||||
if exception
|
if exception
|
||||||
meaasge = default_message + exception.message
|
meaasge = default_message +" " + exception.message
|
||||||
end
|
end
|
||||||
render :text=>meaasge
|
render :text=>meaasge
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module OrbitApp
|
||||||
default_message = 'This is a render_object_auth_error'
|
default_message = 'This is a render_object_auth_error'
|
||||||
meaasge = ''
|
meaasge = ''
|
||||||
if exception
|
if exception
|
||||||
meaasge = default_message + exception.message
|
meaasge = default_message +" " + exception.message
|
||||||
end
|
end
|
||||||
render :text=>meaasge
|
render :text=>meaasge
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module OrbitApp
|
||||||
default_message = 'ModuleAppErrorHandler'
|
default_message = 'ModuleAppErrorHandler'
|
||||||
meaasge = ''
|
meaasge = ''
|
||||||
if exception
|
if exception
|
||||||
meaasge = default_message + exception.message
|
meaasge = default_message +" " + exception.message
|
||||||
end
|
end
|
||||||
render :text=>meaasge
|
render :text=>meaasge
|
||||||
end
|
end
|
||||||
|
|
|
@ -210,6 +210,7 @@ module ParserCommon
|
||||||
when 'default_widget'
|
when 'default_widget'
|
||||||
"/panel/orbit_app/widget/#{part.widget_style}?inner=true"
|
"/panel/orbit_app/widget/#{part.widget_style}?inner=true"
|
||||||
else
|
else
|
||||||
|
raise ModuleAppError,"PagePart can't find ModuleApp" if part.module_app.nil?
|
||||||
"/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true&widget_options=#{part.widget_options_uri}"
|
"/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true&widget_options=#{part.widget_options_uri}"
|
||||||
end
|
end
|
||||||
options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}"
|
options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}"
|
||||||
|
|
|
@ -354,7 +354,19 @@ namespace :migrate do
|
||||||
task :make_default_widget_work_config => :environment do
|
task :make_default_widget_work_config => :environment do
|
||||||
a = ModuleApp.where(:key=>'announcement').first
|
a = ModuleApp.where(:key=>'announcement').first
|
||||||
a.widgets[:default_widget] = ['typeA','typeC','typeB_style2','typeB_style3','typeB_style4']
|
a.widgets[:default_widget] = ['typeA','typeC','typeB_style2','typeB_style3','typeB_style4']
|
||||||
a.widget_fields = ["title","bulletin_category","postdate"]
|
a.widget_fields = [
|
||||||
|
["title","announcement.default_widget.title"],
|
||||||
|
["bulletin_category_with_title","announcement.default_widget.bulletin_category_with_title"],
|
||||||
|
["postdate_with_format","announcement.default_widget.postdate_with_format"]
|
||||||
|
]
|
||||||
|
a.get_default_widget = {:query=>'Bulletin.all',:image=> 'image'}
|
||||||
|
a.widget_fields_link_method = {
|
||||||
|
"title"=>{:method => 'panel_announcement_front_end_bulletin_path',
|
||||||
|
:args=>:self},
|
||||||
|
"bulletin_category_with_title"=>{
|
||||||
|
:method => 'panel_announcement_front_end_bulletins_path',
|
||||||
|
:args=>{:category_id => [:bulletin_category,:id]}}
|
||||||
|
}
|
||||||
a.save
|
a.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,15 @@ class Bulletin
|
||||||
string :bulletin_category_id
|
string :bulletin_category_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def postdate_with_format
|
||||||
|
self[:postdate].strftime("%m/%d/%Y")
|
||||||
|
end
|
||||||
|
|
||||||
|
def bulletin_category_with_title
|
||||||
|
self.bulletin_category.title
|
||||||
|
end
|
||||||
|
|
||||||
def share_item
|
def share_item
|
||||||
Item.first(conditions:{name: 'announcement'})
|
Item.first(conditions:{name: 'announcement'})
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,3 +15,7 @@ zh_tw:
|
||||||
search: 搜尋公告
|
search: 搜尋公告
|
||||||
update_bulletin_success: 公告已成功更新
|
update_bulletin_success: 公告已成功更新
|
||||||
update_bulletin_category_success: 公告類別已成功更新
|
update_bulletin_category_success: 公告類別已成功更新
|
||||||
|
default_widget:
|
||||||
|
bulletin_category_with_title: 分類
|
||||||
|
title: 標題
|
||||||
|
postdate_with_format: 張貼日期
|
||||||
|
|
Reference in New Issue