order by category and tags for index and widget fixed by alex
This commit is contained in:
parent
23022850eb
commit
07a0b33a62
|
@ -1,18 +1,33 @@
|
||||||
class ArchivesController < ApplicationController
|
class ArchivesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
categories = OrbitHelper.page_categories
|
categories = OrbitHelper.page_categories
|
||||||
@categories = []
|
tags = OrbitHelper.page_tags
|
||||||
if categories.first == "all"
|
@tags = []
|
||||||
|
|
||||||
|
if tags.first == "all"
|
||||||
module_app = OrbitHelper.this_module_app
|
module_app = OrbitHelper.this_module_app
|
||||||
@categories = module_app.categories
|
@tags = module_app.tags
|
||||||
else
|
else
|
||||||
categories.each do |cat|
|
tags.each do |tag|
|
||||||
@categories << Category.find(cat)
|
@tags << Tag.find(tag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cats = @categories.collect do |cat|
|
|
||||||
|
files_by_cateogry = ArchiveFile.filter_by_categories.group_by(&:category)
|
||||||
|
cats = files_by_cateogry.keys.collect do |cat|
|
||||||
|
|
||||||
|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags)
|
||||||
|
|
||||||
|
files_by_category_tag.keys.each do |f|
|
||||||
|
if(!@tags.include?(f[0]))
|
||||||
|
files_by_category_tag.delete(f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ts = files_by_category_tag.keys.collect do |t|
|
||||||
url_to_edit = OrbitHelper.user_has_cateogry?(cat) ? "/admin/archive_files?filters[category][]=#{cat.id.to_s}" : ""
|
url_to_edit = OrbitHelper.user_has_cateogry?(cat) ? "/admin/archive_files?filters[category][]=#{cat.id.to_s}" : ""
|
||||||
archives = ArchiveFile.where(:category_id => cat.id).order_by(:sort_number=>'asc').collect do |archive|
|
archives = files_by_category_tag[t].collect do |archive|
|
||||||
|
|
||||||
statuses = archive.statuses_with_classname.collect do |status|
|
statuses = archive.statuses_with_classname.collect do |status|
|
||||||
{
|
{
|
||||||
"status" => status["name"] || "",
|
"status" => status["name"] || "",
|
||||||
|
@ -41,11 +56,26 @@ class ArchivesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"category-title" => cat.title || "",
|
"tag-name" => t[0].name,
|
||||||
"archives" => archives,
|
"archives" => archives,
|
||||||
"url_to_edit" => url_to_edit
|
"url_to_edit" => url_to_edit
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
if(files_by_category_tag.empty?)
|
||||||
|
{
|
||||||
|
"category-title" => "",
|
||||||
|
"tags" => ts
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
"category-title" => cat.title || "",
|
||||||
|
"tags" => ts
|
||||||
|
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
{
|
{
|
||||||
"categories" => cats
|
"categories" => cats
|
||||||
}
|
}
|
||||||
|
@ -65,30 +95,47 @@ class ArchivesController < ApplicationController
|
||||||
def widget
|
def widget
|
||||||
categories = OrbitHelper.widget_categories
|
categories = OrbitHelper.widget_categories
|
||||||
@categories = []
|
@categories = []
|
||||||
if categories.first == "all"
|
|
||||||
|
tags = OrbitHelper.widget_tags
|
||||||
|
@tags = []
|
||||||
|
|
||||||
|
|
||||||
|
if tags.first == "all"
|
||||||
module_app = OrbitHelper.widget_module_app
|
module_app = OrbitHelper.widget_module_app
|
||||||
@categories = module_app.categories.collect do |cat|
|
@tags = module_app.tags
|
||||||
{
|
|
||||||
"title" => cat.title,
|
|
||||||
"id" => cat.id.to_s
|
|
||||||
}
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
categories.each do |cat|
|
tags.each do |tag|
|
||||||
c = Category.find(cat)
|
@tags << Tag.find(tag)
|
||||||
@categories << {"title" => c.title, "id" => c.id.to_s}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cats = @categories.collect do |cat|
|
|
||||||
archives = ArchiveFile.can_display.where(:category_id => cat["id"]).collect do |archive|
|
files_by_cateogry = ArchiveFile.filter_by_widget_categories.group_by(&:category)
|
||||||
|
|
||||||
|
cats = files_by_cateogry.keys.collect do |cat|
|
||||||
|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags)
|
||||||
|
|
||||||
|
files_by_category_tag.keys.each do |f|
|
||||||
|
if(!@tags.include?(f[0]))
|
||||||
|
files_by_category_tag.delete(f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ts = files_by_category_tag.keys.collect do |t|
|
||||||
|
archives = files_by_category_tag[t].collect do |archive|
|
||||||
{
|
{
|
||||||
"archive-title" => archive.title,
|
"archive-title" => archive.title,
|
||||||
"archive_url" => OrbitHelper.widget_more_url
|
"archive_url" => OrbitHelper.widget_more_url
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"category-title" => cat["title"],
|
"tag-name" => t[0].name,
|
||||||
"archives" => archives
|
"archives" => archives
|
||||||
|
|
||||||
|
}
|
||||||
|
end
|
||||||
|
{
|
||||||
|
"category-title" => cat.title,
|
||||||
|
"tags" => ts
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue