Fix bugs.

This commit is contained in:
BoHung Chiu 2021-03-01 23:44:52 +08:00
parent 231ac9c79f
commit fea246f017
21 changed files with 325 additions and 152 deletions

View File

@ -70,14 +70,18 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
if related_modal_name.present? && sub_hash.present?
translate_hash[related_modal_name] = sub_hash
end
#sub_hash["modal_name"] = "關聯欄位翻譯"
end
author_name_translation = @personal_plugin_field.author_name_translations[locale] rescue ""
I18n.with_locale(locale) do
author_name_translation = I18n.t("personal_plugins.author") if author_name_translation.blank?
end
translate_hash["author_name_translation"] = author_name_translation
col_name_translate_yaml = ""
if translate_hash.present?
col_name_translate_yaml = translate_hash.to_yaml.gsub("---\n", '')
end
blank_text = yml_text.split(/(\r\n|\n)/).select{|t| t.include?"col_name_translate_yaml"}.first.split('col_name_translate_yaml').first rescue ""
col_name_translate_yaml = col_name_translate_yaml.gsub("\n","\n#{blank_text}")
yml_text = yml_text.gsub("col_name_translate_yaml",col_name_translate_yaml)
yml_text = gsub_text_by_key_value(yml_text,"col_name_translate_yaml",col_name_translate_yaml)
yml_text = yml_text.gsub("personal_plugin_template_translate",@personal_plugin_field.title_translations[locale])
File.open(yml_file,'w+') do |f|
f.write(yml_text)
@ -89,19 +93,21 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
plugin_template_related_files_text = plugin_template_related_files.to_s
plugin_template_related_files_fields = plugin_template_related_files.map{|field_name|
"has_many :#{field_name.pluralize}, :dependent => :destroy, :autosave => true\r\n" +
"#{@blank_text}accepts_nested_attributes_for :#{field_name.pluralize}, :allow_destroy => true"
}.join("\r\n#{@blank_text}")
"accepts_nested_attributes_for :#{field_name.pluralize}, :allow_destroy => true"
}.join("\r\n")
plugin_template = @personal_plugin_field.primary_modal_name
backend_index_fields = @personal_plugin_field.backend_fields["index"] rescue []
backend_index_fields_contents = backend_index_fields.map do |field_name|
if field_name == slug_title
"<%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" +
"<div class=\"quick-edit\">
<ul class=\"nav nav-pills hide\">
<li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>
<li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>
</ul>
</div>\r\n "
"<div class=\"quick-edit\">"+
" <ul class=\"nav nav-pills hide\">"+
" <li><%= link_to t('edit'), edit_admin_#{plugin_template}_path(#{plugin_template},:page => params[:page]) %></li>"+
" <li><%= link_to t(:delete_), admin_#{plugin_template}_path(id: #{plugin_template}.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>"+
"</ul>"+
"</div>\r\n"
elsif field_name.include?(".")
"<%= #{plugin_template}.#{field_name} rescue \"\" %>"
else
"<%= #{plugin_template}.#{field_name} %>"
end
@ -110,31 +116,73 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
col_name_to_show_in_show_page = @personal_plugin_field.frontend_fields["show"] rescue []
col_name_to_show_in_index_page = @personal_plugin_field.frontend_fields["index"] rescue []
extra_translate_title = col_name_to_show_in_index_page.map{|field_name| #在個人外掛前台index頁面的欄位翻譯名稱hash
["th-#{field_name}","I18n.locale(\"#{@personal_plugin_field.module_name}.#{field_name}\")"]
["th-#{field_name}","I18n.t(\"#{@personal_plugin_field.module_name}.#{field_name}\")"]
}
col_fields = get_fields_text(@personal_plugin_field.primary_modal_fields)
col_related_fields = @personal_plugin_field.related_modal_fields.map{|field_values| get_fields_text(field_values)}
locale_fields = []
none_locale_fields = []
locale_fields_input_fields = []
none_locale_fields_input_fields = []
plugin_template_related = @personal_plugin_field.related_modal_name.select{|n| n.present?}
plugin_template_related_main_field = @personal_plugin_field.related_modal_fields.map{|field_values| field_values.map{|field_value| field_value[:field_name]}.select{|t| t.present?}.first }
@personal_plugin_field.primary_modal_fields.each do |field_value|
field_name = field_value[:field_name]
field_type = field_value[:field_type]
next if field_name.blank?
next if field_type == "file"
if (field_value[:localize] == "1" rescue false)
locale_fields << field_name
input_field = generate_input_field(field_type,field_name,true)
locale_fields_input_fields << input_field
else
none_locale_fields << field_name
input_field = generate_input_field(field_type,field_name)
none_locale_fields_input_fields << input_field
plugin_template_related_main_field = @personal_plugin_field.related_modal_fields.map{|field_values|
slug_titles = field_values.select{|field_value| (field_value[:slug_title] == "1" rescue false)}
if slug_titles.count == 0
slug_titles = field_values
end
slug_titles.map{|field_value| field_value[:field_name]}.select{|t| t.present?}.first
}
locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields = get_input_fields(@personal_plugin_field.primary_modal_fields)
related_locale_fields = []
related_none_locale_fields = []
related_locale_fields_input_fields = []
related_none_locale_fields_input_fields = []
@personal_plugin_field.related_modal_fields.each_with_index do |field_values,i|
related_modal_name = @personal_plugin_field.related_modal_name[i]
f1 , f2 , f3 , f4 = get_input_fields(field_values,related_modal_name,related_modal_name)
related_locale_fields << f1
related_none_locale_fields << f2
related_locale_fields_input_fields << f3
related_none_locale_fields_input_fields << f4
end
backend_profile_fields = backend_index_fields
backend_profile_fields_contents = backend_index_fields_contents
datetime_field_types_hash = {"year_month"=>"%Y/%m","date"=>"%Y/%m/%d","time"=>"%H:%M","date_time"=>"%Y/%m/%d %H:%M"}
datetime_fields = @personal_plugin_field.primary_modal_fields.select{|field_value| datetime_field_types_hash.keys.include?(field_value[:field_type])}.map{|field_value|
[field_value[:field_name],datetime_field_types_hash[field_value[:field_type]]]
}.to_h
value_case_codes = ["value = #{plugin_template}.send(field) rescue \"\"",
"if field.include?(\".\")",
"#{@blank_text}value = #{plugin_template}",
"#{@blank_text}field.split(\".\").each{|f| value = value.send(f) rescue nil }",
"end",
"file_fields = #{plugin_template_related_files}",
"if file_fields.include?(field)",
"#{@blank_text}files = #{plugin_template}.send(field.pluralize)",
"#{@blank_text}value = files.map do |file|",
"#{@blank_text * 2}url = file.file.url",
"#{@blank_text * 2}title = (file.title.blank? ? File.basename(file.file.path) : file.title)",
"#{@blank_text * 2}\"<li><a href='\#{url}'' target='_blank'>\#{title}</li>\"",
"#{@blank_text}end",
"#{@blank_text}value = value.join(\"\")",
"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" +
"value"
value_case_codes += "\r\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?}
}
related_backend_index_fields_contents = related_backend_index_fields.map.with_index{|field_names,i|
related_modal_name = @personal_plugin_field.related_modal_name[i]
field_names.map{|field_name| "<%= #{related_modal_name}.#{field_name} %>"}
}
member_methods_define = @personal_plugin_field.primary_modal_fields.select{|f| f[:field_type] == "member" && f[:field_name].present?}.map{|field_value|
["def #{field_value[:field_name].pluralize}",
" MemberProfile.find(self.#{field_value[:field_name].singularize}_ids) rescue []",
"end"]
}.flatten
@match_pattern = {"personal_plugin_template" => @personal_plugin_field.module_name,
"plugin_template" => plugin_template,
"plugin_template_related" => plugin_template_related,
@ -148,6 +196,8 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"plugin_template_file" => plugin_template_related_files,
"plugin_template_sort_hash" => "nil",
"col_name_to_show_in_index_page_arr" => col_name_to_show_in_index_page,
"related_backend_index_fields" => related_backend_index_fields,
"related_backend_index_fields_contents" => related_backend_index_fields_contents,
"backend_index_fields" => backend_index_fields,
"backend_index_fields_contents" => backend_index_fields_contents,
"plugin_template_related_files_text" => plugin_template_related_files_text,
@ -155,32 +205,74 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
"none_locale_fields" => none_locale_fields,
"none_locale_fields_input_fields" => none_locale_fields_input_fields,
"locale_fields_input_fields" => locale_fields_input_fields,
"plugin_template_related_main_field" => plugin_template_related_main_field
"related_locale_fields" => related_locale_fields,
"related_none_locale_fields" => related_none_locale_fields,
"related_none_locale_fields_input_fields" => related_none_locale_fields_input_fields,
"related_locale_fields_input_fields" => related_locale_fields_input_fields,
"plugin_template_related_main_field" => plugin_template_related_main_field,
"backend_profile_fields" => backend_profile_fields,
"backend_profile_fields_contents" => backend_profile_fields_contents,
"value_case_codes" => value_case_codes,
"display_field_code" => display_field_code,
"member_methods_define" => member_methods_define
}
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}
@logs = []
replace_files(files)
#Thread.new do
dirs.each do |dir|
replace_dir(dir)
end
replace_dirs(dirs,false)
#end
render :html => @logs.join("<br>").html_safe#@match_pattern
copy_templates("#{cp_template_dir_path}modules/#{@personal_plugin_field.module_name}/")
render :html => @logs#@match_pattern#@logs.join("<br>").html_safe#@match_pattern
end
def generate_input_field(field_type,field_name,localize = false)
def copy_templates(source)
templates = Dir.glob('app/templates/*/').select{|f| File.basename(f) != 'mobile'}
templates.each do |template|
FileUtils.cp_r(source,"#{template}modules/.")
end
end
def get_input_fields(field_values,extra_field_name=nil,plugin_template = nil)
none_locale_fields = []
locale_fields = []
locale_fields_input_fields = []
none_locale_fields_input_fields = []
@index = 0
field_values.each do |field_value|
field_name = field_value[:field_name]
field_type = field_value[:field_type]
next if field_name.blank?
next if field_type == "file"
if (field_value[:localize] == "1" rescue false)
locale_fields << field_name
input_field = generate_input_field(field_type,field_name,true,extra_field_name,plugin_template)
locale_fields_input_fields << input_field
else
none_locale_fields << field_name
input_field = generate_input_field(field_type,field_name,false,extra_field_name,plugin_template)
none_locale_fields_input_fields << input_field
end
@index += 1
end
return locale_fields , none_locale_fields , locale_fields_input_fields,none_locale_fields_input_fields
end
def generate_input_field(field_type,field_name,localize = false,extra_field_name = nil, plugin_template = nil)
personal_plugin_template = @personal_plugin_field.module_name
plugin_template = @personal_plugin_field.primary_modal_name
plugin_template = @personal_plugin_field.primary_modal_name if plugin_template.nil?
input_field = ""
field_value_text = "@#{plugin_template}.#{field_name}"
field_name_text = ":#{field_name}"
field_name_text = "locale" if localize
placeholder = "#{personal_plugin_template}.#{field_name}"
placeholder = "#{personal_plugin_template}.#{extra_field_name}.#{field_name}" if extra_field_name
if localize
field_value_text = "@#{plugin_template}.#{field_name}_translations[locale]"
end
case field_type
when "year"
input_field = datetime_picker_text(plugin_template,field_name_text, "yyyy")#"<%= select_year((#{field_value_text} ? #{field_value_text}.to_i : DateTime.now.year), {:start_year => DateTime.now.year + 5, :end_year => 1930}, {:name => '#{plugin_template}[#{field_name}]',:class => 'span1'} ) %>"
when "year_month"
input_field = datetime_picker_text(plugin_template,field_name_text, "yyyy/MM")
when "date"
input_field = datetime_picker_text(plugin_template,field_name_text, "yyyy/MM/dd")
when "time"
@ -188,12 +280,14 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
when "date_time"
input_field = datetime_picker_text(plugin_template,field_name_text)
when "text_editor"
input_field = "<%= f.text_area #{field_name_text}, class: \"input-block-level ckeditor\", placeholder: t(\"#{personal_plugin_template}.#{field_name}\"), value: (#{field_value_text} rescue nil) %>"
input_field = "<%= f.text_area #{field_name_text}, class: \"input-block-level ckeditor\", placeholder: t(\"#{placeholder}\"), value: (#{field_value_text} rescue nil) %>"
when "member"
input_field = "<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: '#{plugin_template}[#{field_name.singularize}_ids][]', email_members: @#{plugin_template}.#{field_name.pluralize},index:'#{@index}',select_name:'#{field_name.pluralize}'} %>"
else #text_field
input_field = "<%= f.text_field #{field_name_text}, class: \"input-block-level\", placeholder: t(\"#{personal_plugin_template}.#{field_name}\"), value: (#{field_value_text} rescue nil) %>"
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("<% end %>\r\n ")
input_field.prepend("<%= f.fields_for :#{field_name}_translations do |f| %>\r\n ").concat("\r\n<% end %>")
end
input_field
end
@ -207,6 +301,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
next if field_value[:field_type] == "file" || field_value[:field_name].blank?
type = "String"
default = "\"\""
field_name = field_value[:field_name]
case field_value[:field_type]
when "date"
type = "Date"
@ -217,45 +312,56 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
when "date_time"
type = "DateTime"
default = "DateTime.now"
when "year_month"
type = "DateTime"
default = "DateTime.now"
when "member"
type = "Array"
default = "[]"
field_name = "#{field_name.singularize}_ids"
end
no_localize_types = ["date","time","date_time"]
field_text = "field :#{field_value[:field_name]}, :type => #{type}, :default => #{default}"
field_text += ", :localize => true" if field_value[:localize] && !no_localize_types.include?(field_value[:field_type])
no_localize_types = ["date","time","date_time","year_month"]
field_text = "field :#{field_name}, :type => #{type}, :default => #{default}"
field_text += ", :localize => true" if field_value[:localize] == "1" && !no_localize_types.include?(field_value[:field_type])
field_text += ", as: :slug_title" if field_value[:slug_title] == "1"
field_text
end
fields_text.join("\r\n#{@blank_text}")
fields_text.select{|t| t.present?}.join("\r\n")
end
def replace_dirs(dirs)
dirs.each do |dir|
def replace_dirs(dirs,is_array = true)
dirs.each_with_index do |dir,i|
if is_array
replace_dir(dir,i)
else
replace_dir(dir)
end
end
def replace_dir(dir)
dir = replace_file(dir)
return true if dir.select{|d| d.present?}.blank?
if dir.count > 1
end
def replace_dir(dir,current_index = nil)
dir = replace_file(dir,current_index)
return true if dir.blank?
if dir.class == Array
replace_dirs(dir)
else
dir = dir[0]
return true
end
sub_dirs = Dir.glob("#{dir}/*/")
files = Dir.glob("#{dir}/*").select { |fn| File.file?(fn) }
replace_files(files)
@logs << files.to_s if current_index
replace_files(files,current_index)
if sub_dirs.present?
sub_dirs.each do |sub_dir|
replace_dir(sub_dir)
replace_dir(sub_dir,current_index)
end
else
return true
end
end
def replace_files(files)
def replace_files(files,current_index = nil)
files.each do |file|
replace_file(file)
replace_file(file,current_index)
end
end
def replace_file(file)
def replace_file(file,current_index = nil)
isfile = File.file?(file)
path = File.dirname(file)
file_name = File.basename(file)
@ -265,6 +371,7 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
elsif file_name != new_filename
if new_filename.class == Array
new_filename.each do |f|
next if f.blank?
FileUtils.cp_r("#{path}/#{file_name}", "#{path}/#{f}")
end
FileUtils.rm_rf("#{path}/#{file_name}")
@ -273,31 +380,39 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
end
end
if new_filename.blank?
return [""]
return ""
else
is_array = new_filename.class == Array
new_filename = Array(new_filename)
if isfile
new_filename.each_with_index do |sub_file,i|
files = Array(new_filename)
files.each_with_index do |sub_file,i|
next if File.extname(sub_file).match(/(png|jpg)/i)
file_text = File.read("#{path}/#{sub_file}")
if is_array
file_text = replace_text_with_pattern(file_text,false,i)
file_text = replace_text_with_pattern(file_text,false,i,nil,true)
elsif current_index
@logs << sub_file
file_text = replace_text_with_pattern(file_text,false,current_index,nil,true)
else
file_text = replace_text_with_pattern(file_text)
end
File.open("#{path}/#{sub_file}",'w+'){|f| f.write(file_text)}
end
end
return new_filename.map{|sub_file| "#{path}/#{sub_file}" if sub_file.present?}
if is_array
return new_filename.map{|sub_file| "#{path}/#{sub_file}" if sub_file.present?}.select{|f| f.present?}
else
return "#{path}/#{new_filename}"
end
end
def replace_text_with_pattern(text,is_file=false,i = nil)
end
def replace_text_with_pattern(text,is_file=false,i = nil,sub_i = nil,inner = false)
new_text = text
@match_pattern.each do |k,v|
next if !include_key(new_text,k)
vv = v
vv = vv[i] if i && vv.class == Array
vv = vv[sub_i] if sub_i && vv.class == Array
if vv.class == String
if i && vv == "" && is_file
new_text = ""
@ -305,6 +420,9 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
new_text = gsub_text_by_key_value(new_text,k,vv)
end
elsif vv.class == Array
if i
@logs << i
end
if is_file
if v.count == 0
new_text = ""
@ -323,7 +441,11 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
start_index = 2 if parse_content[0..1] == "\r\n"
end_index = end_index - 2 if parse_content[(end_index - 2)..(end_index - 1)] == "\r\n"
parse_content = parse_content.slice(start_index,end_index)
result = (0...vv.count).map {|i| replace_text_with_pattern(parse_content,false,i) }.join("")
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
end
result
end
@ -335,10 +457,13 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
return text.include?(key) || text.include?(key.classify)
end
def gsub_text_by_key_value(text,k,v)
text = text.gsub(k + "s",v.pluralize)
text = text.gsub(k ,v )
text = text.gsub(k.classify + "s",v.classify.pluralize)
text = text.gsub(k.classify,v.classify)
@blank_texts = []
text.gsub(/\n(\s*)[^\n]*(#{k}|#{k.classify})/m) {|ff| @blank_texts << $1.gsub(/(\r\n|\n)/,'')}
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]}")}
text = text.gsub(k.classify + "s"){|ff| v.classify.pluralize.gsub("\n","\n#{@blank_texts[i]}")}
text = text.gsub(k.classify){|ff| v.classify.gsub("\n","\n#{@blank_texts[i]}")}
end
private
def personal_plugin_field_params

