Add sort order hint.

This commit is contained in:
BoHung Chiu 2022-05-23 00:19:51 +08:00
parent 974cde8761
commit c5b4bfb735
5 changed files with 26 additions and 4 deletions

View File

@ -128,8 +128,8 @@ class ArchiveFile
a.instance_variable_set(:@skip_callback, true)
self.where(:id=>a.id).update_all(:tmp_sort_number => i)
end
max_sort_number = (sorted_archives.count != 0) ? (sort_order == 1 ? sorted_archives.last.tmp_sort_number : sorted_archives.first.tmp_sort_number) : 0
ArchiveSortOrder.update_all(:max_sort_number=>max_sort_number,:need_update_sort=>false)
min_sort_number, max_sort_number = (sorted_archives.count != 0) ? (sorted_archives.map{|a| a.sort_number.to_i}.minmax) : [0, 0]
ArchiveSortOrder.update_all(:min_sort_number=>min_sort_number,:max_sort_number=>max_sort_number,:need_update_sort=>false)
self.create_indexes
return max_sort_number
end

View File

@ -2,6 +2,7 @@ class ArchiveSortOrder
include Mongoid::Document
field :sort_order, :type => Boolean # true => asc , false => desc
field :need_update_sort, :type => Boolean, :default => true
field :min_sort_number, :type => Integer, :default => 0
field :max_sort_number, :type => Integer, :default => 0
after_initialize do |record|
if(!record.new_record? && record.sort_order.nil?)
@ -44,6 +45,6 @@ class ArchiveSortOrder
end
end
def get_default_order
self.sort_order ? 0 : self.max_sort_number
self.sort_order ? self.min_sort_number : self.max_sort_number
end
end

View File

@ -16,7 +16,11 @@
<%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "lib/jquery-ui-sortable.min" %>
<% end %>
<%
sort_order = ArchiveSortOrder.first
min_sort_number = sort_order.min_sort_number
max_sort_number = sort_order.max_sort_number
%>
<%#= f.error_messages %>
<style>
#fileupload {
@ -88,6 +92,15 @@
<div class="controls">
<% extra_data = f.object.new_record? ? {placeholder: f.object.sort_number, title: f.object.sort_number, value: ''} : {} %>
<%= f.number_field :sort_number, extra_data %>
<p class="muted">
<% if sort_order.sort_order %>
<%= t("archive.ascending") %>
<% else %>
<%= t("archive.decending") %>
<% end %>
; <%= t('default') %>: <%= sort_order.get_default_order %>
</p>
<p class="muted"><%= t('archive.min') %>: <%=min_sort_number%>, <%= t('archive.max') %>: <%=max_sort_number%></p>
</div>
</div>

View File

@ -2,6 +2,10 @@ en:
restful_actions:
categories_order: Categories Order
archive:
min: "Min"
max: "Max"
ascending: "Ascending(smallest one is first order)"
descending: "Descending(biggest is first order)"
back_to_index_page: "Back to Index Page"
delete_selected: "Delete Selected"
feed_name: Feed Name

View File

@ -2,6 +2,10 @@ zh_tw:
restful_actions:
categories_order: 類別排序
archive:
min: "最小值"
max: "最大值"
ascending: "升序排列(小的排在最前面)"
descending: "降序排列(大的排在最前面)"
back_to_index_page: "返回列表頁"
delete_selected: "刪除所選"
feed_name: Feed 標題