2014-11-07 08:44:11 +00:00
|
|
|
class NewsController < ApplicationController
|
|
|
|
|
|
|
|
def index
|
|
|
|
params = OrbitHelper.params
|
|
|
|
news = nil
|
|
|
|
|
|
|
|
if params[:keywords]
|
2015-01-09 06:29:00 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
2014-12-30 01:50:33 +00:00
|
|
|
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
|
2015-01-09 07:23:26 +00:00
|
|
|
news_count = ",共有" + news.count.to_s + "筆資料"
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
|
2014-11-10 02:03:21 +00:00
|
|
|
elsif params[:department]
|
2015-01-09 06:29:00 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
2014-11-07 08:44:11 +00:00
|
|
|
dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil
|
2014-12-30 01:50:33 +00:00
|
|
|
news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
|
2015-01-09 07:23:26 +00:00
|
|
|
news_count = ",共有" + news.count.to_s + "筆資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
|
|
|
|
keywords = params[:department].split("-")
|
|
|
|
keywords.delete(keywords.last)
|
|
|
|
if keywords.kind_of?(Array)
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "列出由:" + keywords.join("-") + "發佈的資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
else
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "列出由:" + keywords + "發佈的資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
elsif params[:unit]
|
2014-11-07 08:44:11 +00:00
|
|
|
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
|
2015-01-09 06:29:00 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
2014-12-30 01:50:33 +00:00
|
|
|
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
|
2015-01-09 07:23:26 +00:00
|
|
|
news_count = ",共有" + news.count.to_s + "筆資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
|
|
|
|
keywords = params[:unit].split("-")
|
|
|
|
keywords.delete(keywords.last)
|
|
|
|
if keywords.kind_of?(Array)
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "列出由:" + keywords.join("-") + "發佈的資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
else
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "列出由:" + keywords + "發佈的資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
end
|
2014-11-07 08:44:11 +00:00
|
|
|
elsif params["category"]
|
2015-01-09 06:29:00 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
2014-11-07 08:44:11 +00:00
|
|
|
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
|
2014-12-30 01:50:33 +00:00
|
|
|
news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
|
2015-01-09 07:23:26 +00:00
|
|
|
news_count = ",共有" + news.count.to_s + "筆資料"
|
2014-11-10 02:03:21 +00:00
|
|
|
|
|
|
|
keywords = params[:category].split("-")
|
|
|
|
keywords.delete(keywords.last)
|
|
|
|
if keywords.kind_of?(Array)
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "搜尋有關 ' " + keywords.join("-") + " '"
|
2014-11-10 02:03:21 +00:00
|
|
|
else
|
2015-01-05 07:23:31 +00:00
|
|
|
keyword = "搜尋有關 ' " + keywords + " '"
|
2014-11-10 02:03:21 +00:00
|
|
|
end
|
2014-11-07 08:44:11 +00:00
|
|
|
end
|
2015-01-09 06:29:00 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
2014-12-30 01:50:33 +00:00
|
|
|
news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil?
|
2014-11-07 08:44:11 +00:00
|
|
|
page = Page.where(:module => "news").first rescue nil
|
2014-11-10 02:03:21 +00:00
|
|
|
ma = ModuleApp.find_by_key("news") rescue nil
|
2014-11-07 08:44:11 +00:00
|
|
|
categories = ma.categories.enabled.collect do |cat|
|
|
|
|
{
|
|
|
|
"category-name" => cat.title,
|
|
|
|
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
anns = news.collect do |a|
|
2015-01-12 06:40:36 +00:00
|
|
|
if a.image_description.nil?
|
|
|
|
image_description = "裝飾性圖片"
|
|
|
|
else
|
|
|
|
image_description = a.image_description
|
|
|
|
end
|
|
|
|
|
2014-11-07 08:44:11 +00:00
|
|
|
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,
|
|
|
|
"category" => a.category.title,
|
|
|
|
"postdate" => a.postdate.strftime('%Y-%m-%d'),
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
2014-11-11 08:31:16 +00:00
|
|
|
"img_src" => a.image.thumb.url || "/assets/news_default_image.jpg",
|
2015-01-12 06:40:36 +00:00
|
|
|
"img_description" => image_description,
|
2014-11-07 08:44:11 +00:00
|
|
|
"more" => t(:more_plus)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"news" => anns,
|
|
|
|
"categories" => categories,
|
|
|
|
"extras" => {
|
|
|
|
"categories-title" => t("news.categories"),
|
|
|
|
"widget-title" =>t('news.news'),
|
|
|
|
"title-head" => t('news.table.title'),
|
|
|
|
"date-head" => t('news.table.date'),
|
|
|
|
"status-head" => t('news.table.status'),
|
|
|
|
"subtitle-head" => t('news.table.sub_title'),
|
|
|
|
"category-head" => t('news.table.category'),
|
|
|
|
"news_count" => news_count,
|
|
|
|
"keyword" => keyword
|
|
|
|
},
|
|
|
|
"total_pages" => news.total_pages
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
2014-11-12 10:04:20 +00:00
|
|
|
params = OrbitHelper.params
|
2015-01-09 08:37:02 +00:00
|
|
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
|
|
|
|
news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:is_hot => true).is_approved.order_by(sort).filter_by_widget_categories if news.nil?
|
2014-11-13 02:05:41 +00:00
|
|
|
|
2014-11-07 08:44:11 +00:00
|
|
|
page = Page.where(:module => "news").first rescue nil
|
|
|
|
ma = ModuleApp.find_by_key("news") rescue nil
|
|
|
|
categories = ma.categories.enabled.collect do |cat|
|
|
|
|
{
|
|
|
|
"name" => cat.title,
|
|
|
|
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
categories.unshift({"name" => t("news.all"), "category-link" => "/#{I18n.locale.to_s + page.url}/"})
|
|
|
|
|
|
|
|
anns = news.collect do |a|
|
2015-01-12 06:40:36 +00:00
|
|
|
if a.image_description.nil?
|
|
|
|
image_description = "裝飾性圖片"
|
|
|
|
else
|
|
|
|
image_description = a.image_description
|
|
|
|
end
|
|
|
|
|
2014-11-07 08:44:11 +00:00
|
|
|
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,
|
|
|
|
"category" => a.category.title,
|
|
|
|
"postdate" => a.postdate,
|
|
|
|
"link_to_show" => OrbitHelper.widget_item_url(a.to_param),
|
2014-11-11 08:31:16 +00:00
|
|
|
"img_src" => a.image.thumb.url || "/assets/news_default_image.jpg",
|
2015-01-12 06:40:36 +00:00
|
|
|
"img_description" => image_description
|
2014-11-07 08:44:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"news" => anns,
|
|
|
|
"categories" => categories,
|
|
|
|
"extras" => {
|
|
|
|
"more_url"=>OrbitHelper.widget_more_url,
|
|
|
|
"title-head" => t('news.table.title'),
|
|
|
|
"date-head" => t('news.table.date'),
|
|
|
|
"status-head" => t('news.table.status'),
|
|
|
|
"subtitle-head" => t('news.table.sub_title'),
|
|
|
|
"category-head" => t('news.table.category')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
news = NewsBulletin.find_by(:uid=>params[:uid])
|
|
|
|
url_to_edit = OrbitHelper.user_can_edit?(news) ? "/admin/news/#{news.id.to_s}/edit" : ""
|
|
|
|
|
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
page = Page.where(:module => "news").first rescue nil
|
|
|
|
|
|
|
|
if !news.approved && (access_level != "manager" && access_level != "admin")
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
ma = ModuleApp.find_by_key("news") rescue nil
|
|
|
|
categories = ma.categories.enabled.collect do |cat|
|
|
|
|
{
|
|
|
|
"category-name" => cat.title,
|
|
|
|
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
tags = news.tags.map{|tag| {
|
|
|
|
"tag" => tag.name ,
|
|
|
|
"url" => OrbitHelper.page_for_tag(tag)
|
|
|
|
} } rescue []
|
|
|
|
files = news.news_bulletin_files.collect{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
|
|
|
|
links = news.news_bulletin_links.collect{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
|
|
|
update_user = news.update_user.member_profile.name rescue ""
|
|
|
|
department = news.department rescue ""
|
|
|
|
{
|
|
|
|
"tags" => tags,
|
|
|
|
"news_bulletin_files" => files,
|
|
|
|
"news_bulletin_links" => links,
|
|
|
|
"categories" => categories,
|
|
|
|
"data" => {
|
|
|
|
"categories-title" => t("news.categories"),
|
|
|
|
"title" => news.title,
|
|
|
|
"category" => news.category.title,
|
|
|
|
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{news.category.to_param}",
|
|
|
|
"unit" => news.unit.name,
|
|
|
|
"unit-link" => "/#{I18n.locale.to_s + page.url}/?unit=#{news.unit.to_param}",
|
|
|
|
"department" => (department.name rescue ""),
|
|
|
|
"department-link" => "/#{I18n.locale.to_s + page.url}/?department=#{(department.to_param rescue "")}",
|
|
|
|
"update_user" => update_user,
|
2014-12-29 08:09:44 +00:00
|
|
|
"updated_at" => news.postdate.strftime('%Y-%m-%d %H:%M'),
|
2014-11-12 10:04:20 +00:00
|
|
|
"body" => news.text == "" ? "Content unavailable for this language." : news.text,
|
2014-11-07 08:44:11 +00:00
|
|
|
"image" => news.image.url,
|
|
|
|
"view_count" =>news.view_count
|
|
|
|
},
|
|
|
|
"impressionist" => (news.is_preview ? nil : news),
|
|
|
|
"url_to_edit"=>url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|