161 lines
7.0 KiB
Ruby
161 lines
7.0 KiB
Ruby
class AnnouncementsController < ApplicationController
|
|
|
|
def index
|
|
if !OrbitHelper.params['tags'].blank?
|
|
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_tags(OrbitHelper.params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
|
|
else
|
|
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_categories.filter_by_tags
|
|
end
|
|
|
|
anns = announcements.collect do |a|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
{
|
|
"status" => status["name"],
|
|
"status-class" => "status-#{status['classname']}"
|
|
}
|
|
end
|
|
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
|
|
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
|
author = User.find(a.create_user_id).member_profile.name rescue ""
|
|
desc = a.image_description
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
|
{
|
|
"bulletin_links" => links,
|
|
"bulletin_files" => files,
|
|
"title" => a.title,
|
|
"subtitle" => a.subtitle,
|
|
"statuses" => statuses,
|
|
"category" => a.category.title,
|
|
"postdate" => a.postdate,
|
|
"author" => author,
|
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
|
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
|
"img_description" => desc,
|
|
"more" => t(:more_plus),
|
|
"view_count" => a.view_count
|
|
}
|
|
end
|
|
|
|
#If no data , hide title&table
|
|
if announcements.count == 0
|
|
display = "hide"
|
|
end
|
|
|
|
{
|
|
"announcements" => anns,
|
|
"extras" => {
|
|
"widget-title" =>t('announcement.announcement'),
|
|
"title-head" => t('announcement.table.title'),
|
|
"date-head" => t('announcement.table.date'),
|
|
"status-head" => t('announcement.table.status'),
|
|
"author-head" => t('announcement.table.author'),
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
"category-head" => t('announcement.table.category'),
|
|
"link-head" => t('announcement.table.link'),
|
|
"file-head" => t('announcement.table.file'),
|
|
"view-count-head" => t('announcement.table.view_count'),
|
|
"display" => display
|
|
},
|
|
"total_pages" => announcements.total_pages
|
|
}
|
|
|
|
end
|
|
|
|
def widget
|
|
tags = ["all"] if OrbitHelper.widget_tags.empty?
|
|
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_widget_categories.filter_by_tags(tags)
|
|
page = Page.where(:module => "announcement").first rescue nil
|
|
anns = announcements.collect do |a|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
{
|
|
"status" => status["name"],
|
|
"status-class" => "status-#{status['classname']}"
|
|
}
|
|
end
|
|
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
|
|
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
|
author = User.find(a.create_user_id).member_profile.name rescue ""
|
|
desc = a.image_description
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
|
{
|
|
"bulletin_links" => links,
|
|
"bulletin_files" => files,
|
|
"title" => a.title,
|
|
"subtitle" => a.subtitle,
|
|
"statuses" => statuses,
|
|
"category" => a.category.title,
|
|
"postdate" => a.postdate,
|
|
"author" => author,
|
|
"link_to_show" => OrbitHelper.widget_item_url(a.to_param),
|
|
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
|
"img_description" => desc
|
|
}
|
|
end
|
|
mp = (anns[0]["img_src"] rescue "")
|
|
mpd = (anns[0]["img_description"] rescue "")
|
|
{
|
|
"announcements" => anns,
|
|
"extras" => {
|
|
"more_url"=>OrbitHelper.widget_more_url,
|
|
"main_picture" => mp,
|
|
"main_picture_description" => mpd,
|
|
"title-head" => t('announcement.table.title'),
|
|
"date-head" => t('announcement.table.date'),
|
|
"author-head" => t('announcement.table.author'),
|
|
"status-head" => t('announcement.table.status'),
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
"category-head" => t('announcement.table.category'),
|
|
"link-head" => t('announcement.table.link'),
|
|
"file-head" => t('announcement.table.file'),
|
|
"read_more" => ("/#{I18n.locale.to_s + page.url}" rescue "")
|
|
}
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
|
|
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
if !announcement.approved && (access_level != "manager" && access_level != "admin")
|
|
return {}
|
|
end
|
|
|
|
return {} if announcement.category.disable
|
|
|
|
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 '') } } 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 ""
|
|
desc = announcement.image_description
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
|
|
|
request = OrbitHelper.request
|
|
meta_desc = announcement.subtitle.nil? || announcement.subtitle == "" ? announcement.text[0..200] : announcement.subtitle
|
|
OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => announcement.title},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => "#{request.base_url}#{announcement.image.url}"},{"property" => "og:type", "content" => "Article"}])
|
|
|
|
{
|
|
"tags" => tags,
|
|
"bulletin_files" => files,
|
|
"bulletin_links" => links,
|
|
"data" => {
|
|
"title" => announcement.title,
|
|
"update_user" => update_user,
|
|
"updated_at" => announcement.postdate.strftime('%Y-%m-%d %H:%M'),
|
|
"body" =>announcement.text,
|
|
"image" => announcement.image.url,
|
|
"alt_title" => desc
|
|
},
|
|
"impressionist" => (announcement.is_preview ? nil : announcement),
|
|
"url_to_edit"=>url_to_edit
|
|
}
|
|
end
|
|
|
|
end
|