Fix a lots.
This commit is contained in:
parent
5659e0531e
commit
5b4386fe7c
|
@ -64,10 +64,67 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
end
|
||||
def update_fields_setting
|
||||
field_params = params.require(:personal_plugin_field).permit! rescue {}
|
||||
field_params[:fields_order] = field_params[:fields_order].map do |k, v|
|
||||
[k, v.sort_by{|k,vv| k.to_i}.map{|vv| vv[1].to_i}]
|
||||
end.to_h
|
||||
@personal_plugin_field.update_attributes(field_params)
|
||||
@personal_plugin_field.save
|
||||
redirect_to params[:referer_url]
|
||||
end
|
||||
def scan_word_block(word)
|
||||
words_idx = []
|
||||
tmp = []
|
||||
is_word = false
|
||||
word.split('').each_with_index do |w, i|
|
||||
if w.match(/\w/)
|
||||
if !is_word
|
||||
tmp << i
|
||||
is_word = true
|
||||
end
|
||||
elsif is_word
|
||||
tmp << i - 1
|
||||
words_idx << tmp
|
||||
tmp = []
|
||||
is_word = false
|
||||
end
|
||||
end
|
||||
if tmp.count == 1
|
||||
tmp << word.length - 1
|
||||
words_idx << tmp
|
||||
tmp = []
|
||||
end
|
||||
last_idx = word.length - 1
|
||||
new_res = []
|
||||
words_idx_reverse = words_idx.reverse
|
||||
words_idx_reverse.each_with_index do |v, i|
|
||||
s = v[0]
|
||||
e = v[1]
|
||||
tmp_str = word[s..e]
|
||||
tmp = word[e+1..last_idx]
|
||||
need_find_quote = tmp.match(/['"]/)
|
||||
need_find_quote = need_find_quote ? need_find_quote[0] : nil
|
||||
tmp_str += tmp
|
||||
prev_word_range = words_idx_reverse[i + 1]
|
||||
start_idx = 0
|
||||
if prev_word_range
|
||||
start_idx = prev_word_range[1] + 1
|
||||
end
|
||||
if need_find_quote
|
||||
tmp = word[start_idx...s].match(/(,\s+|)[,#{need_find_quote}]+\s*$/)
|
||||
else
|
||||
tmp = word[start_idx...s].match(/(,\s+|)\s*$/)
|
||||
end
|
||||
if tmp
|
||||
tmp = tmp[0]
|
||||
tmp_str = tmp + tmp_str
|
||||
last_idx = s - 1 - tmp.length
|
||||
else
|
||||
last_idx = s - 1
|
||||
end
|
||||
new_res << tmp_str
|
||||
end
|
||||
new_res.reverse
|
||||
end
|
||||
def generate_plugin
|
||||
template_dir_path = File.expand_path("../../../../template_generator/", __FILE__) + "/"
|
||||
cp_template_dir_path = "#{Rails.root}/tmp/#{@personal_plugin_field.module_name}/"
|
||||
|
@ -78,6 +135,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
begin
|
||||
in_use_locales = Site.first.in_use_locales
|
||||
primary_modal_fields = @personal_plugin_field.primary_modal_fields.select{|f| (f[:field_name].present? rescue false)}
|
||||
primary_modal_fields << {:field_name=>"authors", :translation_name=>{"zh_tw"=>"全部作者", "en"=>"Authors"}, :field_type=>"text_editor", :localize=>"1", :slug_title=>"0", :periodic_time=>"0"} if primary_modal_fields.select{|f| f[:field_name] == "authors"}.count == 0
|
||||
yml_files = Dir.glob("#{cp_template_dir_path}config/locales/*.yml")
|
||||
yml_files.each do |yml_file|
|
||||
locale = yml_file.split("/").last.split(".yml").first
|
||||
|
@ -125,20 +183,66 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
plugin_template_related_links_text = plugin_template_related_links.to_s
|
||||
fields = plugin_template_related_files + plugin_template_related_links
|
||||
plugin_template_related_files_fields = fields.map{|field_name|
|
||||
"has_many :#{field_name.pluralize}, :dependent => :destroy, :autosave => true\r\n" +
|
||||
"has_many :#{field_name.pluralize}, :dependent => :destroy, :autosave => true\n" +
|
||||
"accepts_nested_attributes_for :#{field_name.pluralize}, :allow_destroy => true"
|
||||
}.join("\r\n")
|
||||
}.join("\n")
|
||||
plugin_template = @personal_plugin_field.primary_modal_name
|
||||
all_fields = primary_modal_fields.map{|f| f[:field_name]} + ["member_profile"]
|
||||
@personal_plugin_field.related_modal_name.each_with_index do |k,i|
|
||||
all_fields += @personal_plugin_field.related_modal_fields[i].to_a.map{|f| "#{k}.#{f[:field_name]}"}
|
||||
end
|
||||
@personal_plugin_field.frontend_fields.each do |k,v|
|
||||
@personal_plugin_field.frontend_fields[k] = v & all_fields
|
||||
end
|
||||
@personal_plugin_field.backend_fields.each do |k,v|
|
||||
@personal_plugin_field.backend_fields[k] = v & all_fields
|
||||
end
|
||||
date_fields = []
|
||||
year_month_fields = []
|
||||
date_time_fields = []
|
||||
primary_modal_fields.each do |field_value|
|
||||
if (field_value[:field_type].present? rescue false)
|
||||
case field_value[:field_type]
|
||||
when "date"
|
||||
date_fields << field_value[:field_name]
|
||||
when "year_month"
|
||||
year_month_fields << field_value[:field_name]
|
||||
when "date_time"
|
||||
date_time_fields << field_value[:field_name]
|
||||
end
|
||||
end
|
||||
end
|
||||
@personal_plugin_field.related_modal_name.each_with_index do |k,i|
|
||||
@personal_plugin_field.related_modal_fields[i].to_a.each do |field_value|
|
||||
field_name = "#{k}.#{field_value[:field_name]}"
|
||||
if (field_value[:field_type].present? rescue false)
|
||||
case field_value[:field_type]
|
||||
when "date"
|
||||
date_fields << field_name
|
||||
when "year_month"
|
||||
year_month_fields << field_name
|
||||
when "date_time"
|
||||
date_time_fields << field_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
backend_index_fields = @personal_plugin_field.backend_fields["index"].to_a rescue []
|
||||
backend_index_fields_contents = backend_index_fields.map do |field_name|
|
||||
if field_name == slug_title
|
||||
"\r\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" +
|
||||
" <div class=\"quick-edit\">\r\n"+
|
||||
" <ul class=\"nav nav-pills hide\">\r\n"+
|
||||
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>\r\n"+
|
||||
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>\r\n"+
|
||||
" </ul>\r\n"+
|
||||
" </div>\r\n "
|
||||
"\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\n" +
|
||||
" <div class=\"quick-edit\">\n"+
|
||||
" <ul class=\"nav nav-pills hide\">\n"+
|
||||
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>\n"+
|
||||
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>\n"+
|
||||
" </ul>\n"+
|
||||
" </div>\n "
|
||||
elsif date_fields.include?(field_name)
|
||||
"<%= #{plugin_template}.#{field_name}.strftime('%Y/%m/%d') rescue \"\" %>"
|
||||
elsif year_month_fields.include?(field_name)
|
||||
"<%= #{plugin_template}.#{field_name}.strftime('%Y/%m') rescue \"\" %>"
|
||||
elsif date_time_fields.include?(field_name)
|
||||
"<%= #{plugin_template}.#{field_name}.strftime('%Y/%m/%d %H:%M') rescue \"\" %>"
|
||||
elsif field_name.include?(".")
|
||||
"<%= #{plugin_template}.#{field_name} rescue \"\" %>"
|
||||
elsif fields.include?(field_name) || plugin_template_related_members.include?(field_name) || field_name == "member_profile" #file or link or member
|
||||
|
@ -150,13 +254,13 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
backend_profile_fields = @personal_plugin_field.backend_fields["profile"].to_a rescue []
|
||||
backend_profile_fields_contents = backend_profile_fields.map do |field_name|
|
||||
if field_name == slug_title
|
||||
"\r\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" +
|
||||
" <div class=\"quick-edit\">\r\n"+
|
||||
" <ul class=\"nav nav-pills hide\">\r\n"+
|
||||
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>\r\n"+
|
||||
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>\r\n"+
|
||||
" </ul>\r\n"+
|
||||
" </div>\r\n "
|
||||
"\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\n" +
|
||||
" <div class=\"quick-edit\">\n"+
|
||||
" <ul class=\"nav nav-pills hide\">\n"+
|
||||
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>\n"+
|
||||
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>\n"+
|
||||
" </ul>\n"+
|
||||
" </div>\n "
|
||||
elsif field_name.include?(".")
|
||||
"<%= #{plugin_template}.#{field_name} rescue \"\" %>"
|
||||
elsif fields.include?(field_name) || plugin_template_related_members.include?(field_name) || field_name == "member_profile" #file or link or member
|
||||
|
@ -230,19 +334,24 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
"#{@blank_text}}",
|
||||
"#{@blank_text}join_text = (text_only rescue false) ? \",\" : \"<br>\"",
|
||||
"#{@blank_text}value = value.join(join_text)",
|
||||
"elsif field == \"member_profile\" && value.present?",
|
||||
"#{@blank_text}path = OrbitHelper.url_to_plugin_show(value.to_param, 'member') rescue '#'",
|
||||
"#{@blank_text}value = \"<a href='\#{path}'>\#{value.name}</a>\"",
|
||||
"elsif field == \"member_profile\" || field == \"authors\"",
|
||||
"#{@blank_text}value = get_authors_show(#{plugin_template})",
|
||||
"end",
|
||||
"strftime_hash = #{datetime_fields}",
|
||||
"if strftime_hash.keys.include?(field)",
|
||||
"#{@blank_text}value = value.strftime(strftime_hash[field]) rescue value",
|
||||
"end"
|
||||
].join("\r\n")
|
||||
display_field_code = value_case_codes + "\r\n" +
|
||||
"value = \"<a href='\#{OrbitHelper.url_to_plugin_show(#{plugin_template}.to_param,'#{@personal_plugin_field.module_name}')}' target='_blank'>\#{value}</a>\" if field == \"#{slug_title}\"\r\n" +
|
||||
].join("\n")
|
||||
enable_one_line_title = @personal_plugin_field.enable_one_line_title && @personal_plugin_field.one_line_title_format.present?
|
||||
tmp_title = enable_one_line_title ? "(title_is_paper_format ? #{plugin_template}.create_link : value)" : "value"
|
||||
display_field_code = value_case_codes + "\n" +
|
||||
"if field == \"#{slug_title}\"\n" +
|
||||
"#{@blank_text}link = OrbitHelper.url_to_plugin_show(#{plugin_template}.to_param,'#{@personal_plugin_field.module_name}')\n" +
|
||||
"#{@blank_text}tmp_title = #{tmp_title}\n"+
|
||||
"#{@blank_text}value = link == '#' ? tmp_title : \"<a href='\#{link}' target='_blank' title='\#{tmp_title}'>\#{tmp_title}</a>\"\n" +
|
||||
"end\n" +
|
||||
"value"
|
||||
value_case_codes += "\r\nvalue"
|
||||
value_case_codes += "\nvalue"
|
||||
related_backend_index_fields = @personal_plugin_field.related_modal_fields.map{|field_values|
|
||||
field_values.map{|field_value| (field_value[:field_name] rescue nil)}.select{|t| t.present?}
|
||||
}
|
||||
|
@ -298,7 +407,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
end
|
||||
period_fields = primary_modal_fields.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|f| f[:field_name]}
|
||||
time_fields = primary_modal_fields.select{|f| f[:field_type] == "time"}.map{|f| f[:field_name]}
|
||||
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\r\n")
|
||||
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\n")
|
||||
plugin_template_sort_hash = {}
|
||||
@personal_plugin_field.backend_fields[:sort_asc].to_a.each do |f|
|
||||
plugin_template_sort_hash[f.to_sym] = 1
|
||||
|
@ -309,10 +418,73 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
if @personal_plugin_field.backend_fields[:sort_desc].to_a.count != 0
|
||||
plugin_template_sort_hash[:id] = -1
|
||||
end
|
||||
all_fields_types = {
|
||||
"member_profile"=>"authors",
|
||||
"authors" => "authors"
|
||||
}
|
||||
all_fields_to_show = []
|
||||
@personal_plugin_field.primary_modal_fields.each do |f|
|
||||
field_name = f[:field_name]
|
||||
if field_name.present?
|
||||
all_fields_types[field_name] = f[:field_type]
|
||||
all_fields_to_show << field_name
|
||||
end
|
||||
end
|
||||
@personal_plugin_field.related_modal_name.each_with_index do |k,i|
|
||||
@personal_plugin_field.related_modal_fields[i].to_a.map do |f|
|
||||
field_name = f[:field_name]
|
||||
if field_name.present?
|
||||
field_name = "#{k}.#{field_name}"
|
||||
all_fields_types[field_name] = f[:field_type]
|
||||
all_fields_to_show << field_name
|
||||
end
|
||||
end
|
||||
end
|
||||
all_fields_to_show_in_index = @personal_plugin_field.get_sorted_fields(:frontend_fields, :index, all_fields_to_show)
|
||||
one_line_title_format_code = []
|
||||
scan_code = scan_word_block(@personal_plugin_field.one_line_title_format)
|
||||
one_line_title_format_code << "title = ''"
|
||||
scan_code.each do |c|
|
||||
left_space = c.match(/^[\s\'\",]+/)
|
||||
right_space = c.match(/[\s\'\",]+$/)
|
||||
variable_name = c.sub(/^[\s\'\",]+/,'').sub(/[\s\'\",]+$/, '')
|
||||
if variable_name.present?
|
||||
field_type = all_fields_types[variable_name]
|
||||
if field_type
|
||||
if_condition = "if self.#{variable_name}.present?"
|
||||
variable_contents = "self.#{variable_name}"
|
||||
if field_type == 'date' || field_type == 'year_month' || field_type == 'date_time'
|
||||
variable_contents += ".strftime('%b. %Y')"
|
||||
elsif field_type == 'year'
|
||||
variable_contents += '.to_s'
|
||||
elsif field_type == 'member'
|
||||
variable_contents = "MemberProfile.where(:id.in=>self.#{variable_name}_ids).pluck(:tmp_name).map{|h| h[I18n.locale]}.to_sentence({:locale=>:en})"
|
||||
elsif field_type == 'authors'
|
||||
variable_contents = "get_authors_text(self, true, :en)"
|
||||
if_condition += ' || self.member_profile_id.present?'
|
||||
end
|
||||
if left_space || right_space
|
||||
left_space = left_space ? left_space[0] : ''
|
||||
right_space = right_space ? right_space[0] : ''
|
||||
one_line_title_format_code << "title += \"#{left_space.gsub('"','\\"')}\#{#{variable_contents}}#{right_space.gsub('"','\\"')}\" #{if_condition}"
|
||||
else
|
||||
one_line_title_format_code << "title += #{variable_contents} #{if_condition}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
one_line_title_format_code << "title.sub(/^\\s*,/,'').gsub(/,(\\s*,)+/,',')"
|
||||
one_line_title_format_code = one_line_title_format_code.join("\n")
|
||||
col_name_to_show_short = []
|
||||
col_name_to_show_short << analysis_field_name
|
||||
col_name_to_show_short << slug_title
|
||||
@match_pattern = {"personal_plugin_template" => personal_plugin_template,
|
||||
"plugin_template" => plugin_template,
|
||||
"plugin_template_related" => plugin_template_related,
|
||||
"plugin_template_related_files_fields" => plugin_template_related_files_fields,
|
||||
"all_fields_to_show" => all_fields_to_show , #所有該模組的欄位
|
||||
"all_fields_to_show_in_index" => all_fields_to_show_in_index , #所有該模組的欄位在前台index頁面
|
||||
"col_name_to_show_short" => col_name_to_show_short.to_s, #在會員前台頁面的顯示欄位
|
||||
"col_name_to_show" => col_name_to_show.to_s, #在會員前台頁面的顯示欄位
|
||||
"col_name_to_show_in_show_page" => col_name_to_show_in_show_page.to_s, #在個人外掛前台show頁面的顯示欄位
|
||||
"col_name_to_show_in_index_page" => col_name_to_show_in_index_page.to_s, #在個人外掛前台index頁面的顯示欄位
|
||||
|
@ -351,10 +523,15 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
"plugin_template_related_members" => plugin_template_related_members.to_s,
|
||||
"periodic_methods_define" => periodic_methods_define,
|
||||
"related_periodic_methods_define" => related_periodic_methods_define,
|
||||
"period_fields_text" => period_fields.to_s
|
||||
"period_fields_text" => period_fields.to_s,
|
||||
"enable_one_line_title" => enable_one_line_title.to_s,
|
||||
"one_line_title_format_code" => one_line_title_format_code,
|
||||
"is_one_line_title" => (enable_one_line_title ? [true] : []), #used in parse_again block if condition
|
||||
"slug_title_text" => slug_title
|
||||
}
|
||||
max_length = @match_pattern.keys.map{|k| k.length}.max
|
||||
@match_pattern = @match_pattern.sort_by{|k,v| (v.class != Array) ? (max_length - k.length) : -k.length}
|
||||
@match_pattern = @match_pattern.sort_by{|k,v| -k.length}
|
||||
#sort_by{|k,v| (v.class != Array) ? (max_length - k.length) : -k.length}
|
||||
@logs = []
|
||||
replace_files(files)
|
||||
#Thread.new do
|
||||
|
@ -447,7 +624,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
input_field = "<%= f.text_field #{field_name_text}, class: \"input-block-level\", placeholder: t(\"#{placeholder}\"), value: (#{field_value_text} rescue nil) %>"
|
||||
end
|
||||
if localize
|
||||
input_field.prepend("<%= f.fields_for :#{field_name}_translations do |f| %>\r\n ").concat("\r\n<% end %>")
|
||||
input_field.prepend("<%= f.fields_for :#{field_name}_translations do |f| %>\n ").concat("\n<% end %>")
|
||||
end
|
||||
if periodic
|
||||
input_fields = []
|
||||
|
@ -510,7 +687,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
field_text
|
||||
end
|
||||
fields_text = fields_text.flatten
|
||||
fields_text.select{|t| t.present?}.join("\r\n")
|
||||
fields_text.select{|t| t.present?}.join("\n")
|
||||
end
|
||||
def replace_dirs(dirs,is_array = true)
|
||||
dirs.each_with_index do |dir,i|
|
||||
|
@ -611,55 +788,62 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
break
|
||||
end
|
||||
end
|
||||
new_text = new_text.gsub(/[ \t]*parse_again_start((?:(?!parse_again_start).)+)parse_again_end[ \t]*(\r\n|\n)/m) do |ff|
|
||||
new_text = new_text.gsub(/[ \t]*parse_again_start((?:(?!parse_again_start).)+)parse_again_end[ \t]*(\r\n|\n|$)/m) do |ff|
|
||||
@parse_again_mode = true
|
||||
parse_content = $1 #parse_again block contents
|
||||
result = ff
|
||||
match_count = parse_content.match(/^ *\* *\d+/m)
|
||||
match_count = match_count ? match_count[0] : nil
|
||||
has_exist_condition = parse_content.split("\n")[0].match(/if[ ]+\w+/).present?
|
||||
exist_condition = parse_content.split("\n")[0].match(/if[ ]+#{::Regexp.escape(k)}(?=\.| |$)/)
|
||||
extra_cond = nil
|
||||
if exist_condition
|
||||
exist_condition = exist_condition[0]
|
||||
parse_content = parse_content[ parse_content.index(exist_condition) + exist_condition.length..-1]
|
||||
extra_cond = parse_content.match(/^\.count *(\!|\<|\>|\=)(\=|) *\d+/)
|
||||
if extra_cond
|
||||
extra_cond = extra_cond[0]
|
||||
exist_condition += extra_cond
|
||||
parse_content = parse_content[extra_cond.length..-1]
|
||||
exist_condition = eval("vv"+extra_cond) ? exist_condition : nil
|
||||
elsif vv.count == 0
|
||||
exist_condition = nil
|
||||
if has_exist_condition && exist_condition.nil? #if this block is for other variables, then not proccessing
|
||||
@parse_again_mode = false
|
||||
result
|
||||
else
|
||||
extra_cond = nil
|
||||
if exist_condition
|
||||
exist_condition = exist_condition[0]
|
||||
parse_content = parse_content[ parse_content.index(exist_condition) + exist_condition.length..-1]
|
||||
extra_cond = parse_content.match(/^\.count *(\!|\<|\>|\=)(\=|) *\d+/)
|
||||
if extra_cond
|
||||
extra_cond = extra_cond[0]
|
||||
exist_condition += extra_cond
|
||||
parse_content = parse_content[extra_cond.length..-1]
|
||||
exist_condition = eval("vv"+extra_cond) ? exist_condition : nil
|
||||
elsif vv.count == 0
|
||||
exist_condition = nil
|
||||
end
|
||||
if exist_condition.nil?
|
||||
match_count = nil
|
||||
parse_content = ""
|
||||
result = ""
|
||||
end
|
||||
elsif match_count
|
||||
parse_content = parse_content[match_count.length..-1]
|
||||
end
|
||||
if exist_condition.nil?
|
||||
match_count = nil
|
||||
parse_content = ""
|
||||
result = ""
|
||||
parse_content = parse_content.sub(/[ \t]+\z/m, '').sub(/\A(\r\n|\n)/, '')
|
||||
if include_key(parse_content,k)
|
||||
vv_count = vv.count
|
||||
if match_count
|
||||
vv_count = [vv_count, match_count.strip[1..-1].to_i].min
|
||||
end
|
||||
if inner
|
||||
result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,i,ii,true) }.join("")
|
||||
else
|
||||
result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,ii) }.join("")
|
||||
end
|
||||
elsif match_count || exist_condition
|
||||
count = 1
|
||||
if match_count
|
||||
count = match_count.strip[1..-1].to_i
|
||||
end
|
||||
result = (0...count).map {|ii| parse_content }.join("")
|
||||
end
|
||||
elsif match_count
|
||||
parse_content = parse_content[match_count.length..-1]
|
||||
@parse_again_mode = false
|
||||
result
|
||||
end
|
||||
parse_content = parse_content.sub(/[ \t]+\z/m, '').sub(/\A(\r\n|\n)/, '')
|
||||
if include_key(parse_content,k)
|
||||
vv_count = vv.count
|
||||
if match_count
|
||||
vv_count = [vv_count, match_count.strip[1..-1].to_i].min
|
||||
end
|
||||
if inner
|
||||
result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,i,ii,true) }.join("")
|
||||
else
|
||||
result = (0...vv_count).map {|ii| replace_text_with_pattern(parse_content,false,ii) }.join("")
|
||||
end
|
||||
elsif match_count || exist_condition
|
||||
count = 1
|
||||
if match_count
|
||||
count = match_count.strip[1..-1].to_i
|
||||
end
|
||||
result = (0...count).map {|ii| parse_content }.join("")
|
||||
end
|
||||
@parse_again_mode = false
|
||||
result
|
||||
end
|
||||
new_text = gsub_text_by_key_value(new_text,k,vv.to_s)
|
||||
end
|
||||
end
|
||||
return new_text
|
||||
|
@ -672,6 +856,12 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
if !@parse_again_mode
|
||||
text.gsub(/\n(\s+)[^\n]*(#{k}|#{k.classify})/m) {|ff| @blank_texts << $1.gsub(/(\r\n|\n)/,'')}
|
||||
end
|
||||
if k == 'display_field_code'
|
||||
puts nil
|
||||
puts "display_field_code: @parse_again_mode: #{@parse_again_mode}"
|
||||
print @blank_texts
|
||||
puts nil
|
||||
end
|
||||
i = 0
|
||||
text = text.gsub(k + "s"){|ff| v.pluralize.gsub("\n","\n#{@blank_texts[i]}")}
|
||||
text = text.gsub(k ){|ff| v.gsub("\n","\n#{@blank_texts[i]}")}
|
||||
|
@ -698,7 +888,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
if txt_scan.count != 1
|
||||
delete_plugin(extention_file,plugin_name)
|
||||
txt = File.read(extention_file) rescue ""
|
||||
txt = txt + "\r\ngem \"#{plugin_name}\", path: \"#{Rails.root}/tmp/#{plugin_name}\"\n"
|
||||
txt = txt + "\ngem \"#{plugin_name}\", path: \"#{Rails.root}/tmp/#{plugin_name}\"\n"
|
||||
File.open(extention_file,'w+') do |f|
|
||||
f.write(txt)
|
||||
end
|
||||
|
@ -707,7 +897,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
def delete_plugin(extention_file,plugin_name)
|
||||
txt = File.read(extention_file) rescue nil
|
||||
return if txt.nil?
|
||||
txt_change = txt.gsub(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/,'')
|
||||
txt_change = txt.gsub(/^[\s#]*gem\s*["']#{plugin_name}["'].*(\n|$)/m,'')
|
||||
if txt_change != txt
|
||||
File.open(extention_file,'w+') do |f|
|
||||
f.write(txt_change)
|
||||
|
@ -744,12 +934,12 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
|
|||
personal_plugin_field_params[:related_modal_name] = []
|
||||
end
|
||||
if personal_plugin_field_params[:primary_modal_fields]
|
||||
personal_plugin_field_params[:primary_modal_fields] = personal_plugin_field_params[:primary_modal_fields].values
|
||||
personal_plugin_field_params[:primary_modal_fields] = personal_plugin_field_params[:primary_modal_fields].sort_by{|k, h| h[:order].to_i}.map{|v| v[1]}
|
||||
else
|
||||
personal_plugin_field_params[:primary_modal_fields] = []
|
||||
end
|
||||
if personal_plugin_field_params[:related_modal_fields]
|
||||
personal_plugin_field_params[:related_modal_fields] = personal_plugin_field_params[:related_modal_fields].values.map{|h| h.values}
|
||||
personal_plugin_field_params[:related_modal_fields] = personal_plugin_field_params[:related_modal_fields].values.map{|h| h.sort_by{|k, h| h[:order].to_i}.map{|v| v[1]}}
|
||||
else
|
||||
personal_plugin_field_params[:related_modal_fields] = []
|
||||
end
|
||||
|
|
|
@ -3,6 +3,8 @@ class PersonalPluginField
|
|||
include Mongoid::Timestamps
|
||||
include OrbitModel::Status
|
||||
include MemberHelper
|
||||
field :one_line_title_format, :type => String, :default => ""
|
||||
field :enable_one_line_title, :type => Boolean, :default => false
|
||||
field :author_name, :type => String, :default => "",:localize => true
|
||||
field :title, :type => String, :default => "",:localize => true
|
||||
field :module_name, :type => String, :default => ""
|
||||
|
@ -81,6 +83,47 @@ class PersonalPluginField
|
|||
return false
|
||||
end
|
||||
end
|
||||
def get_sorted_fields(root_name, page_name, tds=nil)
|
||||
if self.fields_order.present?
|
||||
fields_order = (0...tds.count).to_a
|
||||
if (self.fields_order["#{root_name}_#{page_name}"].present? rescue false)
|
||||
self.fields_order["#{root_name}_#{page_name}"].to_a.each_with_index do |order,i|
|
||||
fields_order[i] = order.to_i
|
||||
end
|
||||
end
|
||||
if tds.respond_to?(:values)
|
||||
tds = tds.values
|
||||
end
|
||||
tds = tds.sort_by.with_index{|td,i| fields_order[i]}
|
||||
else
|
||||
field_values = self[root_name][page_name] rescue []
|
||||
if field_values.present?
|
||||
if tds.respond_to?(:values)
|
||||
new_tds = {}
|
||||
field_values.each do |field_value|
|
||||
new_tds[field_value] = tds[field_value] if tds[field_value]
|
||||
end
|
||||
tds.each do |k,v|
|
||||
if new_tds[k].nil?
|
||||
new_tds[k] = v
|
||||
end
|
||||
end
|
||||
tds = new_tds.values
|
||||
else
|
||||
new_tds = field_values.clone
|
||||
tds.each do |v|
|
||||
new_tds << v unless new_tds.include?(v)
|
||||
end
|
||||
tds = new_tds
|
||||
end
|
||||
else
|
||||
if tds.respond_to?(:values)
|
||||
tds = tds.values
|
||||
end
|
||||
end
|
||||
end
|
||||
tds
|
||||
end
|
||||
def auto_add_display_fields
|
||||
change_primary_fields = self.primary_modal_fields.map{|f| f["field_name"]} - self.primary_modal_fields_was.to_a.map{|f| f["field_name"]}
|
||||
change_related_fields = []
|
||||
|
|
|
@ -4,10 +4,15 @@
|
|||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<%= stylesheet_link_tag "lib/main-form-col2" %>
|
||||
<%= stylesheet_link_tag "lib/togglebox"%>
|
||||
<style type="text/css">
|
||||
.ui-helper-hidden-accessible{
|
||||
display: none;
|
||||
}
|
||||
label[for="enable_one_line_title"] .toggle-control{
|
||||
float: left;
|
||||
margin-right: 0.2em;
|
||||
}
|
||||
</style>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
|
@ -102,7 +107,14 @@
|
|||
<button type="button" class="btn btn-primary" id="add_related_modal"><%= t(:add) %></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%=thead_field("one_line_title_format")%></label>
|
||||
<div class="controls">
|
||||
<label for="enable_one_line_title"><%= f.check_box :enable_one_line_title, :checked => (f.object.enable_one_line_title), :class=>"toggle-check", :id=>"enable_one_line_title", :data=> { disabled: true } %><span style="float: left;"><%=thead_field("enable")%></span></label>
|
||||
<div style="clear: both;"></div>
|
||||
<%= f.text_field :one_line_title_format, (f.object.enable_one_line_title ? {} : {:disabled=>'disabled',:id=>'one_line_title_format'}) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status Module -->
|
||||
|
@ -151,7 +163,15 @@
|
|||
<%= link_to t('cancel'), request.referer, :class=>"btn" %>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#enable_one_line_title').change(function(){
|
||||
if($(this).val() == '1'){
|
||||
$('#one_line_title_format').removeAttr('disabled');
|
||||
}else{
|
||||
$('#one_line_title_format').attr('disabled', 'disabled');
|
||||
}
|
||||
})
|
||||
})
|
||||
$(document).on('click', '.delete_file', function(){
|
||||
$(this).parents('.input-prepend').remove();
|
||||
});
|
||||
|
@ -268,12 +288,12 @@
|
|||
})
|
||||
return can_install;
|
||||
}
|
||||
$('tr >:last-child').css( 'border', '2px solid red');
|
||||
$('.main-forms tr').find('th:eq(-2),td:eq(-2)').css( 'border', '2px solid red');
|
||||
return false;
|
||||
})
|
||||
$('.slug_title').click(function(){
|
||||
if($('.slug_title:checked').length == 1){
|
||||
$('tr >:last-child').css( 'border','');
|
||||
$('.main-forms tr').find('th:eq(-2),td:eq(-2)').css( 'border','');
|
||||
}
|
||||
})
|
||||
$(document).on('blur', 'input.related_modal_name', function(){
|
||||
|
|
|
@ -7,35 +7,40 @@
|
|||
<table class="table table-bordered" id="<%="#{root_name}_#{page_name}"%>">
|
||||
<tbody>
|
||||
<tr>
|
||||
<% tds = [] %>
|
||||
<% tds = {} %>
|
||||
<% ii = -1 %>
|
||||
<% tmp_fields_order = {} %>
|
||||
<% object.primary_modal_fields.each do |field_value| %>
|
||||
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
|
||||
<% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
|
||||
<% tds << "<td data-index=\"#{ii+=1}\">#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}</td>" %>
|
||||
<% field_name = field_value[:field_name] %>
|
||||
<% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", field_name , (object.send(root_name)[page_name].include?(field_name) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
|
||||
<% ii+=1 %>
|
||||
<% tmp_fields_order = "<input class=\"fields_order_hidden_input\" type=\"hidden\" name=\"#{f.object_name}[fields_order][#{root_name}_#{page_name}][#{ii}]\" value=\"${sort_order}\">" %>
|
||||
<% tds[field_name] = "<td data-index=\"#{ii}\">#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}#{tmp_fields_order}</td>" %>
|
||||
<% end %>
|
||||
<% if !defined?(access_field_types) %>
|
||||
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
|
||||
<% field_values = f.object.related_modal_fields[i].to_a %>
|
||||
<% field_values.each do |field_value| %>
|
||||
<% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
|
||||
<% tds << "<td data-index=\"#{ii+=1}\">#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}</td>" %>
|
||||
<% field_name = related_modal_name+'.'+field_value[:field_name] %>
|
||||
<% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", field_name , (object.send(root_name)[page_name].include?(field_name) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
|
||||
<% ii+=1 %>
|
||||
<% tmp_fields_order = "<input class=\"fields_order_hidden_input\" type=\"hidden\" name=\"#{f.object_name}[fields_order][#{root_name}_#{page_name}][#{ii}]\" value=\"${sort_order}\">" %>
|
||||
<% tds[field_name] = "<td data-index=\"#{ii}\">#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}#{tmp_fields_order}</td>" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% author_name_translation = @personal_plugin_field.author_name_translations[locale] rescue ""
|
||||
author_name_translation = I18n.t("personal_plugins.author") if author_name_translation.blank? %>
|
||||
<% content = check_box_tag("#{f.object_name}[#{root_name}][#{page_name}][]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil) %>
|
||||
<% tds << "<td data-index=\"#{ii+=1}\">#{author_name_translation}<hr class=\"border-hr\">#{content}</td>" %>
|
||||
<% ii+=1 %>
|
||||
<% tmp_fields_order = "<input class=\"fields_order_hidden_input\" type=\"hidden\" name=\"#{f.object_name}[fields_order][#{root_name}_#{page_name}][#{ii}]\" value=\"${sort_order}\">" %>
|
||||
<% tds["member_profile"] = "<td data-index=\"#{ii}\">#{author_name_translation}<hr class=\"border-hr\">#{content}#{tmp_fields_order}</td>" %>
|
||||
<% end %>
|
||||
<% fields_order = (0...tds.count).to_a
|
||||
if (object.fields_order["#{root_name}_#{page_name}"].present? rescue false)
|
||||
object.fields_order["#{root_name}_#{page_name}"].to_a.each_with_index do |order,i|
|
||||
fields_order[i] = order.to_i
|
||||
end
|
||||
end
|
||||
<%
|
||||
tds = object.get_sorted_fields(root_name, page_name, tds)
|
||||
%>
|
||||
<% tds = tds.sort_by.with_index{|td,i| fields_order[i]}%>
|
||||
<% tds.each do |td| %>
|
||||
<% tds.each_with_index do |td, i| %>
|
||||
<% td = td.sub('${sort_order}', i.to_s) %>
|
||||
<%= td.html_safe %>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<table class="table table-bordered">
|
||||
<table class="table table-bordered sortable_table">
|
||||
<thead>
|
||||
<th></th>
|
||||
<th><%= t(:remove) %></th>
|
||||
<th><%= thead_field("field_name") %></th>
|
||||
<th><%= thead_field("translation_name") %></th>
|
||||
|
@ -12,7 +13,11 @@
|
|||
<%= f.fields_for root_name do |f| %>
|
||||
<% field_values.each_with_index do |field_value,i| %>
|
||||
<% i = "new_field_index" if field_value.nil? && !@include_blank %>
|
||||
<tr>
|
||||
<tr index="<%=i%>">
|
||||
<td>
|
||||
<span class="brand ui-sortable-handle"><i class="icons-list-2"></i></span>
|
||||
<input class="hidden_order" type="hidden" name="<%= "#{f.object_name}[#{i}][order]" %>" value="<%= i %>">
|
||||
</td>
|
||||
<td><span class="remove_btn">X</span></td>
|
||||
<td><%= text_field_tag "#{f.object_name}[#{i}][field_name]",(field_value["field_name"] rescue nil) %></td>
|
||||
<td>
|
||||
|
@ -41,4 +46,34 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</table>
|
||||
<style type="text/css">
|
||||
.icons-list-2{
|
||||
cursor: all-scroll;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('.sortable_table').each(function(i,v){
|
||||
if(!($(v).hasClass('already_init_sortable'))){
|
||||
$(v).find('tbody').sortable({
|
||||
axis: "y",
|
||||
revert: true,
|
||||
handle: ".brand",
|
||||
update: function(event, ui) {
|
||||
var item = ui.item;
|
||||
var new_index = item.index();
|
||||
var old_index = item.attr("index");
|
||||
var indices = [new_index,old_index].sort();
|
||||
for(var new_i=indices[0];new_i<=indices[1];new_i++){
|
||||
var td = item.parent().find(">").eq(new_i);
|
||||
td.attr("index",new_i);
|
||||
td.find('.hidden_order').val(new_i);
|
||||
}
|
||||
}
|
||||
});
|
||||
$(v).addClass('already_init_sortable')
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -17,6 +17,7 @@
|
|||
<%= javascript_include_tag "lib/file-type" %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<% end %>
|
||||
<h3 style="padding: 20px 20px 0;"><%= @personal_plugin_field.title %></h3>
|
||||
<%= form_for @personal_plugin_field, url: admin_personal_plugin_field_update_fields_setting_path(@personal_plugin_field), html: {class: "form-horizontal main-forms previewable"} do |f| %>
|
||||
<fieldset>
|
||||
|
||||
|
@ -100,19 +101,11 @@
|
|||
var old_index = ui.item.attr("index");
|
||||
var indices = [new_index,old_index].sort();
|
||||
for(var new_i=indices[0];new_i<=indices[1];new_i++){
|
||||
var old_i = ui.item.parent().find(">").eq(new_i).attr("index");
|
||||
var org_i = ui.item.parent().find(">").eq(new_i).data("index");
|
||||
ui.item.parent().find(">").eq(new_i).attr("index",new_i);
|
||||
ui.item.parent().parent().siblings("tbody").find("tr:eq(1) >").eq(org_i).val(new_i);
|
||||
}
|
||||
var tds = ui.item.parent().parent().siblings("tbody").find("tr:eq(0) >");
|
||||
if(tds.length){
|
||||
if(new_index > old_index){ //向後移動
|
||||
tds.eq(new_index).after(tds.eq(old_index))
|
||||
}
|
||||
else if(new_index < old_index){ //向前移動
|
||||
tds.eq(new_index).before(tds.eq(old_index))
|
||||
}
|
||||
var td = ui.item.parent().find(">").eq(new_i);
|
||||
var old_i =td.attr("index");
|
||||
var org_i = td.data("index");
|
||||
td.attr("index",new_i);
|
||||
td.find('.fields_order_hidden_input').val(new_i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,6 +4,8 @@ en:
|
|||
restful_actions:
|
||||
fields_setting: Fields Setting
|
||||
personal_plugin_generator:
|
||||
enable: Enable
|
||||
one_line_title_format: "Paper Format Title"
|
||||
download: Download
|
||||
author_translation_name: Author translation name
|
||||
personal_plugin_generator: Personal Plugin Generate
|
||||
|
|
|
@ -4,6 +4,8 @@ zh_tw:
|
|||
restful_actions:
|
||||
fields_setting: 欄位設定
|
||||
personal_plugin_generator:
|
||||
enable: 啟用
|
||||
one_line_title_format: "論文格式標題"
|
||||
download: 下載
|
||||
author_translation_name: 著作人翻譯名稱
|
||||
personal_plugin_generator: 個人外掛生成
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
$:.push File.expand_path("../lib", __FILE__)
|
||||
|
||||
# Maintain your gem's version:
|
||||
require "rails"
|
||||
# require "rails"
|
||||
require "personal_plugin_generator/version"
|
||||
require "personal_plugin_generator/engine"
|
||||
PersonalPluginGenerator.git_reset('origin','update')
|
||||
# require "personal_plugin_generator/engine"
|
||||
# PersonalPluginGenerator.git_reset('origin','update')
|
||||
# Describe your gem and declare its dependencies:
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "personal_plugin_generator"
|
||||
|
|
|
@ -1,26 +1,46 @@
|
|||
class PersonalPluginTemplatesController < ApplicationController
|
||||
include Admin::PluginTemplatesHelper
|
||||
def index
|
||||
params = OrbitHelper.params
|
||||
plugin_templates = PluginTemplate.sort_for_frontend
|
||||
fields_to_show = col_name_to_show_in_index_page
|
||||
page = OrbitHelper.page rescue Page.where(page_id: params[:page_id]).first
|
||||
parse_again_start * 1 if is_one_line_title.count > 0
|
||||
title_is_paper_format = true
|
||||
if page.custom_string_field == 'table'
|
||||
title_is_paper_format = false
|
||||
fields_to_show = page.custom_array_field rescue []
|
||||
if fields_to_show.blank?
|
||||
fields_to_show = col_name_to_show_in_index_page
|
||||
end
|
||||
else
|
||||
fields_to_show = col_name_to_show_short
|
||||
end
|
||||
parse_again_end
|
||||
parse_again_start * 1 if is_one_line_title.count == 0
|
||||
title_is_paper_format = false
|
||||
fields_to_show = page.custom_array_field rescue []
|
||||
if fields_to_show.blank?
|
||||
fields_to_show = col_name_to_show_in_index_page
|
||||
end
|
||||
parse_again_end
|
||||
if params[:keywords].present?
|
||||
plugin_templates = filter_keywords(plugin_templates,params[:selectbox],params[:keywords])
|
||||
end
|
||||
plugin_templates = plugin_templates.page(params[:page_no]).per(OrbitHelper.page_data_count)
|
||||
plugin_templates_list = plugin_templates.collect do |plugin_template|
|
||||
member = plugin_template.member_profile
|
||||
|
||||
fields_hash = fields_to_show.map{|field| [field, get_display_field(plugin_template,field)]}.to_h
|
||||
|
||||
path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#'
|
||||
fields_hash["authors"] = "<a href='#{path}'>#{member.name}</a>" rescue ""
|
||||
fields_hash["link_to_show"] = OrbitHelper.url_to_show(plugin_template.to_param)
|
||||
fields_hash
|
||||
{'jps' => fields_to_show.map{|field| {"value"=> get_display_field(plugin_template,field, title_is_paper_format)}}}
|
||||
end
|
||||
|
||||
extras = extra_translate_title
|
||||
choice_show = []
|
||||
headers = []
|
||||
fields_to_show.each do |fs|
|
||||
col = 2
|
||||
col = 3 if fs == 'slug_title_text'
|
||||
headers << {
|
||||
'head-title' => t("personal_plugin_template.#{fs}"),
|
||||
'col' => col
|
||||
}
|
||||
choice_show << t("personal_plugin_template.#{fs}")
|
||||
end
|
||||
choice_value = fields_to_show
|
||||
|
@ -44,6 +64,7 @@ class PersonalPluginTemplatesController < ApplicationController
|
|||
extras["widget-title"] = I18n.t("module_name.personal_plugin_template")
|
||||
{
|
||||
"plugin_templates" => plugin_templates_list,
|
||||
"headers" => headers,
|
||||
"extras" => extras,
|
||||
"total_pages" => plugin_templates.total_pages,
|
||||
'choice' => choice
|
||||
|
@ -57,10 +78,29 @@ class PersonalPluginTemplatesController < ApplicationController
|
|||
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
||||
end
|
||||
|
||||
def get_display_field(plugin_template,field)
|
||||
def get_display_field(plugin_template,field, title_is_paper_format=false)
|
||||
text_only = false
|
||||
display_field_code
|
||||
return value
|
||||
end
|
||||
def get_fields_for_index
|
||||
@page = Page.find(params[:page_id]) rescue nil
|
||||
@fields_to_show = all_fields_to_show_in_index
|
||||
@fields_to_show = @fields_to_show.map { |fs| [t("personal_plugin_template.#{fs}"), fs] }
|
||||
if @page.present? && @page.custom_string_field == 'table'
|
||||
@default_fields_to_show = col_name_to_show_in_index_page
|
||||
else
|
||||
@default_fields_to_show = col_name_to_show_short
|
||||
end
|
||||
render layout: false
|
||||
end
|
||||
|
||||
def save_index_fields
|
||||
page = Page.find(params[:page_id]) rescue nil
|
||||
page.custom_array_field = params[:keys]
|
||||
page.save
|
||||
render json: { 'success' => true }.to_json
|
||||
end
|
||||
def filter_keywords(plugin_templates,select_field,keywords)
|
||||
member_fields = plugin_template_related_members
|
||||
file_fields = plugin_template_related_files_text
|
||||
|
|
|
@ -2,6 +2,47 @@ module Admin::PluginTemplatesHelper
|
|||
include OrbitBackendHelper
|
||||
include OrbitFormHelper
|
||||
alias :org_datetime_picker :datetime_picker
|
||||
def get_authors_text(plugin_template, is_to_sentence=false, locale=nil)
|
||||
authors_text = Nokogiri::HTML(plugin_template.authors.to_s).text
|
||||
split_text = authors_text.match(/[、,,\/]/)
|
||||
split_text = split_text.nil? ? '/' : split_text[0]
|
||||
full_authors_names = get_member(plugin_template).collect(&:name)
|
||||
if authors_text.present?
|
||||
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))}
|
||||
full_authors_names += authors_names
|
||||
end
|
||||
if is_to_sentence
|
||||
full_authors_names.to_sentence({:locale=>locale})
|
||||
else
|
||||
full_authors_names.join(split_text)
|
||||
end
|
||||
end
|
||||
def get_authors_show(plugin_template, is_to_sentence=false, locale=nil)
|
||||
authors_text = Nokogiri::HTML(plugin_template.authors.to_s).text
|
||||
split_text = authors_text.match(/[、,,\/]/)
|
||||
split_text = split_text.nil? ? '/' : split_text[0]
|
||||
full_authors_names = []
|
||||
full_authors = get_member(plugin_template).collect do |member|
|
||||
member_name = member.name
|
||||
full_authors_names << member_name
|
||||
"<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member_name}'>#{member_name}</a>"
|
||||
end
|
||||
if authors_text.present?
|
||||
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))}
|
||||
full_authors += authors_names
|
||||
end
|
||||
if is_to_sentence
|
||||
full_authors.to_sentence({:locale=>locale})
|
||||
else
|
||||
full_authors.join(split_text)
|
||||
end
|
||||
end
|
||||
def get_member(plugin_template)
|
||||
Array(MemberProfile.where(:id.in=>Array(plugin_template).collect(&:member_profile_id).flatten))
|
||||
end
|
||||
def get_member_show(plugin_template)
|
||||
get_member(plugin_template).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/')
|
||||
end
|
||||
def datetime_picker(*arg,**args)
|
||||
org_datetime_picker(arg,args)
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class PluginTemplate
|
|||
include Mongoid::Timestamps
|
||||
include OrbitModel::Status
|
||||
include MemberHelper
|
||||
include Admin::PluginTemplatesHelper
|
||||
include Slug
|
||||
|
||||
col_fields
|
||||
|
@ -31,9 +32,34 @@ class PluginTemplate
|
|||
def parse_time(time_str)
|
||||
DateTime.parse("0000-01-01 " + time_str)
|
||||
end
|
||||
parse_again_start * 1 if is_one_line_title.count > 0
|
||||
def create_link
|
||||
one_line_title_format_code
|
||||
end
|
||||
parse_again_end
|
||||
def self.get_plugin_datas_to_member(datas)
|
||||
|
||||
fields_to_show = col_name_to_show
|
||||
page = Page.where(:module => "personal_plugin_template").first rescue nil
|
||||
parse_again_start * 1 if is_one_line_title.count > 0
|
||||
title_is_paper_format = true
|
||||
if !page.nil? && page.custom_string_field == "table"
|
||||
title_is_paper_format = false
|
||||
if !page.custom_array_field.blank?
|
||||
fields_to_show = page.custom_array_field
|
||||
else
|
||||
fields_to_show = col_name_to_show
|
||||
end
|
||||
else
|
||||
fields_to_show = col_name_to_show_short
|
||||
end
|
||||
parse_again_end
|
||||
parse_again_start * 1 if is_one_line_title.count == 0
|
||||
title_is_paper_format = false
|
||||
if !page.nil? && !page.custom_array_field.blank?
|
||||
fields_to_show = page.custom_array_field
|
||||
else
|
||||
fields_to_show = col_name_to_show
|
||||
end
|
||||
parse_again_end
|
||||
|
||||
fields_to_remove = []
|
||||
|
||||
|
@ -60,7 +86,7 @@ class PluginTemplate
|
|||
|
||||
pd_data = []
|
||||
fields_to_show.collect do |t|
|
||||
pd_data << { "data_title" => p.display_field(t) }
|
||||
pd_data << { "data_title" => p.display_field(t, false, title_is_paper_format) }
|
||||
end
|
||||
parse_again_start * 1 if plugin_template_related.count > 0
|
||||
{
|
||||
|
@ -106,7 +132,7 @@ class PluginTemplate
|
|||
}
|
||||
end
|
||||
|
||||
def display_field(field,text_only=false)
|
||||
def display_field(field,text_only=false,title_is_paper_format=false)
|
||||
plugin_template = self
|
||||
display_field_code
|
||||
end
|
||||
|
|
|
@ -159,7 +159,7 @@
|
|||
<label class="control-label muted"><%= t("personal_plugin_template.member_profile") %></label>
|
||||
<div class="controls">
|
||||
<% members = !@plugin_template.member_profile.nil? ? @plugin_template.member_profile.to_a : [] %>
|
||||
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'plugin_template[member_profile_id]', email_members: members,index:'0',select_name:'member_profile_id'} %>
|
||||
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'plugin_template[member_profile_id][]', email_members: members,index:'0',select_name:'member_profile_id'} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div class="bottomnav clearfix">
|
||||
<div class="action pull-right">
|
||||
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_plugin_template_path, :class => 'btn btn-primary' %>
|
||||
parse_again_start * 1 if plugin_template_related.count == 0
|
||||
parse_again_start * 1 if plugin_template_related
|
||||
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_plugin_template_setting_path, :class => 'btn btn-primary pull-right' %>
|
||||
parse_again_end
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<% if !@page.nil? %>
|
||||
<form id="form_for_plugin_fields" action="">
|
||||
<div class="form-inline">
|
||||
<ul class="current-fields">
|
||||
<% if @page.custom_array_field.blank? %>
|
||||
<% @default_fields_to_show.each do |fs| %>
|
||||
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("personal_plugin_template.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% @page.custom_array_field.each do |fs| %>
|
||||
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("personal_plugin_template.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="form-horizontal controls-row">
|
||||
|
||||
<div class="attr-type-wrap control-group">
|
||||
<label class="attr control-label">Fields: </label>
|
||||
<div class="attr controls">
|
||||
<%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %>
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="add-pp-field btn btn-info">Add Field</a>
|
||||
<input type="hidden" name="plugin_key" value="<%= @page.module %>">
|
||||
<input type="hidden" name="plugin_page_frontend_id" value="<%= @page.id.to_s %>">
|
||||
</div>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
$(".current-fields").sortable();
|
||||
var select = $("select#fields_to_show_for_pp");
|
||||
$(".add-pp-field").on("click",function(){
|
||||
var val = select.val(),
|
||||
text = select.find("option:selected").text(),
|
||||
li = null;
|
||||
if(val != ""){
|
||||
li = '<li class="clearfix" data-attrib-key="' + val + '"><span class="field-value">' + text + '</span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>';
|
||||
}
|
||||
$("#modify_plugin_fields ul.current-fields").append(li);
|
||||
})
|
||||
$(document).on("click",".remove-field",function(){
|
||||
$(this).parent().remove();
|
||||
})
|
||||
</script>
|
||||
<% else %>
|
||||
<h3>Page not found.</h3>
|
||||
<% end %>
|
|
@ -28,5 +28,7 @@ Rails.application.routes.draw do
|
|||
resources :plugin_template_relateds
|
||||
parse_again_end
|
||||
end
|
||||
get "/xhr/personal_plugin_template/get_fields_for_index" => "personal_plugin_templates#get_fields_for_index"
|
||||
post "/xhr/personal_plugin_template/save_index_fields" => "personal_plugin_templates#save_index_fields"
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module PersonalPluginTemplate
|
|||
OrbitApp.registration "PersonalPluginTemplate",:type=> 'ModuleApp' do
|
||||
module_label 'module_name.plugin_templates'
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
personal_plugin :enable => true, :sort_number => '35', :app_name=>"PluginTemplate", :intro_app_name=>"PluginTemplateIntro",:path=>"/plugin/personal_plugin_template/profile",:front_path=>"/profile",:admin_path=>"/admin/plugin_templates/",:i18n=>'module_name.plugin_templates', :module_app_name=>'PluginTemplate', :analysis => true, :analysis_path => "/admin/plugin_templates/analysis"
|
||||
personal_plugin :enable => true, :sort_number => '35', :app_name=>"PluginTemplate", :intro_app_name=>"PluginTemplateIntro",:path=>"/plugin/personal_plugin_template/profile",:front_path=>"/profile",:admin_path=>"/admin/plugin_templates/",:i18n=>'module_name.plugin_templates', :module_app_name=>'PluginTemplate', :one_line_title => enable_one_line_title, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/plugin_templates/analysis"
|
||||
|
||||
version "0.1"
|
||||
desktop_enabled true
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
<table class="table table-hover table-striped projects-index plugin_templates-index dt-responsive nowrap">
|
||||
<caption><h3>{{widget-title}}</h3></caption>
|
||||
<thead>
|
||||
<tr>
|
||||
parse_again_start
|
||||
<th class="col-md-1">{{th-col_name_to_show_in_index_page_arr}}</th>
|
||||
parse_again_end
|
||||
<tr data-level="0" data-list="headers">
|
||||
<th class="col-md-{{col}}">{{head-title}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody data-level="0" data-list="plugin_templates">
|
||||
<tr>
|
||||
parse_again_start
|
||||
<td>{{col_name_to_show_in_index_page_arr}}</td>
|
||||
parse_again_end
|
||||
<tr data-level="1" data-list="jps">
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -26,17 +26,13 @@ $( ".selectbox" ).ready(function() {
|
|||
<table class="table table-hover table-striped plugin_templates-index dt-responsive nowrap">
|
||||
<caption><h3>{{widget-title}}</h3></caption>
|
||||
<thead>
|
||||
<tr>
|
||||
parse_again_start
|
||||
<th class="col-md-1">{{th-col_name_to_show_in_index_page_arr}}</th>
|
||||
parse_again_end
|
||||
<tr data-level="0" data-list="headers">
|
||||
<th class="col-md-{{col}}">{{head-title}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody data-level="0" data-list="plugin_templates">
|
||||
<tr>
|
||||
parse_again_start
|
||||
<td>{{col_name_to_show_in_index_page_arr}}</td>
|
||||
parse_again_end
|
||||
<tr data-level="1" data-list="jps">
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue