modify the algo for tags group by for index and widget

This commit is contained in:
Ruling-Mac 2015-07-16 16:22:14 +08:00
parent 07a0b33a62
commit 7951358695
1 changed files with 10 additions and 47 deletions

View File

@ -1,31 +1,13 @@
class ArchivesController < ApplicationController class ArchivesController < ApplicationController
def index def index
categories = OrbitHelper.page_categories files_by_cateogry = ArchiveFile.filter_by_categories.filter_by_tags.group_by(&:category)
tags = OrbitHelper.page_tags
@tags = []
if tags.first == "all"
module_app = OrbitHelper.this_module_app
@tags = module_app.tags
else
tags.each do |tag|
@tags << Tag.find(tag)
end
end
files_by_cateogry = ArchiveFile.filter_by_categories.group_by(&:category)
cats = files_by_cateogry.keys.collect do |cat| cats = files_by_cateogry.keys.collect do |cat|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags) 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
url_to_edit = OrbitHelper.user_has_cateogry?(cat) ? "/admin/archive_files?filters[category][]=#{cat.id.to_s}" : ""
ts = files_by_category_tag.keys.collect do |t| 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}" : ""
archives = files_by_category_tag[t].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|
@ -57,20 +39,21 @@ class ArchivesController < ApplicationController
end end
{ {
"tag-name" => t[0].name, "tag-name" => t[0].name,
"archives" => archives, "archives" => archives
"url_to_edit" => url_to_edit
} }
end end
if(files_by_category_tag.empty?) if(files_by_category_tag.empty?)
{ {
"category-title" => "", "category-title" => "",
"tags" => ts "tags" => ts,
"link_to_edit" => url_to_edit
} }
else else
{ {
"category-title" => cat.title || "", "category-title" => cat.title || "",
"tags" => ts "tags" => ts,
"link_to_edit" => url_to_edit
} }
end end
@ -93,32 +76,12 @@ class ArchivesController < ApplicationController
end end
def widget def widget
categories = OrbitHelper.widget_categories files_by_cateogry = ArchiveFile.filter_by_widget_categories.with_tags(OrbitHelper.widget_tags).group_by(&:category)
@categories = []
tags = OrbitHelper.widget_tags
@tags = []
if tags.first == "all"
module_app = OrbitHelper.widget_module_app
@tags = module_app.tags
else
tags.each do |tag|
@tags << Tag.find(tag)
end
end
files_by_cateogry = ArchiveFile.filter_by_widget_categories.group_by(&:category)
cats = files_by_cateogry.keys.collect do |cat| cats = files_by_cateogry.keys.collect do |cat|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags) 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| ts = files_by_category_tag.keys.collect do |t|
archives = files_by_category_tag[t].collect do |archive| archives = files_by_category_tag[t].collect do |archive|