From cd2865c6b851f69e222b0de59eb3200755b077e0 Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 12 Aug 2014 11:40:06 +0800 Subject: [PATCH] add new widget method --- app/controllers/announcements_controller.rb | 31 ++++++++++++++++++++- lib/announcement/engine.rb | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 9280860..0548bb5 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -44,7 +44,7 @@ class AnnouncementsController < ApplicationController "title" => a.title, "subtitle" => a.subtitle, "statuses" => statuses, - "postdate" => a.postdate.strftime("%b %d, %Y at %I:%M %p"), + "postdate" => a.postdate.strftime("%d"), "link_to_show" => OrbitHelper.widget_item_url(a.to_param), "img_src" => a.image.thumb.url || "http://placehold.it/100x100", } @@ -57,6 +57,35 @@ class AnnouncementsController < ApplicationController } end + def widget1 + announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags) + + anns = announcements.collect do |a| + statuses = a.statuses_with_classname.collect do |status| + { + "status" => status["name"], + "status-class" => "status-#{status['classname']}" + } + end + { + "title" => a.title, + "subtitle" => a.subtitle, + "statuses" => statuses, + "week" => a.postdate.strftime("%A"), + "day" => a.postdate.strftime("%d"), + "month" => a.postdate.strftime("%b"), + "year" => a.postdate.strftime("%Y"), + "link_to_show" => OrbitHelper.widget_item_url(a.to_param), + "img_src" => a.image.thumb.url || "http://placehold.it/100x100", + } + end + { + "announcements" => anns, + "extras" => { + "more_url"=>OrbitHelper.widget_more_url + } + } + end def show params = OrbitHelper.params diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 174c9ad..6cd2fdb 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -4,7 +4,7 @@ module Announcement OrbitApp.registration "Announcement", :type => "ModuleApp" do module_label "announcement.announcement" base_url File.expand_path File.dirname(__FILE__) - widget_methods ["widget"] + widget_methods ["widget","widget1"] widget_settings [{"data_count"=>10}] taggable "Bulletin" categorizable