fix sort order
This commit is contained in:
parent
2fcfe60017
commit
41e54c2f4d
|
@ -1,5 +1,11 @@
|
||||||
class ArchivesController < ApplicationController
|
class ArchivesController < ApplicationController
|
||||||
#avoid the categories to be not in the ArchiveCategory
|
#avoid the categories to be not in the ArchiveCategory
|
||||||
|
before_action :set_archive_sort_order, only: [:index, :widget]
|
||||||
|
def set_archive_sort_order
|
||||||
|
if ArchiveSortOrder.count == 0
|
||||||
|
ArchiveSortOrder.new('sort_order' => false).save
|
||||||
|
end
|
||||||
|
end
|
||||||
def serve_cmap
|
def serve_cmap
|
||||||
serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__)
|
serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__)
|
||||||
if Dir.glob(serve_path).length != 0
|
if Dir.glob(serve_path).length != 0
|
||||||
|
@ -9,9 +15,6 @@ class ArchivesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def index
|
def index
|
||||||
if ArchiveSortOrder.count == 0
|
|
||||||
ArchiveSortOrder.new('sort_order' => false).save
|
|
||||||
end
|
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
if !params['title'].nil?
|
if !params['title'].nil?
|
||||||
files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category)
|
files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category)
|
||||||
|
@ -118,15 +121,6 @@ class ArchivesController < ApplicationController
|
||||||
"url_to_edit" => url_to_edit
|
"url_to_edit" => url_to_edit
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if ArchiveSortOrder.first['sort_order'] #Order with ascending
|
|
||||||
cats = cats.collect do |cat|
|
|
||||||
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
cats = cats.collect do |cat|
|
|
||||||
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : -tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if params[:data_count].to_i <=0
|
if params[:data_count].to_i <=0
|
||||||
page_data_count = 0
|
page_data_count = 0
|
||||||
else
|
else
|
||||||
|
@ -271,9 +265,6 @@ class ArchivesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
def widget
|
||||||
if ArchiveSortOrder.count == 0
|
|
||||||
ArchiveSortOrder.new('sort_order' => false).save
|
|
||||||
end
|
|
||||||
page_data_count = OrbitHelper.widget_data_count
|
page_data_count = OrbitHelper.widget_data_count
|
||||||
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
||||||
@categories = []
|
@categories = []
|
||||||
|
@ -296,7 +287,7 @@ class ArchivesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cats = @categories.collect do |cat|
|
cats = @categories.collect do |cat|
|
||||||
if ArchiveSortOrder.first['sort_order'] #Order with ascending
|
if ArchiveSortOrder.first.sort_order #Order with ascending
|
||||||
archives_all = ArchiveFile.can_display.where(:category_id => cat["id"]).filter_by_tags(OrbitHelper.widget_tags)
|
archives_all = ArchiveFile.can_display.where(:category_id => cat["id"]).filter_by_tags(OrbitHelper.widget_tags)
|
||||||
temp_with_nil = archives_all.in(sort_number: nil).order_by(created_at: 'desc')
|
temp_with_nil = archives_all.in(sort_number: nil).order_by(created_at: 'desc')
|
||||||
temp_no_nil = archives_all.not_in(sort_number: nil).order_by(sort_number: 'asc',created_at: 'desc')
|
temp_no_nil = archives_all.not_in(sort_number: nil).order_by(sort_number: 'asc',created_at: 'desc')
|
||||||
|
@ -342,7 +333,8 @@ class ArchivesController < ApplicationController
|
||||||
private
|
private
|
||||||
def get_sorted_cat_with_filter(categories,cat_type)
|
def get_sorted_cat_with_filter(categories,cat_type)
|
||||||
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil).uniq{|c| c.category_id }.to_a rescue []
|
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil).uniq{|c| c.category_id }.to_a rescue []
|
||||||
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: 'desc').uniq{|c| c.category_id }.to_a rescue []
|
sort_method = ArchiveSortOrder.first.sort_order ? 'asc' : 'desc'
|
||||||
|
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: sort_method).uniq{|c| c.category_id }.to_a rescue []
|
||||||
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
||||||
cat.category_id.to_s
|
cat.category_id.to_s
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue