From c6abf7ad6ad1dba939e20a0b74996db3401b01df Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 1 Aug 2014 19:48:33 +0800 Subject: [PATCH] Update frontend --- app/controllers/personal_labs_controller.rb | 55 ++++++--------------- app/models/lab.rb | 37 ++++++++++++++ 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/app/controllers/personal_labs_controller.rb b/app/controllers/personal_labs_controller.rb index c2dfc15..ba8ff86 100644 --- a/app/controllers/personal_labs_controller.rb +++ b/app/controllers/personal_labs_controller.rb @@ -26,45 +26,22 @@ class PersonalLabsController < ApplicationController def show params = OrbitHelper.params - lab = Lab.where(:is_hidden=>false).find_by(uid: params[:uid]) - - 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 + 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"=>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 \ No newline at end of file diff --git a/app/models/lab.rb b/app/models/lab.rb index 613e953..afa4209 100644 --- a/app/models/lab.rb +++ b/app/models/lab.rb @@ -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 << "
  • #{title}
  • " + end + value = files.join("") + else + value = self.send(field) rescue "" + end + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : 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