diff --git a/app/controllers/admin/personal_plugin_fields_controller.rb b/app/controllers/admin/personal_plugin_fields_controller.rb index 6d70263..28ff3cf 100644 --- a/app/controllers/admin/personal_plugin_fields_controller.rb +++ b/app/controllers/admin/personal_plugin_fields_controller.rb @@ -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,20 +93,22 @@ 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 " + - "
- -
\r\n " - else + "<%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\r\n" + + "
"+ + " "+ + "
\r\n" + elsif field_name.include?(".") + "<%= #{plugin_template}.#{field_name} rescue \"\" %>" + else "<%= #{plugin_template}.#{field_name} %>" end 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}\"
  • \#{title}
  • \"", + "#{@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 = \"\#{value}\" 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("
    ").html_safe#@match_pattern + copy_templates("#{cp_template_dir_path}modules/#{@personal_plugin_field.module_name}/") + render :html => @logs#@match_pattern#@logs.join("
    ").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| - replace_dir(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 end - def replace_dir(dir) - dir = replace_file(dir) - return true if dir.select{|d| d.present?}.blank? - if dir.count > 1 + 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 end - def replace_text_with_pattern(text,is_file=false,i = nil) + 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 diff --git a/app/models/personal_plugin_field.rb b/app/models/personal_plugin_field.rb index 9a3a3e9..640ffcf 100644 --- a/app/models/personal_plugin_field.rb +++ b/app/models/personal_plugin_field.rb @@ -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 => "" diff --git a/app/views/admin/personal_plugin_fields/_form.html.erb b/app/views/admin/personal_plugin_fields/_form.html.erb index 7977917..75e5a71 100644 --- a/app/views/admin/personal_plugin_fields/_form.html.erb +++ b/app/views/admin/personal_plugin_fields/_form.html.erb @@ -50,6 +50,15 @@ <% end %> + +
    + +
    + <%= 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 %> +
    +
    <% end %> @@ -108,8 +117,8 @@ - <% 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"} %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 7573e6d..d354e69 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 @@ -33,4 +35,5 @@ en: slug_title: Slug title 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 \ No newline at end of file + generate_plugin: Generate plugin + member: Member \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index eaa4eee..c09be43 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: 日期與時間 @@ -33,4 +35,5 @@ zh_tw: slug_title: 頭銜標題 please_choose_one_slug_title: 請至少選擇一個頭銜標題! slug_title_can_only_choose_one: 頭銜標題只能選擇一個! - generate_plugin: 生成個人外掛 \ No newline at end of file + generate_plugin: 生成個人外掛 + member: 會員 \ No newline at end of file diff --git a/template_generator/app/controllers/admin/plugin_template_relateds_controller.rb b/template_generator/app/controllers/admin/plugin_template_relateds_controller.rb index a75f892..3b68d12 100644 --- a/template_generator/app/controllers/admin/plugin_template_relateds_controller.rb +++ b/template_generator/app/controllers/admin/plugin_template_relateds_controller.rb @@ -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 diff --git a/template_generator/app/controllers/admin/plugin_templates_controller.rb b/template_generator/app/controllers/admin/plugin_templates_controller.rb index 2c69b49..ca73d31 100644 --- a/template_generator/app/controllers/admin/plugin_templates_controller.rb +++ b/template_generator/app/controllers/admin/plugin_templates_controller.rb @@ -121,6 +121,6 @@ class Admin::PluginTemplatesController < OrbitMemberController uid = path[-2].split("-").last uid = uid.split("?").first end - @plugin_template = PluginTemplate.find_by(:uid => uid) rescue PluginTemplate.find(params[:id]) + @plugin_template = PluginTemplate.find_by(:uid => uid) rescue PluginTemplate.find(params[:id]) end end \ No newline at end of file diff --git a/template_generator/app/controllers/personal_plugin_templates_controller.rb b/template_generator/app/controllers/personal_plugin_templates_controller.rb index 059bf01..abb4f6e 100644 --- a/template_generator/app/controllers/personal_plugin_templates_controller.rb +++ b/template_generator/app/controllers/personal_plugin_templates_controller.rb @@ -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"] = "#{member.name}" - 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 diff --git a/template_generator/app/models/plugin_template.rb b/template_generator/app/models/plugin_template.rb index 39cd5a5..276c1e8 100644 --- a/template_generator/app/models/plugin_template.rb +++ b/template_generator/app/models/plugin_template.rb @@ -1,24 +1,27 @@ class PluginTemplate - include Mongoid::Document - include Mongoid::Timestamps - include OrbitModel::Status - include MemberHelper - include Slug + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include MemberHelper + include Slug col_fields - plugin_template_related_files_fields + plugin_template_related_files_fields - <% parse_again_start %> - belongs_to :plugin_template_related - <% parse_again_end %> +<% parse_again_start %> + belongs_to :plugin_template_related +<% parse_again_end %> - belongs_to :member_profile + belongs_to :member_profile - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(plugin_template_sort_hash) } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(plugin_template_sort_hash) } - def self.get_plugin_datas_to_member(datas) +<% 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) - else + 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 { @@ -58,7 +63,7 @@ class PluginTemplate end - def get_plugin_data(fields_to_show) + def get_plugin_data(fields_to_show) plugin_datas = [] fields_to_show.each do |field| plugin_data = self.get_plugin_field_data(field) rescue nil @@ -66,9 +71,10 @@ class PluginTemplate plugin_datas << plugin_data end plugin_datas - end + end def get_plugin_field_data(field) + plugin_template = self value_case_codes value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value @@ -83,6 +89,7 @@ class PluginTemplate end def display_field(field) + plugin_template = self display_field_code end diff --git a/template_generator/app/views/admin/plugin_template_relateds/_form.html.erb b/template_generator/app/views/admin/plugin_template_relateds/_form.html.erb index 07b442c..c3b05ac 100644 --- a/template_generator/app/views/admin/plugin_template_relateds/_form.html.erb +++ b/template_generator/app/views/admin/plugin_template_relateds/_form.html.erb @@ -1,20 +1,38 @@ -<%= 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| %>