Update frontend

This commit is contained in:
manson 2014-08-01 19:48:33 +08:00
parent 0c7b4c8761
commit c6abf7ad6a
2 changed files with 53 additions and 39 deletions

View File

@ -26,45 +26,22 @@ class PersonalLabsController < ApplicationController
def show
params = OrbitHelper.params
lab = Lab.where(:is_hidden=>false).find_by(uid: params[:uid])
plugin = Lab.where(:is_hidden=>false).find_by(uid: params[:uid])
fields_to_show = [
"lab_title",
"location",
"participating_professor",
"participating_student",
"research_direction",
"facility",
"year",
"keywords",
"extension_no",
"url",
"note",
"file"
]
files = lab.lab_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"=>{
"lab_title" => lab.lab_title,
"location" => lab.location,
"participating_professor" => lab.participating_professor,
"participating_student" => lab.participating_student,
"year" => lab.year,
"keywords" => lab.keywords,
"extension_no" => lab.extension_no,
"research_direction" => lab.research_direction,
"facility" => lab.facility,
"url" => lab.url,
"note" => lab.note,
"th_lab_title" => t('personal_lab.lab_title'),
"th_location" => t('personal_lab.location'),
"th_participating_professor" => t('personal_lab.participating_professor'),
"th_participating_student" => t('personal_lab.participating_student'),
"th_year" => t('personal_lab.year'),
"th_keywords" => t('personal_lab.keywords'),
"th_extension_no" => t('personal_lab.extension_no'),
"th_research_direction" => t('personal_lab.research_direction'),
"th_facility" => t('personal_lab.facility'),
"th_url" => t('personal_lab.url'),
"th_note" => t('personal_lab.note'),
"td_files" => t(:file_)
}
}
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
end

View File

@ -29,6 +29,43 @@ class Lab
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 "file"
files = []
self.lab_files.each do |lab_file|
url = lab_file.file.url
title = (lab_file.title.blank? ? File.basename(lab_file.file.path) : lab_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"=>"lab-#{field.gsub('_','-')}-field",
"value_class"=>"lab-#{field.gsub('_','-')}-value",
"title"=>I18n.t('personal_lab.'+field),
"value"=>value
}
end
protected
def add_http