From 8aa42bd5a19aa05cba213c17e9d1a171540ae719 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 1 Aug 2014 19:47:16 +0800 Subject: [PATCH] Update frontend --- .../personal_experiences_controller.rb | 62 +++++++++++-------- app/models/experience.rb | 31 ++++++++++ config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 4 files changed, 70 insertions(+), 25 deletions(-) diff --git a/app/controllers/personal_experiences_controller.rb b/app/controllers/personal_experiences_controller.rb index 272f154..97d19c3 100644 --- a/app/controllers/personal_experiences_controller.rb +++ b/app/controllers/personal_experiences_controller.rb @@ -28,32 +28,44 @@ class PersonalExperiencesController < ApplicationController def show params = OrbitHelper.params - experience = Experience.where(:is_hidden=>false).find_by(uid: params[:uid]) + plugin = Experience.where(:is_hidden=>false).find_by(uid: params[:uid]) + + fields_to_show = [ + "organizationt_title", + "department", + "job_title", + "experience_type", + "duration", + "keywords", + "url", + "note" + ] - { - "organizationt_title" => experience.organizationt_title, - "department" => experience.department, - "job_title" => experience.job_title, - "experience_type" => (experience.experience_type.title rescue ""), - "language" => t(experience.language), - "start_date" => experience.start_date, - "end_date" => experience.end_date, - "duration" => experience.duration, - "keywords" => experience.keywords, - "url" => experience.url, - "note" => experience.note, + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} + # { + # "organizationt_title" => experience.organizationt_title, + # "department" => experience.department, + # "job_title" => experience.job_title, + # "experience_type" => (experience.experience_type.title rescue ""), + # "language" => t(experience.language), + # "start_date" => experience.start_date, + # "end_date" => experience.end_date, + # "duration" => experience.duration, + # "keywords" => experience.keywords, + # "url" => experience.url, + # "note" => experience.note, - "th_organizationt_title" =>t("personal_experience.organizationt_title") , - "th_department" =>t("personal_experience.department") , - "th_job_title" =>t("personal_experience.job_title") , - "th_experience_type" =>t("personal_experience.experience_category") , - "th_language" =>t("personal_experience.language") , - "th_start_date" =>t("personal_experience.start_date") , - "th_end_date" =>t("personal_experience.end_date") , - "th_duration" =>t("personal_experience.duration") , - "th_keywords" =>t("personal_experience.keywords") , - "th_url" =>t("personal_experience.url") , - "th_note" =>t("personal_experience.note") - } + # "th_organizationt_title" =>t("personal_experience.organizationt_title") , + # "th_department" =>t("personal_experience.department") , + # "th_job_title" =>t("personal_experience.job_title") , + # "th_experience_type" =>t("personal_experience.experience_category") , + # "th_language" =>t("personal_experience.language") , + # "th_start_date" =>t("personal_experience.start_date") , + # "th_end_date" =>t("personal_experience.end_date") , + # "th_duration" =>t("personal_experience.duration") , + # "th_keywords" =>t("personal_experience.keywords") , + # "th_url" =>t("personal_experience.url") , + # "th_note" =>t("personal_experience.note") + # } end end \ No newline at end of file diff --git a/app/models/experience.rb b/app/models/experience.rb index 8335ed3..d76a0ab 100644 --- a/app/models/experience.rb +++ b/app/models/experience.rb @@ -37,6 +37,37 @@ class Experience [self.organizationt_title,self.department,self.job_title].join(' ') 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 "experience_type" + value = self.experience_type.title rescue "" + else + value = self.send(field) rescue "" + end + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + + { + "key"=>field, + "title_class"=>"experience-#{field.gsub('_','-')}-field", + "value_class"=>"experience-#{field.gsub('_','-')}-value", + "title"=>I18n.t('personal_experience.'+field), + "value"=>value + } + end + protected def add_http diff --git a/config/locales/en.yml b/config/locales/en.yml index 5af4c4a..e18040b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,6 +4,7 @@ en: personal_experience: department : "Department" experience_category : "Experience Category" + experience_type: "Experience Category" organizationt_title : "Organization Title" paper_title : "Paper Title" book_title : "Book Title" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 8f53501..1341b88 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -4,6 +4,7 @@ zh_tw: personal_experience: department : "單位" experience_category : 經歷類別 + experience_type: 經歷類別 end_date : "結束日期" start_date : "開始日期" duration: "期間"