Update frontend
This commit is contained in:
parent
0c7b4c8761
commit
c6abf7ad6a
|
@ -26,45 +26,22 @@ class PersonalLabsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
params = OrbitHelper.params
|
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 = [
|
||||||
files = lab.lab_files.map do |file|
|
"lab_title",
|
||||||
{
|
"location",
|
||||||
"file_url" => file.file.url,
|
"participating_professor",
|
||||||
"file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title),
|
"participating_student",
|
||||||
"file_ext" => File.extname(file.file.path).sub('.',''),
|
"research_direction",
|
||||||
"file_description" => file.description
|
"facility",
|
||||||
}
|
"year",
|
||||||
end
|
"keywords",
|
||||||
|
"extension_no",
|
||||||
|
"url",
|
||||||
|
"note",
|
||||||
|
"file"
|
||||||
|
]
|
||||||
|
|
||||||
{
|
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
||||||
"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_)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -29,6 +29,43 @@ class Lab
|
||||||
|
|
||||||
before_validation :add_http
|
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
|
protected
|
||||||
|
|
||||||
def add_http
|
def add_http
|
||||||
|
|
Loading…
Reference in New Issue