View File

@ -3,6 +3,7 @@ class PersonalPluginField
include Mongoid::Timestamps
include OrbitModel::Status
include MemberHelper
field :author_name, :type => String, :default => "",:localize => true
field :title, :type => String, :default => "",:localize => true
field :module_name, :type => String, :default => ""
field :primary_modal_name, :type => String, :default => ""

View File

@ -50,6 +50,15 @@
<% end %>
</div>
</div>
<!-- author_translation_name -->
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_plugin_generator.author_translation_name") %></label>
<div class="controls">
<%= f.fields_for :author_name_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_plugin_generator.author_translation_name"), value: (@personal_plugin_field.author_name_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
@ -108,8 +117,8 @@
</div>
</div>
</div>
<% field_types = ["text_field","text_editor","file","select","year","date","time","date_time"].map{|field| [thead_field(field),field]}
field_types1 = field_types.select{|a| a[1] != "file"}
<% field_types = ["text_field","text_editor","file","select","year","year_month","date","time","date_time","member"].map{|field| [thead_field(field),field]}
field_types1 = field_types.select{|a| a[1] != "file" && a[1] != "member"}
%>
<div class="tab-content language-area">
<div id="primary_modal_plane">

View File

@ -4,6 +4,7 @@ en:
restful_actions:
fields_setting: Fields Setting
personal_plugin_generator:
author_translation_name: Author translation name
personal_plugin_generator: Personal Plugin Generate
personal_plugin_name: Personal Plugin Name Translation
module_name: Module Name
@ -19,6 +20,7 @@ en:
file: File
select: Select field
year: Year
year_month: Year Month
date: Date
time: Time
date_time: Date time
@ -34,3 +36,4 @@ en:
please_choose_one_slug_title: Please choose one Slug title!
slug_title_can_only_choose_one: Slug title can only choose one!
generate_plugin: Generate plugin
member: Member

