announcement-test/app/controllers/announcements_controller.rb

81 lines
2.8 KiB
Ruby

class AnnouncementsController < ApplicationController
def index
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_categories
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,
"postdate" => a.postdate.strftime("%b %d, %Y at %I:%M %p"),
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
"more" => "More"
}
end
{
"announcements" => anns,
"extras" => {"widget-title"=>"Announcements"},
"total_pages" => announcements.total_pages
}
end
def widget
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories
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,
"postdate" => a.postdate.strftime("%b %d, %Y at %I:%M %p"),
"link_to_show" => OrbitHelper.widget_item_url(a.to_param),
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
}
end
{
"announcements" => anns,
"extras" => {"widget-title"=>"Announcements","more_url"=>OrbitHelper.widget_more_url}
}
end
def show
params = OrbitHelper.params
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
tags = announcement.tags.map{|tag| { "tag" => tag.name } } rescue []
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
update_user = announcement.update_user.member_profile.name rescue ""
# announcement.destroy if announcement.is_preview
{
"tags" => tags,
"bulletin_files" => files,
"bulletin_links" => links,
"data" => {
"title" => announcement.title,
"update_user" => update_user,
"updated_at" => announcement.updated_at.strftime('%Y-%m-%d %H:%M'),
"body" =>announcement.text,
"image" => announcement.image.url
},
"impressionist" => (announcement.is_preview ? nil : announcement)
}
end
end