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
conference_title
location
period_start_date
period_end_date
period
vol_no
issue_no
form_to_start
form_to_end
paper_type
paper_level
total_pages
sponsor
author_type
number_of_authors
@ -163,8 +166,6 @@ class PersonalConferencesController < ApplicationController
paper_title
conference_title
location
period_start_date
period_end_date
period
paper_type
paper_level

View File

@ -25,6 +25,11 @@ class WritingConference
field :create_user_id, :type => BSON::ObjectId
field :update_user_id, :type => BSON::ObjectId
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 :number_of_authors
field :rss2_id
@ -52,28 +57,61 @@ class WritingConference
title << self.paper_title if self.paper_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_levels = ( !self.conference_paper_levels.blank? ? "(#{self.conference_paper_levels.collect{|x| x.title}.join(', ')})" : "")
title << paper_types + paper_levels
title << "#{period_start_date}-#{period_end_date}" if (self.period_start_date.present? && self.period_end_date.present?)
# if !self.publication_date.nil?
# pd = self.publication_date.strftime("%Y-%m-%d").split('-')
# title << pd[0]
# end
# title << self.year
title = title.join(', ')
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 = ""
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")
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")
if self.period_start_date.present? && self.period_end_date.present?
title << self.duration
elsif !self.publication_date.nil?
title << (self.publication_date.strftime("%b. %Y") rescue nil)
elsif self.year.present?
title << self.year
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
@ -105,11 +143,16 @@ class WritingConference
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)
else
t = "conference_author_types" if t == "author_type"
t = "period_start_date" if t == "period"
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false)
t = "author_type" if t == "conference_author_types"
t = "period" if t == "period_start_date"
t2 = t
case t
when "form_to"
t2 = "form_to_start"
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
pd_title << {
"plugin_data_title" => I18n.t("personal_conference.#{t}")
@ -117,31 +160,31 @@ class WritingConference
end
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|
pd_data = []
fields_to_show.collect do |t|
if !page.nil? && page.custom_string_field == "table"
case t
when "paper_title"
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>")
pd_data << { "data_title" => link}
when "paper_types"
pd_data << {"data_title" => ( !p.conference_paper_types.blank? ? p.conference_paper_types.collect{|x| x.title}.join(', ') : "")}
when "paper_levels"
pd_data << {"data_title" => ( !p.conference_paper_levels.blank? ? p.conference_paper_levels.collect{|x| x.title}.join(', ') : "")}
when "author_type"
pd_data << {"data_title" => (p.conference_author_types.collect{|cat| cat.title}.join(", ") rescue "")}
when "period"
pd_data << {"data_title" => p.duration}
when "url"
pd_data << { "data_title" => "<a href='#{p.url}' title=\"#{p.url}\" target='_blank'>#{p.url}</a>" }
when "publication_date"
pd_data << { "data_title" => (p.publication_date.strftime(@setting.publication_date_format) rescue "") }
else
pd_data << { "data_title" => p.send(t) }
when "paper_title"
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>")
pd_data << { "data_title" => link}
when "paper_types"
pd_data << {"data_title" => ( !p.conference_paper_types.blank? ? p.conference_paper_types.collect{|x| x.title}.join(', ') : "")}
when "paper_levels"
pd_data << {"data_title" => ( !p.conference_paper_levels.blank? ? p.conference_paper_levels.collect{|x| x.title}.join(', ') : "")}
when "author_type"
pd_data << {"data_title" => (p.conference_author_types.collect{|cat| cat.title}.join(", ") rescue "")}
when "period"
pd_data << {"data_title" => p.duration(date_format)}
when "url"
pd_data << { "data_title" => "<a href='#{p.url}' title=\"#{p.url}\" target='_blank'>#{p.url}</a>" }
when "publication_date"
pd_data << { "data_title" => (p.publication_date.strftime(@setting.publication_date_format) rescue "") }
else
pd_data << { "data_title" => p.send(t) }
end
else
if t == "paper_title"
@ -190,6 +233,8 @@ class WritingConference
end
end
value = value.join(" / ")
when "period"
value = self.duration((I18n.locale == :zh_tw ? '%Y-%m-%d' : '%b. %d, %Y'))
when "publication_date"
get_setting
value = self.publication_date.strftime(@setting.publication_date_format) rescue ""

View File

@ -170,6 +170,38 @@
</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 -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_conference.period_start_date") %></label>

View File

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

View File

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