diff --git a/app/controllers/personal_researches_controller.rb b/app/controllers/personal_researches_controller.rb index 6f53fe2..bc9ea17 100644 --- a/app/controllers/personal_researches_controller.rb +++ b/app/controllers/personal_researches_controller.rb @@ -26,41 +26,55 @@ class PersonalResearchesController < ApplicationController def show params = OrbitHelper.params - research = Research.where(:is_hidden=>false).find_by(uid: params[:uid]) + plugin = Research.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show =[ + "research_title", + "authors", + "extracted_chapters", + "year", + "language", + "publish_date", + "keywords", + "url", + "note", + "file" + ] - files = research.research_files.map do |file| - { - "file_url" => file.file.url, - "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title), - "file_ext" => File.extname(file.file.path).sub('.',''), - "file_description" => file.description - } - end + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} + + # files = research.research_files.map do |file| + # { + # "file_url" => file.file.url, + # "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title), + # "file_ext" => File.extname(file.file.path).sub('.',''), + # "file_description" => file.description + # } + # end - { - "files" => files, - "data" => { - "research_title" => research.research_title, - "authors" => research.authors, - "extracted_chapters" => research.extracted_chapters, - "year" => research.year, - "language" => t(research.language), - "publish_date" => (research.publish_date.strftime("%Y.%m") rescue ""), - "keywords" => research.keywords, - "url" => research.url, - "note" => research.note, + # { + # "files" => files, + # "data" => { + # "research_title" => research.research_title, + # "authors" => research.authors, + # "extracted_chapters" => research.extracted_chapters, + # "year" => research.year, + # "language" => t(research.language), + # "publish_date" => (research.publish_date.strftime("%Y.%m") rescue ""), + # "keywords" => research.keywords, + # "url" => research.url, + # "note" => research.note, - "th_research_title" => t("personal_research.research_title"), - "th_authors" => t("personal_research.authors"), - "th_extracted_chapters" => t("personal_research.extracted_chapters"), - "th_year" => t("personal_research.year"), - "th_language" => t("personal_research.language"), - "th_publish_date" => t("personal_research.publication_date"), - "th_keywords" => t("personal_research.keywords"), - "th_url" => t("personal_research.url"), - "th_note" => t("personal_research.note"), - "th_files" => t(:file_) - } - } + # "th_research_title" => t("personal_research.research_title"), + # "th_authors" => t("personal_research.authors"), + # "th_extracted_chapters" => t("personal_research.extracted_chapters"), + # "th_year" => t("personal_research.year"), + # "th_language" => t("personal_research.language"), + # "th_publish_date" => t("personal_research.publication_date"), + # "th_keywords" => t("personal_research.keywords"), + # "th_url" => t("personal_research.url"), + # "th_note" => t("personal_research.note"), + # "th_files" => t(:file_) + # } + # } end end \ No newline at end of file diff --git a/app/models/research.rb b/app/models/research.rb index 75f6331..1a0f1e4 100644 --- a/app/models/research.rb +++ b/app/models/research.rb @@ -28,6 +28,45 @@ class Research before_validation :add_http + def get_plugin_data(fields_to_show) + plugin_datas = [] + fields_to_show.each do |field| + plugin_data = self.get_plugin_field_data(field) + next if plugin_data.blank? or plugin_data['value'].blank? + plugin_datas << plugin_data + end + plugin_datas + end + + def get_plugin_field_data(field) + case field + when "language" + value = I18n.t(self.language) rescue "" + when "publish_date" + value = self.publish_date.strftime("%Y-%m") rescue "" + when "file" + files = [] + self.research_files.each do |research_file| + url = research_file.file.url + title = (research_file.title.blank? ? File.basename(research_file.file.path) : research_file.title) + files << "
  • #{title}
  • " + end + value = files.join("") + else + value = self.send(field) rescue "" + end + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + + { + "key"=>field, + "title_class"=>"research-#{field.gsub('_','-')}-field", + "value_class"=>"research-#{field.gsub('_','-')}-value", + "title"=>I18n.t('personal_research.'+field), + "value"=>value + } + end + protected def add_http diff --git a/config/locales/en.yml b/config/locales/en.yml index 552d962..7665fa2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -19,6 +19,7 @@ en: keywords : "Keywords" abstract : "Abstract" publication_date : "Date of Publication" + publish_date: "Publish Date" url : "Reference URL" note : "Note" level_type : "Level Type" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 324f60e..6621eed 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -19,6 +19,7 @@ zh_tw: keywords : "關鍵字" abstract : "摘要" publication_date : "發表日期" + publish_date: "發表日期" url : "參考連結" note : "記事" level_type : "期刊類別"