From b81faab88710a57faa444da9898161c87e32e68a Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 2 Dec 2015 18:31:53 +0800 Subject: [PATCH] sort and date fixed --- .../{jquery-ui.min.js => jquery-ui-sortable.min.js} | 0 app/controllers/admin/experiences_controller.rb | 2 +- app/models/experience.rb | 10 ++++++---- app/views/admin/experiences/_form.html.erb | 4 ++-- app/views/admin/experiences/setting.html.erb | 2 +- app/views/plugin/personal_experience/_profile.html.erb | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) rename app/assets/javascripts/personal_experience/{jquery-ui.min.js => jquery-ui-sortable.min.js} (100%) diff --git a/app/assets/javascripts/personal_experience/jquery-ui.min.js b/app/assets/javascripts/personal_experience/jquery-ui-sortable.min.js similarity index 100% rename from app/assets/javascripts/personal_experience/jquery-ui.min.js rename to app/assets/javascripts/personal_experience/jquery-ui-sortable.min.js diff --git a/app/controllers/admin/experiences_controller.rb b/app/controllers/admin/experiences_controller.rb index e8352cd..8d7c66a 100644 --- a/app/controllers/admin/experiences_controller.rb +++ b/app/controllers/admin/experiences_controller.rb @@ -147,7 +147,7 @@ class Admin::ExperiencesController < OrbitMemberController uid = path[-2].split("-").last uid = uid.split("?").first end - @experience = Experience.find_by(:uid => uid) rescue Experience.find("53c4fd3548345219f04c0000") + @experience = Experience.find_by(:uid => uid) rescue Experience.find(params[:id]) end def find_experience diff --git a/app/models/experience.rb b/app/models/experience.rb index b4b6a57..7241401 100644 --- a/app/models/experience.rb +++ b/app/models/experience.rb @@ -25,6 +25,8 @@ class Experience before_validation :add_http + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:start_date=>'desc', :end_date => "asc") } + def duration if !self.start_date.nil? or !self.end_date.nil? (self.start_date.strftime('%Y.%m') rescue "")+' ~ '+(self.end_date.strftime('%Y.%m') rescue I18n.t('personal_experience.up_to_today')) @@ -40,10 +42,10 @@ class Experience def self.get_plugin_datas_to_member(datas) fields_to_show = [ + "experience_type", "organizationt_title", "department", "job_title", - "experience_type", "duration" ] @@ -53,7 +55,7 @@ class Experience } end - plugin_datas = datas.where(:is_hidden=>false).order_by(:end_date=>'desc', :start_date=>'desc').collect do |p| + plugin_datas = datas.sort_for_frontend.collect do |p| pd_data = [] fields_to_show.collect do |t| @@ -68,7 +70,7 @@ class Experience end pd_data << { "data_title" => date } elsif t == "experience_type" - pd_data << {"data_title" => p.experience_type.title} + pd_data << {"data_title" => (p.experience_type.title rescue "")} else pd_data << { "data_title" => p.send(t) } end @@ -76,7 +78,7 @@ class Experience { "pd_datas" => pd_data, - "type-sort" => p.experience_type.sort_position + "type-sort" => (p.experience_type.sort_position rescue 1000) } end diff --git a/app/views/admin/experiences/_form.html.erb b/app/views/admin/experiences/_form.html.erb index fc131fc..cb61eef 100644 --- a/app/views/admin/experiences/_form.html.erb +++ b/app/views/admin/experiences/_form.html.erb @@ -133,7 +133,7 @@
- <%= f.datetime_picker :start_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM" %> + <%= f.datetime_picker :start_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM", :value => @experience.start_date, :new_record => @experience.new_record? %>
@@ -141,7 +141,7 @@
- <%= f.datetime_picker :end_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM" %> + <%= f.datetime_picker :end_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM", :value => @experience.end_date, :new_record => @experience.new_record? %>
diff --git a/app/views/admin/experiences/setting.html.erb b/app/views/admin/experiences/setting.html.erb index 2f3ed75..f359fa0 100644 --- a/app/views/admin/experiences/setting.html.erb +++ b/app/views/admin/experiences/setting.html.erb @@ -1,5 +1,5 @@ <% content_for :page_specific_javascript do %> - <%= javascript_include_tag "personal_experience/jquery-ui.min" %> + <%= javascript_include_tag "lib/jquery-ui-sortable.min" %> <% end %>