From 63ec149248cf832ac51a6d72aaaac685804ab80c Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 26 Jul 2022 19:02:01 +0800 Subject: [PATCH] Update sort. --- app/controllers/admin/projects_controller.rb | 4 ++-- app/models/project.rb | 8 +++++--- app/views/plugin/personal_project/_profile.html.erb | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) 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? %> <% end -%> - <%= t('personal_project.year') %> + <%= t('personal_project.period') %> <%= t('personal_project.project_title') %> <%= t('personal_project.job_title') %> @@ -41,7 +41,7 @@ <%= check_box_tag 'to_change[]', project.id.to_s, false, :class => "list-check" %> <% end %> - <%= project.year %> + <%= project.duration %> <% link = OrbitHelper.url_to_plugin_show(project.to_param,'personal_project') %> <%= (link == "#" ? project.project_title : link_to(project.project_title, link , target: "blank")) %>