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 << "