From 2ddc2922559115e19fbca02fc50eab6a71299842 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 23 Aug 2022 18:40:36 +0800 Subject: [PATCH] Add some fields. Fix bug. --- .../personal_conferences_controller.rb | 9 +- app/models/writing_conference.rb | 129 ++++++++++++------ .../admin/writing_conferences/_form.html.erb | 32 +++++ config/locales/en.yml | 12 +- config/locales/zh_tw.yml | 12 +- 5 files changed, 138 insertions(+), 56 deletions(-) diff --git a/app/controllers/personal_conferences_controller.rb b/app/controllers/personal_conferences_controller.rb index 189ff7c..9590c31 100644 --- a/app/controllers/personal_conferences_controller.rb +++ b/app/controllers/personal_conferences_controller.rb @@ -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 diff --git a/app/models/writing_conference.rb b/app/models/writing_conference.rb index c7f5426..18d7661 100644 --- a/app/models/writing_conference.rb +++ b/app/models/writing_conference.rb @@ -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 : "#{p.paper_title}") - 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" => "#{p.url}" } - 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 : "#{p.paper_title}") + 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" => "#{p.url}" } + 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 "" diff --git a/app/views/admin/writing_conferences/_form.html.erb b/app/views/admin/writing_conferences/_form.html.erb index 4bb6a0a..c0291eb 100644 --- a/app/views/admin/writing_conferences/_form.html.erb +++ b/app/views/admin/writing_conferences/_form.html.erb @@ -170,6 +170,38 @@ + +
+ +
+ <%= f.text_field :vol_no %> +
+
+ + +
+ +
+ <%= f.text_field :issue_no %> +
+
+ + +
+ +
+ <%= f.text_field :form_to_start, :class=>'span1' %> ~ <%= f.text_field :form_to_end, :class=>'span1' %> +
+
+ + +
+ +
+ <%= f.text_field :total_pages %> +
+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index bd67067..8652cf6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 4a1bbcf..450c524 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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 : "參考連結"