Update frontend

This commit is contained in:
manson 2014-08-01 19:04:43 +08:00
parent 4b4a4cf92c
commit 4de1fba4fd
2 changed files with 63 additions and 95 deletions

View File

@ -23,75 +23,28 @@ class PersonalConferencesController < ApplicationController
def show
params = OrbitHelper.params
writing_conference = WritingConference.where(:is_hidden=>false).find_by(uid: params[:uid])
plugin = WritingConference.where(:is_hidden=>false).find_by(uid: params[:uid])
files = writing_conference.writing_conference_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
paper_types = writing_conference.conference_paper_types.map do |type|
{"paper_type"=>type.title}
end
author_types = writing_conference.conference_author_types.map do |type|
{"author_type"=>type.title}
end
paper_levels = writing_conference.conference_paper_levels.map do |level|
{"paper_level"=>level.title}
end
{
"files" => files,
"paper_types" => paper_types,
"author_types" => author_types,
"paper_levels" => paper_levels,
"data" => {
"paper_title" => writing_conference.paper_title,
"conference_title" => writing_conference.conference_title,
"authors" => writing_conference.authors,
"location" => writing_conference.location,
"sponsor" => writing_conference.sponsor,
"year" => writing_conference.year,
"language" => (t(writing_conference.language) rescue ""),
"keywords" => writing_conference.keywords,
"abstract" => writing_conference.abstract,
"publication_date" => writing_conference.publication_date,
"period_start_date"=> writing_conference.period_start_date,
"period_end_date" => writing_conference.period_end_date,
"url" => writing_conference.url,
"note" => writing_conference.note,
"isbn" => writing_conference.isbn,
"isi_number" => writing_conference.isi_number,
"td_year" => t("personal_conference.year"),
"td_paper_title" => t("personal_conference.paper_title"),
"td_conference_title" => t("personal_conference.conference_title"),
"td_location" => t("personal_conference.location"),
"td_period_start_date" => t("personal_conference.period_start_date"),
"td_period_end_date" => t("personal_conference.period_end_date"),
"td_duration" => t("personal_conference.duration"),
"td_publication_date" => t("personal_conference.publication_date"),
"td_sponsor" => t("personal_conference.sponsor"),
"td_authors" => t("personal_conference.authors"),
"td_language" => t("personal_conference.language"),
"td_isbn" => t("personal_conference.isbn"),
"td_isi_number" => t("personal_conference.isi_number"),
"td_url" => t("personal_conference.url"),
"td_keywords" => t("personal_conference.keywords"),
"td_abstract" => t("personal_conference.abstract"),
"td_note" => t("personal_conference.note"),
"td_paper_type" => t("personal_conference.paper_type"),
"td_author_type" => t("personal_conference.author_type"),
"td_paper_level" => t("personal_conference.paper_level"),
"td_files" => t(:file_)
}
}
fields_to_show = [
"paper_title",
"conference_title",
"paper_level",
"paper_type",
"authors",
"author_type",
"year",
"language",
"isi_number",
"period_start_date",
"period_end_date",
"url",
"isbn",
"note",
"location",
"sponsor",
"file"
]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
end

View File

@ -55,34 +55,49 @@ class WritingConference
title.join(', ')
end
def values_for_view
attribute_values = self.attributes.select{|k,v| v if (k.in?(
[ "year",
"language",
"period_start_date",
"period_end_date",
"publication_date",
"keywords",
"abstract",
"url",
"note",
"isbn",
"isi_number"]) && v.present?)}
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
localized_fields = {
"paper_title" => self.paper_title,
"conference_title" => self.conference_title,
"location"=>self.location,
"sponsor"=>self.sponsor}
def get_plugin_field_data(field)
case field
when "paper_level"
value = self.conference_paper_levels.collect{|level| level.title}.join(',') rescue ""
when "author_type"
value = self.conference_author_types.collect{|type| type.title}.join(',') rescue ""
when "paper_type"
value = self.conference_paper_types.collect{|type| type.title}.join(',') 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.writing_conference_files.each do |conference_files|
url = conference_files.file.url
title = (conference_files.title.blank? ? File.basename(conference_files.file.path) : conference_files.title)
files << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = files.join("")
else
value = self.send(field) rescue ""
end
authors = {"authors" => self.authors}
files = Hash.new
# self.writing_conference_files.each do |f, index|
# title = f.title.blank? ? File.basename(f.file.path) : f.title
# end
values = [localized_fields, attribute_values, authors,files]
values.inject(&:merge)
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value
{
"key"=>field,
"title_class"=>"conference-#{field.gsub('_','-')}-field",
"value_class"=>"conference-#{field.gsub('_','-')}-value",
"title"=>I18n.t('personal_conference.'+field),
"value"=>value
}
end
protected