Add authors settings.

This commit is contained in:
chiu committed 2024-01-23 07:58:32 +08:00
1 parent 05bbab70b8
commit 774a5ec062
8 files changed
+54 -7

No files matched your search

@@ -137,7 +137,16 @@ 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
authors_translation_name = @personal_plugin_field.authors_name_translations
in_use_locales.each do |l|
l = l.to_s
if authors_translation_name[l].blank?
I18n.with_locale(l) do
authors_translation_name[l] = I18n.t("personal_plugin_generator.authors")
end
end
end
primary_modal_fields << {:field_name=>"authors", :translation_name=> authors_translation_name, :field_type=>"text_editor", :localize=>"1", :slug_title=>"0", :periodic_time=>"0"} if primary_modal_fields.select{|f| f[:field_name] == "authors"}.count == 0 && @personal_plugin_field.enable_authors
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
@@ -232,7 +241,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
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
"\n <%= link_to #{plugin_template}.#{field_name}, page_for_#{plugin_template}(#{plugin_template}), target: \"blank\" %>\n" +
"\n <%= link_to #{plugin_template}.#{field_name}, OrbitHelper.url_to_plugin_show(plugin_template.to_param,'personal_plugin_template').to_s, 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"+
@@ -274,6 +283,10 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
col_name_to_show = @personal_plugin_field.frontend_fields["member_show"].to_a rescue []
col_name_to_show_in_show_page = @personal_plugin_field.frontend_fields["show"].to_a rescue []
col_name_to_show_in_index_page = @personal_plugin_field.frontend_fields["index"].to_a rescue []
if @personal_plugin_field.enable_authors
col_name_to_show_in_show_page = col_name_to_show_in_show_page.map{|col| (col == 'member_profile' ? 'authors' : col)}
col_name_to_show_in_index_page = col_name_to_show_in_index_page.map{|col| (col == 'member_profile' ? 'authors' : col)}
end
extra_translate_title = col_name_to_show_in_index_page.map{|field_name| #在個人外掛前台index頁面的欄位翻譯名稱hash
["th-#{field_name}","I18n.t(\"#{@personal_plugin_field.module_name}.#{field_name}\")"]
}
@@ -304,6 +317,15 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
datetime_fields = 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
if @personal_plugin_field.enable_authors
authors_codes = ["elsif field == \"member_profile\" || field == \"authors\"",
"#{@blank_text}value = get_authors_show(#{plugin_template})"]
else
authors_codes = ["elsif field == \"member_profile\"",
"#{@blank_text}member = #{plugin_template}.member_profile",
"#{@blank_text}member_name = (member ? member.name : nil)",
"#{@blank_text}value = (member ? \"<a href='\#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='\#{member_name}'>\#{member_name}</a>\" : \"\")"]
end
value_case_codes = ["value = #{plugin_template}.send(field) rescue \"\"",
"if field.include?(\".\")",
"#{@blank_text}value = #{plugin_template}",
@@ -336,8 +358,7 @@ 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\" || field == \"authors\"",
"#{@blank_text}value = get_authors_show(#{plugin_template})",
*authors_codes,
"end",
"strftime_hash = #{datetime_fields}",
"if strftime_hash.keys.include?(field)",