Update sort.

This commit is contained in:
BoHung Chiu 2022-07-26 19:02:01 +08:00
parent f66629b9e4
commit 63ec149248
3 changed files with 11 additions and 9 deletions

View File

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

View File

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

View File

@ -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? %>
<th><input type="checkbox" /></th>
<% end -%>
<th class="span2"><%= t('personal_project.year') %></th>
<th class="span2"><%= t('personal_project.period') %></th>
<th class="span4"><%= t('personal_project.project_title') %></th>
<th class="span4"><%= t('personal_project.job_title') %></th>
</tr>
@ -41,7 +41,7 @@
<%= check_box_tag 'to_change[]', project.id.to_s, false, :class => "list-check" %>
</td>
<% end %>
<td><%= project.year %></td>
<td><%= project.duration %></td>
<td>
<% link = OrbitHelper.url_to_plugin_show(project.to_param,'personal_project') %>
<%= (link == "#" ? project.project_title : link_to(project.project_title, link , target: "blank")) %>