From 1c7a27bfe44555917140f02ea318f6489d7f351f Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 23 May 2014 14:00:49 +0800 Subject: [PATCH] added widget and changed engine settings --- app/controllers/archives_controller.rb | 35 +++++++++++++++++++++++++- lib/archive/engine.rb | 5 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index a2ffd5d..a9332c4 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -4,7 +4,6 @@ class ArchivesController < ApplicationController @categories = [] if categories.first == "all" module_app = OrbitHelper.this_module_app - # debugger @categories = module_app.categories.collect do |cat| { "title" => cat.title, @@ -47,4 +46,38 @@ class ArchivesController < ApplicationController "extras" => {"widget-title" => "Archives"} } 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.where(:category_id => cat["id"]).collect do |archive| + { + "archive-title" => archive.title + } + end + { + "category-title" => cat["title"], + "archives" => archives + } + end + { + "categories" => cats, + "extras" => {"widget-title" => "Archives"} + } + end end \ No newline at end of file diff --git a/lib/archive/engine.rb b/lib/archive/engine.rb index 423e2ea..1b2ecfd 100644 --- a/lib/archive/engine.rb +++ b/lib/archive/engine.rb @@ -4,11 +4,12 @@ module Archive OrbitApp.registration "Archive", :type => "ModuleApp" do module_label "archive.archive" base_url File.expand_path File.dirname(__FILE__) - + widget_methods ["widget"] + widget_settings [{"data_count"=>10}] taggable "ArchiveFile" categorizable authorizable - + frontend_enabled side_bar do head_label_i18n 'archive.archive', icon_class: "icons-archive" available_for [:admin,:manager,:sub_manager]