diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index e80f8a2..46af582 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -25,7 +25,7 @@ class Admin::ProjectsController < OrbitMemberController redirect_to :action=> 'index' end def merge - @projects=Project.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:project_title],v[:unit]]} + @projects=Project.sort_date.map{|value| value}.group_by{|v| [v[:project_title],v[:unit]]} @projects.each do |key,value| if value.length<=1 @projects.delete key @@ -48,7 +48,7 @@ class Admin::ProjectsController < OrbitMemberController end def index - @projects = Project.order_by(:period_start_date=>'desc',:year=>'desc').page(params[:page]).per(10) + @projects = Project.sort_date.page(params[:page]).per(10) end def new diff --git a/app/models/project.rb b/app/models/project.rb index 9859921..70717ac 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -34,7 +34,9 @@ class Project before_validation :add_http - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc', :period_start_date=>'desc') } + index({period_start_date: -1, _id: -1}, { unique: false, background: false }) + scope :sort_date, ->{ order_by(:period_start_date=>'desc', :id => 'desc') } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:period_start_date=>'desc', :id => 'desc') } def duration if !self.send('period_start_date').nil? or !self.send('period_end_date').nil? @@ -81,7 +83,7 @@ class Project fields_to_show = fields_to_show - fields_to_remove - plugin_datas = datas.sort_for_frontend.collect.with_index do |p,index| + plugin_datas = datas.sort_for_frontend.collect.with_index do |p,idx| pd_data = [] fields_to_show.collect do |t| @@ -102,7 +104,7 @@ class Project { "pd_datas" => pd_data, "type-sort" => (p.project_type.sort_position.to_i rescue 1000), - "sort-index" => index + "sort-index" => idx } end diff --git a/app/views/plugin/personal_project/_profile.html.erb b/app/views/plugin/personal_project/_profile.html.erb index 54e1c3b..3a67315 100644 --- a/app/views/plugin/personal_project/_profile.html.erb +++ b/app/views/plugin/personal_project/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @projects = Project.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @projects = Project.where(member_profile_id: @member.id).sort_date.page(params[:page]).per(10) else - @projects = Project.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @projects = Project.where(is_hidden: false, member_profile_id: @member.id).sort_date.page(params[:page]).per(10) end %> @@ -28,7 +28,7 @@ <% if has_access? %>