announcement-test/app/controllers/announcements_controller.rb

156 lines
5.4 KiB
Ruby
Raw Normal View History

2014-04-01 07:12:43 +00:00
class AnnouncementsController < ApplicationController
def index
2014-07-11 10:30:52 +00:00
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
2014-05-01 09:28:20 +00:00
anns = announcements.collect do |a|
2014-06-18 09:59:03 +00:00
statuses = a.statuses_with_classname.collect do |status|
2014-06-06 09:48:33 +00:00
{
2014-06-18 09:59:03 +00:00
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
2014-06-06 09:48:33 +00:00
}
end
2014-05-01 09:28:20 +00:00
{
"title" => a.title,
"subtitle" => a.subtitle,
2014-06-06 09:48:33 +00:00
"statuses" => statuses,
2014-09-12 03:02:56 +00:00
2014-05-14 11:51:17 +00:00
"postdate" => a.postdate.strftime("%b %d, %Y at %I:%M %p"),
2014-09-12 03:02:56 +00:00
"date" => a.postdate.strftime("%F"),
"year" => a.postdate.strftime("%Y"),
"month" => a.postdate.strftime("%b"),
"month-num" => a.postdate.strftime("%m"),
"week" => a.postdate.strftime("%A"),
"week-num" => a.postdate.strftime("%u"),
"day" => a.postdate.strftime("%d"),
"hour" => a.postdate.strftime("%H"),
"minute" => a.postdate.strftime("%M"),
"second" => a.postdate.strftime("%S"),
"meridian" => a.postdate.strftime("%p"),
2014-05-01 09:28:20 +00:00
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
2014-05-14 11:51:17 +00:00
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
2014-07-11 10:30:52 +00:00
"more" => t(:more_plus)
2014-05-01 09:28:20 +00:00
}
2014-04-01 07:12:43 +00:00
end
2014-04-02 06:44:36 +00:00
{
2014-05-14 11:51:17 +00:00
"announcements" => anns,
2014-07-11 10:30:52 +00:00
"extras" => {
"widget-title"=>t('announcement.announcement')
},
"total_pages" => announcements.total_pages
2014-04-02 06:44:36 +00:00
}
2014-04-01 07:12:43 +00:00
end
def widget
2014-07-11 10:30:52 +00:00
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)
2014-04-02 06:44:36 +00:00
anns = announcements.collect do |a|
2014-06-18 09:59:03 +00:00
statuses = a.statuses_with_classname.collect do |status|
2014-06-06 09:48:33 +00:00
{
2014-06-18 09:59:03 +00:00
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
2014-06-06 09:48:33 +00:00
}
end
2014-04-01 07:12:43 +00:00
{
"title" => a.title,
2014-05-01 09:28:20 +00:00
"subtitle" => a.subtitle,
2014-06-06 09:48:33 +00:00
"statuses" => statuses,
2014-09-12 03:02:56 +00:00
2014-08-12 03:40:06 +00:00
"postdate" => a.postdate.strftime("%d"),
2014-09-12 03:02:56 +00:00
"date" => a.postdate.strftime("%F"),
"year" => a.postdate.strftime("%Y"),
"month" => a.postdate.strftime("%b"),
"month-num" => a.postdate.strftime("%m"),
"week" => a.postdate.strftime("%A"),
"week-num" => a.postdate.strftime("%u"),
"day" => a.postdate.strftime("%d"),
"hour" => a.postdate.strftime("%H"),
"minute" => a.postdate.strftime("%M"),
"second" => a.postdate.strftime("%S"),
"meridian" => a.postdate.strftime("%p"),
2014-05-24 11:36:23 +00:00
"link_to_show" => OrbitHelper.widget_item_url(a.to_param),
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
2014-04-01 07:12:43 +00:00
}
end
2014-04-02 06:44:36 +00:00
{
"announcements" => anns,
2014-07-11 10:30:52 +00:00
"extras" => {
"more_url"=>OrbitHelper.widget_more_url
}
2014-04-02 06:44:36 +00:00
}
2014-04-01 07:12:43 +00:00
end
2014-08-12 03:40:06 +00:00
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,
2014-09-12 03:02:56 +00:00
"postdate" => a.postdate.strftime("%d"),
"date" => a.postdate.strftime("%F"),
"year" => a.postdate.strftime("%Y"),
"month" => a.postdate.strftime("%b"),
"month-num" => a.postdate.strftime("%m"),
2014-08-12 03:40:06 +00:00
"week" => a.postdate.strftime("%A"),
2014-09-12 03:02:56 +00:00
"week-num" => a.postdate.strftime("%u"),
2014-08-12 03:40:06 +00:00
"day" => a.postdate.strftime("%d"),
2014-09-12 03:02:56 +00:00
"hour" => a.postdate.strftime("%H"),
"minute" => a.postdate.strftime("%M"),
"second" => a.postdate.strftime("%S"),
"meridian" => a.postdate.strftime("%p"),
2014-08-12 03:40:06 +00:00
"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
2014-04-01 07:12:43 +00:00
def show
params = OrbitHelper.params
2014-05-02 10:21:51 +00:00
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
2014-05-05 07:48:49 +00:00
2014-08-05 06:37:33 +00:00
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
2014-07-11 10:30:52 +00:00
tags = announcement.tags.map{|tag| {
"tag" => tag.name ,
"url" => OrbitHelper.page_for_tag(tag)
} } 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 []
2014-05-14 11:51:17 +00:00
update_user = announcement.update_user.member_profile.name rescue ""
2014-05-05 07:48:49 +00:00
{
"tags" => tags,
2014-05-05 07:48:49 +00:00
"bulletin_files" => files,
"bulletin_links" => links,
"data" => {
2014-05-02 10:21:51 +00:00
"title" => announcement.title,
2014-05-14 11:51:17 +00:00
"update_user" => update_user,
"updated_at" => announcement.updated_at.strftime('%Y-%m-%d %H:%M'),
2014-05-05 07:48:49 +00:00
"body" =>announcement.text,
"image" => announcement.image.url
2014-05-15 11:27:05 +00:00
},
2014-08-05 06:37:33 +00:00
"impressionist" => (announcement.is_preview ? nil : announcement),
"url_to_edit"=>url_to_edit
2014-05-05 07:48:49 +00:00
}
2014-06-17 10:46:52 +00:00
end
2014-04-02 06:44:36 +00:00
2014-04-01 07:12:43 +00:00
end