Update frontend

This commit is contained in:
manson 2014-08-01 19:49:10 +08:00
parent 40eea87a01
commit 26418ef119
4 changed files with 101 additions and 41 deletions

View File

@ -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

View File

@ -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 << "<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"=>"project-#{field.gsub('_','-')}-field",
"value_class"=>"project-#{field.gsub('_','-')}-value",
"title"=>I18n.t('personal_project.'+field),
"value"=>value
}
end
protected

View File

@ -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"

View File

@ -7,6 +7,7 @@ zh_tw:
participator : "參與人"
extracted_chapters : "Extracted Chapters"
project_category : "計畫類別"
project_type : "計畫類別"
period : "計畫期間"
end_date : "結束日期"
start_date : "開始日期"