Add some fields.

Fix bug.
This commit is contained in:
BoHung Chiu 2022-08-23 18:40:36 +08:00
parent 364341d246
commit 2ddc292255
5 changed files with 138 additions and 56 deletions

View File

@ -135,11 +135,14 @@ class PersonalConferencesController < ApplicationController
paper_title paper_title
conference_title conference_title
location location
period_start_date
period_end_date
period period
vol_no
issue_no
form_to_start
form_to_end
paper_type paper_type
paper_level paper_level
total_pages
sponsor sponsor
author_type author_type
number_of_authors number_of_authors
@ -163,8 +166,6 @@ class PersonalConferencesController < ApplicationController
paper_title paper_title
conference_title conference_title
location location
period_start_date
period_end_date
period period
paper_type paper_type
paper_level paper_level

View File

@ -25,6 +25,11 @@ class WritingConference
field :create_user_id, :type => BSON::ObjectId field :create_user_id, :type => BSON::ObjectId
field :update_user_id, :type => BSON::ObjectId field :update_user_id, :type => BSON::ObjectId
field :isbn field :isbn
field :vol_no, type: String
field :issue_no, type: String
field :form_to_start, type: String
field :form_to_end, type: String
field :total_pages, type: String
field :isi_number field :isi_number
field :number_of_authors field :number_of_authors
field :rss2_id field :rss2_id
@ -52,28 +57,61 @@ class WritingConference
title << self.paper_title if self.paper_title.present? title << self.paper_title if self.paper_title.present?
title << self.conference_title if self.conference_title.present? title << self.conference_title if self.conference_title.present?
title << self.location if self.location.present?
paper_types = ( !self.conference_paper_types.blank? ? self.conference_paper_types.collect{|x| x.title}.join(', ') : "") paper_types = ( !self.conference_paper_types.blank? ? self.conference_paper_types.collect{|x| x.title}.join(', ') : "")
paper_levels = ( !self.conference_paper_levels.blank? ? "(#{self.conference_paper_levels.collect{|x| x.title}.join(', ')})" : "") paper_levels = ( !self.conference_paper_levels.blank? ? "(#{self.conference_paper_levels.collect{|x| x.title}.join(', ')})" : "")
title << paper_types + paper_levels title << paper_types + paper_levels
title << "#{period_start_date}-#{period_end_date}" if (self.period_start_date.present? && self.period_end_date.present?) title << "vol. " + self.vol_no.strip if (self.vol_no.present? && self.vol_no != "0")
title << self.issue_no if (self.issue_no.present? && self.issue_no != "0")
# if !self.publication_date.nil? title << "pp." + self.form_to_start.to_s+"-"+self.form_to_end.to_s if (self.form_to_start.present? && self.form_to_start != "0")
# pd = self.publication_date.strftime("%Y-%m-%d").split('-') if self.period_start_date.present? && self.period_end_date.present?
# title << pd[0] title << self.duration
# end elsif !self.publication_date.nil?
# title << self.year title << (self.publication_date.strftime("%b. %Y") rescue nil)
elsif self.year.present?
title = title.join(', ') title << self.year
title.rstrip.chomp(",")
end
def duration
if !self.send('period_start_date').nil? or !self.send('period_end_date').nil?
date = (self.send('period_start_date').strftime('%Y.%m.%d') rescue "")+' ~ '+(self.send('period_end_date').strftime('%Y.%m.%d') rescue I18n.t('personal_project.up_to_today'))
else
date = ""
end end
if self.location.present?
title << self.location
end
title = title.join(', ')
title.sub(/^\\s*,/,'').gsub(/,(\s*,)+/,',').strip
end
def form_to
if (self.form_to_start.present? && self.form_to_start != "0")
self.form_to_start.to_s+"-"+self.form_to_end.to_s
else
""
end
end
def duration(date_format="%b. %d, %Y")
period_start_date_present = self.period_start_date.present?
period_end_date_present = self.period_end_date.present?
date = ""
if period_start_date_present && period_end_date_present
if self.period_start_date == self.period_end_date
date = self.period_start_date.strftime(date_format)
else
period_start_ym = [self.period_start_date.year, self.period_start_date.month]
period_end_ym = [self.period_end_date.year, self.period_end_date.month]
same_year = period_start_ym[0] == period_end_ym[0]
same_month = period_start_ym[1] == period_end_ym[1]
month_date_format = date_format.sub('%Y','').gsub(',','').strip.sub(/^[\/\-\.]/,'').sub(/[\/\-\.]$/,'')
if same_year && same_month
date = self.period_start_date.strftime("#{month_date_format}-#{self.period_end_date.day}, %Y")
elsif same_year
date = self.period_start_date.strftime("#{month_date_format}-#{self.period_end_date.strftime(month_date_format)}, %Y")
else
date = self.period_start_date.strftime(date_format) + ' ~ ' + self.period_end_date.strftime(date_format)
end
end
elsif period_start_date_present || period_end_date_present
if self.period_start_date
date = self.period_start_date.strftime('%b. %d, %Y') + ' ~ ' + I18n.t('personal_conference.up_to_today')
else
date = self.period_end_date.strftime('%b. %d, %Y')
end
end
date
end end
@ -105,11 +143,16 @@ class WritingConference
if (self.fields[t].type.to_s == "String" rescue false) if (self.fields[t].type.to_s == "String" rescue false)
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).or(t.to_sym.ne => "").count == 0 rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil).or(t.to_sym.ne => "").count == 0 rescue false)
else else
t = "conference_author_types" if t == "author_type" t2 = t
t = "period_start_date" if t == "period" case t
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) when "form_to"
t = "author_type" if t == "conference_author_types" t2 = "form_to_start"
t = "period" if t == "period_start_date" when "author_type"
t2 = "conference_author_types"
when "period"
t2 = "period_start_date"
end
fields_to_remove << t if (datas.where(t2.to_sym.ne => nil).count == 0 rescue false)
end end
pd_title << { pd_title << {
"plugin_data_title" => I18n.t("personal_conference.#{t}") "plugin_data_title" => I18n.t("personal_conference.#{t}")
@ -117,31 +160,31 @@ class WritingConference
end end
fields_to_show = fields_to_show - fields_to_remove fields_to_show = fields_to_show - fields_to_remove
date_format = (I18n.locale == :zh_tw ? '%Y-%m-%d' : '%b. %d, %Y')
plugin_datas = datas.sort_for_frontend.collect do |p| plugin_datas = datas.sort_for_frontend.collect do |p|
pd_data = [] pd_data = []
fields_to_show.collect do |t| fields_to_show.collect do |t|
if !page.nil? && page.custom_string_field == "table" if !page.nil? && page.custom_string_field == "table"
case t case t
when "paper_title" when "paper_title"
link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_conference') link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_conference')
link = (link == "#" ? p.paper_title : "<a href='#{link}' title=\"#{p.paper_title}\" target='_blank'>#{p.paper_title}</a>") link = (link == "#" ? p.paper_title : "<a href='#{link}' title=\"#{p.paper_title}\" target='_blank'>#{p.paper_title}</a>")
pd_data << { "data_title" => link} pd_data << { "data_title" => link}
when "paper_types" when "paper_types"
pd_data << {"data_title" => ( !p.conference_paper_types.blank? ? p.conference_paper_types.collect{|x| x.title}.join(', ') : "")} pd_data << {"data_title" => ( !p.conference_paper_types.blank? ? p.conference_paper_types.collect{|x| x.title}.join(', ') : "")}
when "paper_levels" when "paper_levels"
pd_data << {"data_title" => ( !p.conference_paper_levels.blank? ? p.conference_paper_levels.collect{|x| x.title}.join(', ') : "")} pd_data << {"data_title" => ( !p.conference_paper_levels.blank? ? p.conference_paper_levels.collect{|x| x.title}.join(', ') : "")}
when "author_type" when "author_type"
pd_data << {"data_title" => (p.conference_author_types.collect{|cat| cat.title}.join(", ") rescue "")} pd_data << {"data_title" => (p.conference_author_types.collect{|cat| cat.title}.join(", ") rescue "")}
when "period" when "period"
pd_data << {"data_title" => p.duration} pd_data << {"data_title" => p.duration(date_format)}
when "url" when "url"
pd_data << { "data_title" => "<a href='#{p.url}' title=\"#{p.url}\" target='_blank'>#{p.url}</a>" } pd_data << { "data_title" => "<a href='#{p.url}' title=\"#{p.url}\" target='_blank'>#{p.url}</a>" }
when "publication_date" when "publication_date"
pd_data << { "data_title" => (p.publication_date.strftime(@setting.publication_date_format) rescue "") } pd_data << { "data_title" => (p.publication_date.strftime(@setting.publication_date_format) rescue "") }
else else
pd_data << { "data_title" => p.send(t) } pd_data << { "data_title" => p.send(t) }
end end
else else
if t == "paper_title" if t == "paper_title"
@ -190,6 +233,8 @@ class WritingConference
end end
end end
value = value.join(" / ") value = value.join(" / ")
when "period"
value = self.duration((I18n.locale == :zh_tw ? '%Y-%m-%d' : '%b. %d, %Y'))
when "publication_date" when "publication_date"
get_setting get_setting
value = self.publication_date.strftime(@setting.publication_date_format) rescue "" value = self.publication_date.strftime(@setting.publication_date_format) rescue ""

View File

@ -170,6 +170,38 @@
</div> </div>
</div> </div>
<!-- vol_no -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.vol_no") %></label>
<div class="controls">
<%= f.text_field :vol_no %>
</div>
</div>
<!-- issue_no -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.issue_no") %></label>
<div class="controls">
<%= f.text_field :issue_no %>
</div>
</div>
<!-- form_to -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.form_to") %></label>
<div class="controls">
<%= f.text_field :form_to_start, :class=>'span1' %> ~ <%= f.text_field :form_to_end, :class=>'span1' %>
</div>
</div>
<!-- total_pages -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.total_pages") %></label>
<div class="controls">
<%= f.text_field :total_pages %>
</div>
</div>
<!-- period_start_date --> <!-- period_start_date -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_conference.period_start_date") %></label> <label class="control-label muted"><%= t("personal_conference.period_start_date") %></label>

View File

@ -35,11 +35,13 @@ en:
keywords : "Keywords" keywords : "Keywords"
isbn: "ISSN (ISBN)" isbn: "ISSN (ISBN)"
isi_number: "ISI Number" isi_number: "ISI Number"
# total_pages : "Total Pages" vol_no : "Vol.No"
# form_to_start : "From" issue_no : "Issue.No"
# form_to_end : "To" form_to: "Page(s)"
# from : "From" form_to_start : "From"
# to : "To" form_to_end : "To"
up_to_today : "Up to today"
total_pages : "Total Pages"
abstract : "Abstract" abstract : "Abstract"
publication_date : "Date of Publication" publication_date : "Date of Publication"
url : "Reference URL" url : "Reference URL"

View File

@ -34,11 +34,13 @@ zh_tw:
keywords : "關鍵字" keywords : "關鍵字"
isbn: "ISSN (ISBN)" isbn: "ISSN (ISBN)"
isi_number: "ISI Number" isi_number: "ISI Number"
# total_pages : "總頁數" vol_no : "卷數"
# form_to_start : "From" issue_no : "期數"
# form_to_end : "To" form_to: "頁碼"
# from : "起" form_to_start : "起"
# to : "迄" form_to_end : "迄"
up_to_today : "迄今"
total_pages : "總頁數"
abstract : "摘要" abstract : "摘要"
publication_date : "發表日期" publication_date : "發表日期"
url : "參考連結" url : "參考連結"