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 def show
params = OrbitHelper.params 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| fields_to_show = [
{ "paper_title",
"file_url" => file.file.url, "conference_title",
"file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title), "paper_level",
"file_ext" => File.extname(file.file.path).sub('.',''), "paper_type",
"file_description" => file.description "authors",
} "author_type",
end "year",
"language",
paper_types = writing_conference.conference_paper_types.map do |type| "isi_number",
{"paper_type"=>type.title} "period_start_date",
end "period_end_date",
"url",
author_types = writing_conference.conference_author_types.map do |type| "isbn",
{"author_type"=>type.title} "note",
end "location",
"sponsor",
paper_levels = writing_conference.conference_paper_levels.map do |level| "file"
{"paper_level"=>level.title} ]
end
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
{
"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_)
}
}
end end
end end

View File

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