Update frontend

This commit is contained in:
manson 2014-08-01 18:56:56 +08:00
parent e9e29da1fc
commit b763b047eb
3 changed files with 79 additions and 48 deletions

View File

@ -4,7 +4,7 @@ class JournalPapersController < ApplicationController
journal_paper_list = journal_papers.collect do |journal_paper|
{
"year" => journal_paper.year,
"paper_title" => journal_paper.paper_title,
"paper_title" => journal_paper.create_link,
"author" => journal_paper.authors,
"link_to_show" => OrbitHelper.url_to_show(journal_paper.to_param)
}
@ -23,31 +23,28 @@ class JournalPapersController < ApplicationController
def show
params = OrbitHelper.params
journal_paper = JournalPaper.find_by(uid: params[:uid])
field_to_show = ["year", "language", "vol_no", "issue_no", "form_to_start", "form_to_end", "total_pages", "isbn", "publication_date", "url", "note", "journal_title", "paper_title", "updated_at", "created_at", "uid", "journal_level_ids", "journal_paper_author_type_ids", "member_profile_id"]
plugin = JournalPaper.find_by(uid: params[:uid])
fields_to_show = [
"paper_title",
"journal_title",
"level_type",
"paper_type",
"authors",
"author_type",
"year",
"publication_date",
"language",
"vol_no",
"issue_no",
"form_to_start",
"form_to_end",
"total_pages",
"isbn",
"url",
"note",
"file"
]
publication_date = journal_paper.publication_date.to_date.strftime("%Y/%m/%d") rescue nil
files = journal_paper.journal_paper_files.map{|file| { "file_url" => file.journal_file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
{
"journal_paper_files" => files,
"data" => {
"title" => journal_paper.paper_title,
"journal_title" => journal_paper.journal_title,
"year" => journal_paper.year,
"authors" => journal_paper.authors,
"isbn" => journal_paper.isbn,
"vol_no" => journal_paper.vol_no,
"issue_no" => journal_paper.issue_no,
"form_to_start" => journal_paper.form_to_start,
"form_to_end" => journal_paper.form_to_end,
"language" => journal_paper.language,
"total_pages" => journal_paper.total_pages,
"keywords" => journal_paper.keywords,
"abstract" => journal_paper.abstract,
"publication_date" => publication_date,
"url" => journal_paper.url,
"note" => journal_paper.note
}
}
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
end

View File

@ -65,7 +65,7 @@ class JournalPaper
def authors
authors = []
authors << self.member_profile.name if self.member_profile_id.present?
authors << (!self.journal_paper_authors.blank? ? "#{self.journal_paper_authors.collect{|j| j.name}.join(', ')}" : nil)
authors << self.journal_paper_authors.collect{|j| j.name}.join(', ') unless self.journal_paper_authors.blank?
authors.join(', ')
end
@ -98,14 +98,47 @@ class JournalPaper
end
end
def values_for_view
attribute_values = self.attributes.select{|k,v| v if (k.in?(["year","language","isbn","vol_no","issue_no","form_to_start","form_to_end","total_pages","keywords","abstract","publication_date","url","note"]) && v.present?)}
localized_fields = {"paper_title" => self.attributes["paper_title"][I18n.locale], "journal_title" => self.attributes["journal_title"][I18n.locale]}
authors = {"authors" => self.authors}
files = {}
files = self.journal_paper_files.collect do |f| {f.title => url_to_file(f.journal_file.url, f.title)} end
values = [attribute_values, localized_fields, authors] + files
values.inject(&:merge)
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 "level_type"
value = self.journal_levels.collect{|level| level.title}.join(',') rescue ""
when "author_type"
value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue ""
when "paper_type"
value = self.journal_paper_type.title rescue ""
when "publication_date"
value = self.publication_date.to_date.strftime("%Y-%m-%d") rescue ""
when "language"
value = I18n.t(self.language) rescue ""
when "file"
files = []
self.journal_paper_files.each do |file|
url = file.journal_file.url
title = (file.title.blank? ? File.basename(file.journal_file.path) : file.title)
files << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = files.join("")
else
value = self.send(field) rescue ""
end
{
"key"=>field,
"title_class"=>"journal-#{field.gsub('_','-')}-field",
"value_class"=>"journal-#{field.gsub('_','-')}-value",
"title"=>I18n.t('personal_journal.'+field),
"value"=>value
}
end
protected

View File

@ -13,8 +13,8 @@ zh_tw:
vol_no : "卷數"
issue_no : "期數"
form_to: "From To"
form_to_start : "起"
form_to_end : ""
form_to_start : "起"
form_to_end : "迄頁"
total_pages : "總頁數"
keywords : "關鍵字"
abstract : "摘要"
@ -23,6 +23,7 @@ zh_tw:
note : "記事"
level_type : "期刊等級"
author_type : "作者類別"
paper_type: "論文類型"
from : "起"
to : "訖"
file : "檔案"