diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 1af1546..2498adb 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -1,6 +1,6 @@ class PersonalProjectsController < ApplicationController def index - projects = Project.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + projects = Project.where(:is_hidden=>false).order_by(:period_start_date=>'desc',:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) project_list = projects.collect do |project| { "duration" => project.duration, @@ -27,49 +27,66 @@ class PersonalProjectsController < ApplicationController def show params = OrbitHelper.params - project = Project.where(:is_hidden=>false).find_by(uid: params[:uid]) + plugin = Project.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show = [ + "project_title", + "project_type", + "job_title", + "participator", + "unit", + "year", + "language", + "keywords", + "abstract", + "period", + "url", + "note", + "file" + ] - files = project.project_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_datas"=>plugin.get_plugin_data(fields_to_show)} - { - "files" => files, + # files = project.project_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 - "data" => { - "project_title" => project.project_title, - "project_type" => project.project_type.title, - "job_title" => project.job_title, - "participator" => project.participator, - "unit" => project.unit, - "year" => project.year, - "language" => project.language, - "keywords" => project.keywords, - "abstract" => project.abstract, - "duration" => project.duration, - "url" => project.url, - "note" => project.note, + # { + # "files" => files, - "th_project_title" => t("personal_project.project_title"), - "th_job_title" => t("personal_project.job_title"), - "th_participator" => t("personal_project.participator"), - "th_unit" => t("personal_project.unit"), - "th_year" => t("personal_project.year"), - "th_language" => t("personal_project.language"), - "th_keywords" => t("personal_project.keywords"), - "th_abstract" => t("personal_project.abstract"), - "th_duration" => t("personal_project.period"), - "th_url" => t("personal_project.url"), - "th_note" => t("personal_project.note"), + # "data" => { + # "project_title" => project.project_title, + # "project_type" => project.project_type.title, + # "job_title" => project.job_title, + # "participator" => project.participator, + # "unit" => project.unit, + # "year" => project.year, + # "language" => project.language, + # "keywords" => project.keywords, + # "abstract" => project.abstract, + # "duration" => project.duration, + # "url" => project.url, + # "note" => project.note, - "th_project_type" => t("personal_project.project_category"), - "th_files" => t(:file_) - } - } + # "th_project_title" => t("personal_project.project_title"), + # "th_job_title" => t("personal_project.job_title"), + # "th_participator" => t("personal_project.participator"), + # "th_unit" => t("personal_project.unit"), + # "th_year" => t("personal_project.year"), + # "th_language" => t("personal_project.language"), + # "th_keywords" => t("personal_project.keywords"), + # "th_abstract" => t("personal_project.abstract"), + # "th_duration" => t("personal_project.period"), + # "th_url" => t("personal_project.url"), + # "th_note" => t("personal_project.note"), + + # "th_project_type" => t("personal_project.project_category"), + # "th_files" => t(:file_) + # } + # } end end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 95c7168..d869238 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -34,7 +34,48 @@ class Project before_validation :add_http def duration - "#{self.period_start_date.strftime("%Y.%m")} ~ #{self.period_end_date.strftime("%Y.%m")}" + "#{self.period_start_date.strftime("%Y.%m") rescue ""} ~ #{self.period_end_date.strftime("%Y.%m") rescue ""}" + end + + 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 "project_type" + value = self.project_type.title rescue "" + when "period" + value = self.duration + when "file" + files = [] + self.project_files.each do |project_file| + url = project_file.file.url + title = (project_file.title.blank? ? File.basename(project_file.file.path) : project_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"=>"project-#{field.gsub('_','-')}-field", + "value_class"=>"project-#{field.gsub('_','-')}-value", + "title"=>I18n.t('personal_project.'+field), + "value"=>value + } end protected diff --git a/config/locales/en.yml b/config/locales/en.yml index a4dc2a3..63859ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,6 +6,7 @@ en: job_title : "Job Title" participator : "Participartor" project_category : "Project Category" + project_type: "Project Category" period : "Period" end_date : "End Date" start_date : "Start Date" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 361b8a9..52bf83c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -7,6 +7,7 @@ zh_tw: participator : "參與人" extracted_chapters : "Extracted Chapters" project_category : "計畫類別" + project_type : "計畫類別" period : "計畫期間" end_date : "結束日期" start_date : "開始日期"