View File

@ -4,6 +4,7 @@ zh_tw:
restful_actions:
fields_setting: 欄位設定
personal_plugin_generator:
author_translation_name: 著作人翻譯名稱
personal_plugin_generator: 個人外掛生成
personal_plugin_name: 個人外掛翻譯名稱
module_name: 模組名稱
@ -19,6 +20,7 @@ zh_tw:
file: 檔案
select: 選項欄位
year: 年份
year_month: 年月
date: 日期
time: 時間
date_time: 日期與時間
@ -34,3 +36,4 @@ zh_tw:
please_choose_one_slug_title: 請至少選擇一個頭銜標題!
slug_title_can_only_choose_one: 頭銜標題只能選擇一個!
generate_plugin: 生成個人外掛
member: 會員

View File

@ -5,7 +5,7 @@ class Admin::PluginTemplateRelatedsController < OrbitMemberController
def new
@plugin_template_related = PluginTemplateRelated.new
@url = admin_course_semesters_path
@url = admin_plugin_template_relateds_path
end
def edit
@ -21,7 +21,7 @@ class Admin::PluginTemplateRelatedsController < OrbitMemberController
def update
plugin_template_related = PluginTemplateRelated.find(params[:id]) rescue nil
if !plugin_template_related.nil?
plugin_template_related.update_attributes(course_semester_params)
plugin_template_related.update_attributes(plugin_template_related_params)
end
@plugin_template_relateds = PluginTemplateRelated.all
end

