First version of new feed for announcement
This commit is contained in:
parent
88861985c6
commit
9da9284a7f
|
@ -7,8 +7,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
# before_filter :for_admin_only,:only => [:]
|
# before_filter :for_admin_only,:only => [:]
|
||||||
# before_filter :for_app_manager,:only => [:index,:show,]
|
# before_filter :for_app_manager,:only => [:index,:show,]
|
||||||
before_filter :force_order_for_visitor,:only=>[:index,:show,:get_sorted_and_filtered_bulletins]
|
before_filter :force_order_for_visitor,:only=>[:index,:show,:get_sorted_and_filtered_bulletins]
|
||||||
before_filter :force_order_for_user,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
|
before_filter :force_order_for_user,:except => [:index,:show,:get_sorted_and_filtered_bulletins, :get_bulletins_as_json]
|
||||||
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
|
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins, :get_bulletins_as_json]
|
||||||
|
|
||||||
before_filter :only => [ :new,:create,:edit,:update,:create] do |controller|
|
before_filter :only => [ :new,:create,:edit,:update,:create] do |controller|
|
||||||
controller.get_categorys('BulletinCategory')
|
controller.get_categorys('BulletinCategory')
|
||||||
|
@ -312,6 +312,41 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
redirect_to panel_announcement_back_end_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
redirect_to panel_announcement_back_end_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ================================================================
|
||||||
|
# language:
|
||||||
|
# - default: zh_tw
|
||||||
|
# - specify language: locale=[string]
|
||||||
|
# category:
|
||||||
|
# - default: no category
|
||||||
|
# - specify: category_id=[ID]
|
||||||
|
# pagination:
|
||||||
|
# - default: no pagination
|
||||||
|
# - use it: paginate=true
|
||||||
|
# - specify the number of results: per=[number]
|
||||||
|
# - specify the page: page=[number]
|
||||||
|
# ================================================================
|
||||||
|
def get_bulletins_as_json
|
||||||
|
I18n.locale = params[:locale] || :zh_tw
|
||||||
|
bulletins = params[:category_id] ? Bulletin.where(bulletin_category_id: params[:category_id]).order_by(:created_at, :desc) : Bulletin.admin_manager_all.order_by(:created_at, :desc)
|
||||||
|
bulletins = Kaminari.paginate_array(bulletins).page(params[:page]).per(params[:per] || 10) if params[:paginate]
|
||||||
|
|
||||||
|
custom_bulletins = bulletins.inject([]) do |data, bulletin|
|
||||||
|
deadline = bulletin.deadline.nil? ? t(:no_deadline) : display_date_time(bulletin.deadline)
|
||||||
|
image_url = "#{'/' unless bulletin.image.url.start_with?('/')}#{bulletin.image.url}"
|
||||||
|
data << {
|
||||||
|
title: bulletin.title,
|
||||||
|
link: "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}",
|
||||||
|
image: "#{request.protocol}#{request.host_with_port}#{image_url}",
|
||||||
|
category: bulletin.bulletin_category.title,
|
||||||
|
content: bulletin.text,
|
||||||
|
postdate: display_date_time(bulletin.postdate),
|
||||||
|
deadline: deadline,
|
||||||
|
tag: bulletin.sorted_tags.map{|tag| tag.name}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
render json: JSON.pretty_generate(custom_bulletins)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ Rails.application.routes.draw do
|
||||||
get 'load_quick_edit'
|
get 'load_quick_edit'
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
|
get "get_bulletins_as_json"
|
||||||
post "preview"
|
post "preview"
|
||||||
put "preview"
|
put "preview"
|
||||||
get 'delete'
|
get 'delete'
|
||||||
|
|
Loading…
Reference in New Issue