widget data count and add old widget controller back

This commit is contained in:
Ruling-Mac 2015-08-18 17:57:16 +08:00
parent f22e8ee17f
commit 9461aeb279
3 changed files with 52 additions and 11 deletions

View File

@ -70,7 +70,6 @@ class ArchivesController < ApplicationController
} }
end end
end end
{ {
"categories" => cats "categories" => cats
@ -88,43 +87,50 @@ class ArchivesController < ApplicationController
render :nothing => true render :nothing => true
end end
def widget def group_by_category
cat_id = OrbitHelper.widget_categories.map {|cat_id| cat_id.to_s}
if OrbitHelper.widget_tags.first == "all" if OrbitHelper.widget_tags.first == "all"
files_by_cateogry = ArchiveFile.filter_by_widget_categories.with_tags(OrbitHelper.widget_module_app.tags.collect{|tag| tag.id.to_s}).group_by(&:category) files_by_cateogry = ArchiveFile.where(:category_id.in => OrbitHelper.widget_categories).with_tags(OrbitHelper.widget_module_app.tags.collect{|tag| tag.id.to_s}).group_by(&:category)
else else
files_by_cateogry = ArchiveFile.filter_by_widget_categories.with_tags(OrbitHelper.widget_tags).group_by(&:category) files_by_cateogry = ArchiveFile.where(:category_id.in => OrbitHelper.widget_categories).with_tags(OrbitHelper.widget_tags).group_by(&:category)
end end
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)
ts = [] ts = []
archive_counts = 0
files_by_category_tag.keys.each do |t| files_by_category_tag.keys.each do |t|
archives = [] archives = []
archive_counts = archive_counts + 1
files_by_category_tag[t].each_with_index do |archive,index| files_by_category_tag[t].each_with_index do |archive,index|
a = { a = {
"archive-title" => archive.title, "archive-title" => archive.title,
"archive_url" => OrbitHelper.widget_more_url "archive_url" => OrbitHelper.url_to_show(archive.to_param)
} }
if t.count > 1 if t.count > 1
t.each do |inner_tag| t.each do |inner_tag|
index = ts.index{|tot| tot["tag-name"] == inner_tag.name} index = ts.index{|tot| tot["tag-name"] == inner_tag.name}
if !index.nil? if !index.nil?
break if ts[index]["archives"].count >= OrbitHelper.widget_data_count
ts[index]["archives"] << a ts[index]["archives"] << a
else else
break if archives.count >= OrbitHelper.widget_data_count
archives << a archives << a
end end
end end
else else
break if archives.count >= OrbitHelper.widget_data_count
archives << a archives << a
end end
end end
ts << { ts << {
"tag-name" => (t[0].name rescue ""), "tag-name" => (t[0].name rescue ""),
"archives" => archives "archives" => archives
} if !archives.blank? && archive_counts < OrbitHelper.widget_data_count
} if !archives.blank?
end end
{ {
"category-title" => cat.title, "category-title" => cat.title,
@ -136,4 +142,39 @@ class ArchivesController < ApplicationController
"extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url} "extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url}
} }
end end
def widget
categories = OrbitHelper.widget_categories
@categories = []
if categories.first == "all"
module_app = OrbitHelper.widget_module_app
@categories = module_app.categories.collect do |cat|
{
"title" => cat.title,
"id" => cat.id.to_s
}
end
else
categories.each do |cat|
c = Category.find(cat)
@categories << {"title" => c.title, "id" => c.id.to_s}
end
end
cats = @categories.collect do |cat|
archives = ArchiveFile.can_display.where(:category_id => cat["id"]).collect do |archive|
{
"archive-title" => archive.title,
"archive_url" => OrbitHelper.widget_more_url
}
end
{
"category-title" => cat["title"],
"archives" => archives
}
end
{
"categories" => cats,
"extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url}
}
end
end end

View File

@ -1,4 +1,4 @@
<%= render_filter @filter_fields, "index_table" %> <%= render_filter @filter_fields, "index_table" %>
<div id="index_table"> <div id="index_table">
<%= render 'index'%> <%= render 'index'%>
</div> </div>

View File

@ -4,7 +4,7 @@ module Archive
OrbitApp.registration "Archive", :type => "ModuleApp" do OrbitApp.registration "Archive", :type => "ModuleApp" do
module_label "archive.archive" module_label "archive.archive"
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"] widget_methods ["widget","group_by_category"]
widget_settings [{"data_count"=>30}] widget_settings [{"data_count"=>30}]
models_to_cache [:archive_file] models_to_cache [:archive_file]
taggable "ArchiveFile" taggable "ArchiveFile"