This commit is contained in:
BoHung Chiu 2021-03-08 21:02:36 +08:00
parent aff1807a35
commit 6dc3bba750
3 changed files with 13 additions and 7 deletions

View File

@ -262,9 +262,11 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")" strftime_string = ".strftime(\"#{date_time_strftime[field_value[:field_type]]}\")"
end end
["def #{field_value[:field_name]}", ["def #{field_value[:field_name]}",
" \"\#{self.#{field_value[:field_name]}_start#{strftime_string}} ~ \#{self.#{field_value[:field_name]}_end#{strftime_string}}\"", " #{field_value[:field_name]}_start = self.#{field_value[:field_name]}_start#{strftime_string} rescue \"\"",
"end"] " #{field_value[:field_name]}_end = self.#{field_value[:field_name]}_end#{strftime_string} rescue \"\"",
}.flatten " \"\#{#{field_value[:field_name]}_start} ~ \#{#{field_value[:field_name]}_end}\"",
"end"]
}.flatten
related_periodic_methods_define = @personal_plugin_field.related_modal_fields.map{|field_values| related_periodic_methods_define = @personal_plugin_field.related_modal_fields.map{|field_values|
field_values.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value| field_values.select{|f| (f[:periodic_time] == "1" rescue false)}.map{|field_value|
strftime_string = "" strftime_string = ""
@ -294,6 +296,7 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
iterate_step_text = "1" iterate_step_text = "1"
end end
end 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]} 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("\r\n")
@match_pattern = {"personal_plugin_template" => personal_plugin_template, @match_pattern = {"personal_plugin_template" => personal_plugin_template,
@ -337,7 +340,8 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
"iterate_step_text" => iterate_step_text, "iterate_step_text" => iterate_step_text,
"plugin_template_related_members" => plugin_template_related_members.to_s, "plugin_template_related_members" => plugin_template_related_members.to_s,
"periodic_methods_define" => periodic_methods_define, "periodic_methods_define" => periodic_methods_define,
"related_periodic_methods_define" => related_periodic_methods_define "related_periodic_methods_define" => related_periodic_methods_define,
"period_fields_text" => period_fields.to_s
} }
max_length = @match_pattern.keys.map{|k| k.length}.max 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| (v.class != Array) ? (max_length - k.length) : -k.length}

View File

@ -13,7 +13,7 @@ class PersonalPluginTemplatesController < ApplicationController
fields_hash = fields_to_show.map{|field| [field, get_display_field(plugin_template,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 '#' path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#'
fields_hash["authors"] = "<a href='#{path}'>#{member.name}</a>" 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["link_to_show"] = OrbitHelper.url_to_show(plugin_template.to_param)
fields_hash fields_hash
end end

View File

@ -43,8 +43,10 @@ parse_again_end
if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false) 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) 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) elsif (self.relations.include?(t.pluralize) rescue false)
fields_to_remove << t if (datas.where(t.pluralize.to_sym.ne=>[]).count == 0 rescue false) fields_to_remove << t if (datas.where(t.pluralize.to_sym.ne=>[]).count == 0 rescue false)
else elsif period_fields_text.include?(t)
fields_to_remove << t if (datas.select{|d| d.send(t) != " ~ " }.count == 0 rescue false)
else
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false)
end end
pd_title << { pd_title << {