Update frontend

This commit is contained in:
manson 2014-08-01 19:49:35 +08:00
parent 582757864b
commit f92689293e
4 changed files with 88 additions and 33 deletions

View File

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

View File

@ -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 << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = files.join("")
else
value = self.send(field) rescue ""
end
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : 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

View File

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

View File

@ -19,6 +19,7 @@ zh_tw:
keywords : "關鍵字"
abstract : "摘要"
publication_date : "發表日期"
publish_date: "發表日期"
url : "參考連結"
note : "記事"
level_type : "期刊類別"