widget data count and add old widget controller back
This commit is contained in:
parent
f22e8ee17f
commit
9461aeb279
|
@ -70,7 +70,6 @@ class ArchivesController < ApplicationController
|
|||
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
{
|
||||
"categories" => cats
|
||||
|
@ -88,43 +87,50 @@ class ArchivesController < ApplicationController
|
|||
render :nothing => true
|
||||
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"
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
||||
cats = files_by_cateogry.keys.collect do |cat|
|
||||
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags)
|
||||
|
||||
ts = []
|
||||
archive_counts = 0
|
||||
files_by_category_tag.keys.each do |t|
|
||||
archives = []
|
||||
archive_counts = archive_counts + 1
|
||||
files_by_category_tag[t].each_with_index do |archive,index|
|
||||
a = {
|
||||
"archive-title" => archive.title,
|
||||
"archive_url" => OrbitHelper.widget_more_url
|
||||
"archive_url" => OrbitHelper.url_to_show(archive.to_param)
|
||||
}
|
||||
|
||||
if t.count > 1
|
||||
t.each do |inner_tag|
|
||||
index = ts.index{|tot| tot["tag-name"] == inner_tag.name}
|
||||
if !index.nil?
|
||||
break if ts[index]["archives"].count >= OrbitHelper.widget_data_count
|
||||
ts[index]["archives"] << a
|
||||
else
|
||||
break if archives.count >= OrbitHelper.widget_data_count
|
||||
archives << a
|
||||
end
|
||||
end
|
||||
else
|
||||
break if archives.count >= OrbitHelper.widget_data_count
|
||||
archives << a
|
||||
end
|
||||
|
||||
end
|
||||
ts << {
|
||||
"tag-name" => (t[0].name rescue ""),
|
||||
"archives" => archives
|
||||
|
||||
} if !archives.blank?
|
||||
} if !archives.blank? && archive_counts < OrbitHelper.widget_data_count
|
||||
end
|
||||
{
|
||||
"category-title" => cat.title,
|
||||
|
@ -136,4 +142,39 @@ class ArchivesController < ApplicationController
|
|||
"extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url}
|
||||
}
|
||||
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
|
|
@ -1,4 +1,4 @@
|
|||
<%= render_filter @filter_fields, "index_table" %>
|
||||
<%= render_filter @filter_fields, "index_table" %>
|
||||
<div id="index_table">
|
||||
<%= render 'index'%>
|
||||
</div>
|
||||
</div>
|
|
@ -4,7 +4,7 @@ module Archive
|
|||
OrbitApp.registration "Archive", :type => "ModuleApp" do
|
||||
module_label "archive.archive"
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
widget_methods ["widget"]
|
||||
widget_methods ["widget","group_by_category"]
|
||||
widget_settings [{"data_count"=>30}]
|
||||
models_to_cache [:archive_file]
|
||||
taggable "ArchiveFile"
|
||||
|
|
Loading…
Reference in New Issue