View File

@ -5,11 +5,12 @@ class PersonalPluginTemplatesController < ApplicationController
member = plugin_template.member_profile
fields_to_show = col_name_to_show_in_index_page
fields_hash = fields_to_show.map{|field| [field, get_display_field(field)]}.to_h
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>"
fields_hash["link_to_show"] = OrbitHelper.url_to_show(course.to_param)
fields_hash["link_to_show"] = OrbitHelper.url_to_show(plugin_template.to_param)
fields_hash
end
extras = extra_translate_title
@ -29,8 +30,8 @@ class PersonalPluginTemplatesController < ApplicationController
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
def get_display_field(field)
value_case_codes
def get_display_field(plugin_template,field)
display_field_code
return value
end
end

View File

@ -18,6 +18,9 @@ class PluginTemplate
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(plugin_template_sort_hash) }
<% parse_again_start %>
member_methods_define
<% parse_again_end %>
def self.get_plugin_datas_to_member(datas)
fields_to_show = col_name_to_show
@ -29,11 +32,13 @@ class PluginTemplate
fields_to_show.each do |t|
if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false)
fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false)
elsif (self.relations.include?(t.pluralize) rescue false)
fields_to_remove << t if (datas.where(t.pluralize.to_sym.ne=>[]).count == 0 rescue false)
else
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false)
end
pd_title << {
"plugin_data_title" => I18n.t("plugin_template.#{t}")
"plugin_data_title" => I18n.t("personal_plugin_template.#{t}")
} if !fields_to_remove.include?(t)
end
@ -43,7 +48,7 @@ class PluginTemplate
pd_data = []
fields_to_show.collect do |t|
pd_data << { "data_title" => display_field(t) }
pd_data << { "data_title" => p.display_field(t) }
end
{
@ -69,6 +74,7 @@ class PluginTemplate
end
def get_plugin_field_data(field)
plugin_template = self
value_case_codes
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value
@ -83,6 +89,7 @@ class PluginTemplate
end
def display_field(field)
plugin_template = self
display_field_code
end

View File

@ -1,21 +1,39 @@
<%= form_for(@course_semester, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %>
<%= form_for(@plugin_template_related, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t("personal_course.course_semester") %></h3>
<h3 id="myModalLabel"><%= t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field") %></h3>
</div>
<div class="modal-body">
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<% parse_again_start %>
<div class="control-group">
<%= label_tag t(locale), t(locale), :class => 'control-label' %>
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.related_locale_fields") %></label>
<div class="controls">
<%= f.text_field locale, :value => (@course_semester.title_translations[locale] rescue nil) %>
</div>
<div class="tab-content">
<% @site_in_use_locales.each_with_index do |locale,i| %>
<div class="tab-pane fade <%= "active in" if i == 0 %>" id="related_locale_fields_<%=locale%>">
related_locale_fields_input_fields
</div>
<% end %>
</div>
<div class="btn-group" data-toggle="buttons-radio">
<% @site_in_use_locales.each_with_index do |locale,i| %>
<a class="btn <%= "active" if i == 0 %>" href="#related_locale_fields_<%=locale%>" data-toggle="tab"><%= t(locale) %></a>
<% end %>
</div>
</div>
</div>
<% parse_again_end %>
<% parse_again_start %>
<!-- related_none_locale_fields -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.related_none_locale_fields") %></label>
<div class="controls">
related_none_locale_fields_input_fields
</div>
</div>
<% parse_again_end %>
</div>
<div class="modal-footer">
<%= f.submit t('submit'), :class=>'btn btn-primary' %>

View File

@ -1,2 +1,2 @@
$("#course_semesters tbody").html("<%= j render :partial => '/admin/courses/course_semester', :collection => @course_semesters %>");
$("#course_semester_modal").modal("hide");
$("#plugin_template_relateds").html("<%= j render :partial => '/admin/plugin_templates/plugin_template_related' %>");
$("#plugin_template_related_modal").modal("hide");

View File

@ -1,2 +1,2 @@
$("#course_semesters tbody").html("<%= j render :partial => '/admin/courses/course_semester', :collection => @course_semesters %>");
$("#course_semester_modal").modal("hide");
$("#plugin_template_relateds").html("<%= j render :partial => '/admin/plugin_templates/plugin_template_related' %>");
$("#plugin_template_related_modal").modal("hide");

View File

@ -1 +1 @@
$('#course_semester_modal').html("<%= j render 'form' %>");
$('#plugin_template_related_modal').html("<%= j render 'form' %>");

View File

@ -1 +1 @@
$('#course_semester_modal').html("<%= j render 'form' %>");
$('#plugin_template_related_modal').html("<%= j render 'form' %>");

View File

@ -1,2 +1,2 @@
$("#course_semesters tbody").html("<%= j render :partial => '/admin/courses/course_semester', :collection => @course_semesters %>");
$("#course_semester_modal").modal("hide");
$("#plugin_template_relateds").html("<%= j render :partial => '/admin/plugin_templates/plugin_template_related' %>");
$("#plugin_template_related_modal").modal("hide");

View File

@ -109,7 +109,7 @@
<% if !@member.nil? %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<label class="control-label muted"><%= t("personal_plugin_template.author_name_translation") %></label>
<div class="controls">
<%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
@ -119,7 +119,7 @@
<% else %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<label class="control-label muted"><%= t("personal_plugin_template.author_name_translation") %></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'} %>
@ -139,9 +139,9 @@
<% parse_again_start %>
<!-- plugin_template_related -->
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related") %></label>
<label class="control-label muted"><%= t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field") %></label>
<div class="controls">
<%= f.select :plugin_template_related_id, plugin_template_related.all.collect {|t| [ t.plugin_template_related_main_field, t.id ]} %>
<%= f.select :plugin_template_related_id, PluginTemplateRelated.all.collect {|t| [ t.plugin_template_related_main_field, t.id ]} %>
</div>
</div>
<% parse_again_end %>

View File

@ -1,7 +1,21 @@
<thead>
<tr>
<% parse_again_start %>
<th><%= t("personal_plugin_template.plugin_template_related.related_backend_index_fields") %></th>
<% parse_again_end %>
<th><%= t(:action) %></th>
</tr>
</thead>
<tbody>
<% @plugin_template_relateds.each do |plugin_template_related| %>
<tr id="<%= dom_id plugin_template_related %>">
<td><%= plugin_template_related.title %></td>
<% parse_again_start %>
<td>related_backend_index_fields_contents</td>
<% parse_again_end %>
<td class="span2">
<a href="<%= edit_admin_plugin_template_related_path(plugin_template_related) %>#plugin_template_related_modal" data-toggle="modal" data-remote="true" class="action"><%= t(:edit) %></a>
<%= link_to t(:delete_), admin_plugin_template_related_path(plugin_template_related), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %>
</td>
</tr>
<% end %>
</tbody>

View File

@ -26,7 +26,7 @@
<div class="detail w-a h-a">
<p class="totle">
<a class="btn btn-small btn-primary pull-right" href="<%= new_admin_plugin_template_related_path %>#plugin_template_related_modal" data-toggle="modal" data-remote="true"><i class="icon-plus"></i> <%= t('add')%></a>
<span><%= t("personal_plugin_template.plugin_template_related") %></span>
<span><%= t("personal_plugin_template.plugin_template_related.plugin_template_related_main_field") %></span>
</p>
<div class="detal-list my_scroll">
<div class="scrollbar">
@ -38,10 +38,8 @@
</div>
<div class="viewport">
<div class="overview">
<table id="course_semesters" class="table table-striped">
<tbody>
<%= render :partial => 'plugin_template_related', :collection => @plugin_template_relateds %>
</tbody>
<table id="plugin_template_relateds" class="table table-striped">
<%= render :partial => 'plugin_template_related', :locals => {:@plugin_template_relateds => @plugin_template_relateds} %>
</table>
</div>
</div>

View File

@ -7,17 +7,17 @@
<%
if has_access?
@plugin_templates = PluginTemplate.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@plugin_templates = PluginTemplate.where(member_profile_id: @member.id).order_by(plugin_template_sort_hash).page(params[:page]).per(10)
else
@plugin_templates = PluginTemplate.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
@plugin_templates = PluginTemplate.where(is_hidden: false, member_profile_id: @member.id).order_by(plugin_template_sort_hash).page(params[:page]).per(10)
end
%>
<% if has_access? %>
<div class="list-active">
<div class="btn-group">
<%= link_to('Hide', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-hide", :rel => toggle_hide_admin_courses_path(member_profile_id: @member.id.to_s, disable: 'true') ) %>
<%= link_to('Show', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-show", :rel => toggle_hide_admin_courses_path(member_profile_id: @member.id.to_s, disable: 'false') ) %>
<%= link_to('Hide', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-hide", :rel => toggle_hide_admin_plugin_templates_path(member_profile_id: @member.id.to_s, disable: 'true') ) %>
<%= link_to('Show', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-show", :rel => toggle_hide_admin_plugin_templates_path(member_profile_id: @member.id.to_s, disable: 'false') ) %>
</div>
</div>
<% end -%>
@ -28,7 +28,9 @@
<% if has_access? %>
<th><input type="checkbox" /></th>
<% end -%>
<th><%= t('personal_plugin_template.col_name') %></th>
<% parse_again_start %>
<th><%= t('personal_plugin_template.backend_profile_fields') %></th>
<% parse_again_end %>
</tr>
</thead>
<tbody>
@ -39,18 +41,9 @@
<%= check_box_tag 'to_change[]', plugin_template.id.to_s, false, :class => "list-check" %>
</td>
<% end %>
<td><%= plugin_template.year %></td>
<td>
<%= link_to plugin_template.title, OrbitHelper.url_to_plugin_show(plugin_template.to_param,'plugin_template').to_s, target: "blank"%>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<% if has_access? %>
<li><%= link_to t('edit'), '/admin/members/'+@member.to_param+'/plugin_templates/'+plugin_template.id+'/edit' %></li>
<li><%= link_to t(:delete_), admin_plugin_template_path(id: plugin_template.id, member_profile_id: @member.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li>
<% end %>
</ul>
</div>
</td>
<% parse_again_start %>
<td>backend_profile_fields_contents</td>
<% parse_again_end %>
</tr>
<% end %>
</tbody>

View File

@ -24,8 +24,9 @@ Rails.application.routes.draw do
end
end
end
<% parse_again_start %>
resources :plugin_template_relateds
<% parse_again_end %>
end
end
end

View File

@ -3,7 +3,7 @@
<thead>
<tr>
<% parse_again_start %>
<th class="col-md-1">{{th_col_name_to_show_in_index_page_arr}}</th>
<th class="col-md-1">{{th-col_name_to_show_in_index_page_arr}}</th>
<% parse_again_end %>
</tr>
</thead>