merge some feature from event news
This commit is contained in:
parent
51028d1372
commit
59e38422c3
|
@ -14,7 +14,6 @@ class AnnouncementsController < ApplicationController
|
|||
def index
|
||||
Bulletin.remove_expired_status
|
||||
sorted,total_pages = get_sorted_annc
|
||||
sorted = [] if sorted.nil?
|
||||
anns = sorted.collect do |a|
|
||||
if a["source-site"].blank?
|
||||
statuses = a.statuses_with_classname.collect do |status|
|
||||
|
@ -24,8 +23,7 @@ class AnnouncementsController < ApplicationController
|
|||
}
|
||||
end
|
||||
locale = OrbitHelper.get_site_locale.to_s
|
||||
files = a.bulletin_files.map{|file| { "file_url" => file.file.url + "\" title=\"#{file.file_title}", "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
|
||||
files.delete(nil)
|
||||
files = a.bulletin_files.to_fronted(locale)
|
||||
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
|
||||
|
@ -454,6 +452,9 @@ class AnnouncementsController < ApplicationController
|
|||
end
|
||||
end
|
||||
def get_anncs_for_pack_data(cats,tags,set_tags=nil,is_random = false)
|
||||
if tags.blank?
|
||||
tags = ["all"]
|
||||
end
|
||||
subpart = OrbitHelper.get_current_widget
|
||||
widget_data_count = OrbitHelper.widget_data_count
|
||||
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
|
||||
|
@ -516,6 +517,7 @@ class AnnouncementsController < ApplicationController
|
|||
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil }
|
||||
anns
|
||||
end
|
||||
|
||||
def get_file
|
||||
@url = request.path
|
||||
begin
|
||||
|
@ -553,6 +555,7 @@ class AnnouncementsController < ApplicationController
|
|||
return
|
||||
end
|
||||
end
|
||||
|
||||
def show_local_announcement(uid, is_preview)
|
||||
locale = OrbitHelper.get_site_locale.to_s
|
||||
if is_preview
|
||||
|
@ -582,16 +585,7 @@ class AnnouncementsController < ApplicationController
|
|||
"tag" => tag.name ,
|
||||
"url" => OrbitHelper.page_for_tag(tag)
|
||||
} } rescue []
|
||||
files = announcement.bulletin_files.map do |file|
|
||||
{ "file_url" => "/xhr/announcements/file/#{file.id}/#{file['file']}" + "\" title=\"#{file.file_title}",
|
||||
"file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } rescue nil if file.enabled_for?(locale)
|
||||
end rescue []
|
||||
files.delete(nil)
|
||||
files.each do |file|
|
||||
if file["file_url"] =="" || file["file_url"] == nil
|
||||
files.delete(file)
|
||||
end
|
||||
end
|
||||
files = announcement.bulletin_files.to_fronted(locale)
|
||||
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
|
||||
|
@ -769,8 +763,7 @@ class AnnouncementsController < ApplicationController
|
|||
}
|
||||
end
|
||||
locale = I18n.locale.to_s
|
||||
files = a.bulletin_files.map{|file| { "file_url" => file.file.url + "\" title=\"#{file.file_title}", "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
|
||||
files.delete(nil)
|
||||
files = a.bulletin_files.to_fronted(locale)
|
||||
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
|
||||
|
@ -833,4 +826,35 @@ class AnnouncementsController < ApplicationController
|
|||
render :layout => false
|
||||
end
|
||||
|
||||
def agenda
|
||||
I18n.with_locale(params[:locale]||I18n.locale) do
|
||||
if !params[:subpart_id].nil?
|
||||
subpartid = params[:subpart_id]
|
||||
subpart = SubPart.find(subpartid)
|
||||
all_cats = subpart.categories
|
||||
all_cats = ['all'] if all_cats.length==0
|
||||
all_tags = subpart.tags
|
||||
all_tags = ['all'] if all_tags.length==0
|
||||
page = Page.where(:page_id=> subpart.read_more_page_id).first rescue nil
|
||||
page = Page.where(:module => "announcement").first rescue nil if page.nil?
|
||||
read_more_url_root = "/#{I18n.locale.to_s + page.url}" rescue ""
|
||||
read_more_url = read_more_url_root + "?" + {"category"=>all_cats,"tags"=> all_tags}.to_param if read_more_url != ""
|
||||
else
|
||||
page = Page.where(:module => "announcement").first
|
||||
read_more_url_root = "/#{I18n.locale.to_s + page.url}" rescue ""
|
||||
end
|
||||
if params[:unix_start].present? && params[:unix_end].present?
|
||||
agenda_start = Time.at(params[:unix_start].to_i).utc.to_s
|
||||
agenda_end = Time.at(params[:unix_end].to_i).utc.to_s
|
||||
events = Bulletin.agenda_events(agenda_start,agenda_end,read_more_url_root)
|
||||
end
|
||||
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
|
||||
end
|
||||
end
|
||||
|
||||
def get_calendar_title(now_date=nil)
|
||||
now_date = Time.now.utc if now_date.nil?
|
||||
month_name = I18n.locale.to_s=='zh_tw' ? now_date.month : I18n.t("announcement.month_name.#{now_date.month}")
|
||||
I18n.t("announcement.calendar_title",year: now_date.year,month: month_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ module AnnouncementsHelper
|
|||
"source-site-link" => "",
|
||||
"subtitle" => a.subtitle,
|
||||
"statuses" => statuses,
|
||||
"category" => a.category.title,
|
||||
"category" => (a.category.title rescue ""),
|
||||
"tag_ids" => (set_tag_ids.nil? ? (a.tag_ids.map{|id| id.to_s}.to_s.gsub('"',"'") rescue '[]') : set_tag_ids),
|
||||
"postdate" => a.postdate,
|
||||
"author" => author,
|
||||
|
@ -205,7 +205,7 @@ module AnnouncementsHelper
|
|||
tags = page.tags
|
||||
tags = params[:tags] if params[:tags].present?
|
||||
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
|
||||
if params['category'].present?
|
||||
if params['category'].present? && tags.blank?
|
||||
tags = ["all"]
|
||||
end
|
||||
end
|
||||
|
@ -479,4 +479,56 @@ module AnnouncementsHelper
|
|||
end
|
||||
layout_types
|
||||
end
|
||||
def render_ad_banner(event_carousel_images,data)
|
||||
("<div class=\"carousel_images\">
|
||||
<div class=\"w-ba-banner ba-banner-widget-1\">
|
||||
<div class=\"w-ba-banner__wrap cycle-slideshow\"
|
||||
data-list=\"event_carousel_images\"
|
||||
data-level=\"0\"
|
||||
data-cycle-slides=\".event_carousel_slide\"
|
||||
data-cycle-log=\"false\"
|
||||
data-cycle-auto-height=\"0\"
|
||||
data-cycle-speed=\"300\"
|
||||
data-cycle-timeout=\"5000\"
|
||||
data-cycle-fx=\"fade\"
|
||||
data-pager-active-class=\"active-slide\"
|
||||
data-cycle-swipe=true
|
||||
data-cycle-swipe-fx=\"scrollHorz\"
|
||||
>" +
|
||||
event_carousel_images.collect do |e|
|
||||
"<div class=\"w-ba-banner__slide event_carousel_slide\"
|
||||
data-cycle-title=\"#{e['description_text']}\"
|
||||
>
|
||||
<img class=\"w-ba-banner__image banner-responsive\" src=\"#{e['src']}\" alt=\"#{e['description_text']}\">
|
||||
<div class=\"ad-overlay w-ad-banner__overlay event_carousel__overlay\">
|
||||
<p><strong class=\"carousel__description\">#{e['description']}</strong></p>
|
||||
</div>
|
||||
<div class=\"transitionfade\"></div>
|
||||
</div>"
|
||||
end.join+
|
||||
"</div>
|
||||
<ul class=\"controlplay\"><a class=\"resume-slide\" title = \"#{data['resume_btn_title']}\"><i></i></a><a class=\"pause-slide\" title = \"#{data['pause_btn_title']}\"><i></i></a></ul>
|
||||
<ul class=\"button-mid\">
|
||||
<i class=\"fa fa-angle-left prev-button\" aria-hidden=\"true\" title = \"#{data['prev_btn_title']}\"></i>
|
||||
<i class=\"fa fa-angle-right next-button\" aria-hidden=\"true\" title = \"#{data['next_btn_title']}\"></i>
|
||||
</ul>
|
||||
</div>
|
||||
<div style=\"position: relative;\">
|
||||
<h4><span class=\"active_slide\">1</span>/#{data['carousel_count']}</h4>
|
||||
<ul class=\"carousel_images_slide w-annc__list row list-unstyled\" data-level=\"0\" data-list=\"event_carousel_images\">" +
|
||||
event_carousel_images.collect do |e|
|
||||
"<li class=\"carousel_img_item col-sm-3\">
|
||||
<div class=\"carousel_img-wrap\">
|
||||
<img class=\"carousel_img\" src=\"#{e['src']}\" alt=\"#{e['description_text']}\">
|
||||
</div>
|
||||
</li>"
|
||||
end.join +
|
||||
"</ul>
|
||||
<ul class=\"button-mid\">
|
||||
<i class=\"fa fa-angle-left prev-button prev_img\" aria-hidden=\"true\" title = \"#{data['prev_btn_title']}\"></i>
|
||||
<i class=\"fa fa-angle-right next-button next_img\" aria-hidden=\"true\" title = \"#{data['next_btn_title']}\"></i>
|
||||
</ul>
|
||||
</div>
|
||||
</div>").html_safe
|
||||
end
|
||||
end
|
||||
|
|
|
@ -128,9 +128,9 @@ class Bulletin
|
|||
if status_settings.count != 0
|
||||
reach_limit = status_settings.collect do |status_setting|
|
||||
status = status_setting.status
|
||||
if status_setting.top_limit.to_i <= Bulletin.where(:is_preview.ne=>true,:update_user_id.in => Role.find(status_setting.role_id).member_profiles.collect(&:user).flatten.uniq.map{|v| v.id},status => true).count
|
||||
if status_setting.top_limit.to_i <= self.class.where(:is_preview.ne=>true,:update_user_id.in => Role.find(status_setting.role_id).member_profiles.collect(&:user).flatten.uniq.map{|v| v.id},status => true).count
|
||||
if !check_only
|
||||
if self[status] && !Bulletin.where(id:self.id).first[status]
|
||||
if self[status] && !self.class.where(id:self.id).first[status]
|
||||
self[status] = false
|
||||
nil
|
||||
end
|
||||
|
@ -242,4 +242,22 @@ class Bulletin
|
|||
def carousel_image_width
|
||||
(self.custom_carousel_image_width.blank? ? AnnouncementSetting.last.carousel_image_width : self.custom_carousel_image_width)
|
||||
end
|
||||
def self.agenda_events(agenda_start, agenda_end,read_more_url)
|
||||
events = self.monthly_event(agenda_start, agenda_end).convert_front(read_more_url)
|
||||
end
|
||||
def self.monthly_event(start_date,end_date)
|
||||
self.any_of({:postdate.lte => start_date,:deadline.gte => start_date},{:postdate.gte => start_date,:deadline.lte => end_date},{:postdate.lte => end_date,:deadline.gte => end_date}).asc(:postdate)
|
||||
end
|
||||
def self.convert_front(read_more_url)
|
||||
self.all.collect do |re|
|
||||
{:id => re.id.to_s,
|
||||
:title=>re.title,
|
||||
:note=>re.subtitle || "",
|
||||
:allDay => false,
|
||||
:color => nil,
|
||||
:url_linked => (re.is_external_link ? re.external_link : "#{read_more_url}/#{re.to_param}" rescue ""),
|
||||
:start => re.postdate,
|
||||
:end => re.deadline}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,9 +3,9 @@ class BulletinFeed
|
|||
include Mongoid::Timestamps
|
||||
include Slug
|
||||
|
||||
field :title, as: :slug_title, type: String, localize: true
|
||||
field :tag_ids, type: Array, default: []
|
||||
field :category_ids, type: Array, default: []
|
||||
field :title, as: :slug_title, type: String, localize: true
|
||||
field :tag_ids, type: Array, default: []
|
||||
field :category_ids, type: Array, default: []
|
||||
before_save do
|
||||
BulletinFeedCache.where(uid: self.uid).each do |cache|
|
||||
cache.regenerate
|
||||
|
|
|
@ -9,7 +9,7 @@ class BulletinFeedCache
|
|||
field :date
|
||||
field :invalid_date, type: DateTime
|
||||
def self.regenerate_all
|
||||
caches = BulletinFeedCache.all.to_a
|
||||
caches = self.all.to_a
|
||||
caches.each do |cache|
|
||||
cache.regenerate
|
||||
end
|
||||
|
|
|
@ -11,6 +11,13 @@ class BulletinFile
|
|||
field :choose_lang, :type => Array, :default => ["en","zh_tw"]
|
||||
field :privacy_type, type: String, default: 'public'
|
||||
belongs_to :bulletin
|
||||
scope :to_fronted, ->(locale=I18n.locale){ self.map{|file| file.to_fronted(locale)}.compact rescue [] }
|
||||
def to_fronted(locale=I18n.locale)
|
||||
file = self
|
||||
file.enabled_for?(locale) && !file[:file].blank? ? { "file_url" => "/xhr/announcements/file/#{file.id}/#{file['file']}" + "\" title=\"#{file.file_title}",
|
||||
"file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '')
|
||||
} : nil rescue nil
|
||||
end
|
||||
|
||||
def file_title
|
||||
if self.description.present?
|
||||
|
|
|
@ -164,4 +164,19 @@ en:
|
|||
status:
|
||||
top: Important
|
||||
hot: Hot
|
||||
hidden: Hidden
|
||||
hidden: Hidden
|
||||
month_name:
|
||||
'1': 'January'
|
||||
'2': 'February'
|
||||
'3': 'March'
|
||||
'4': 'April'
|
||||
'5': 'May'
|
||||
'6': 'June'
|
||||
'7': 'July'
|
||||
'8': 'August'
|
||||
'9': 'September'
|
||||
'10': 'October'
|
||||
'11': 'November'
|
||||
'12': 'December'
|
||||
calendar_title: "%{month} %{year}"
|
||||
|
|
@ -167,4 +167,5 @@ zh_tw:
|
|||
status:
|
||||
top: 重要
|
||||
hot: 熱門
|
||||
hidden: 隱藏
|
||||
hidden: 隱藏
|
||||
calendar_title: "%{year}年%{month}月"
|
|
@ -7,7 +7,7 @@ Rails.application.routes.draw do
|
|||
locales = Site.first.in_use_locales rescue I18n.available_locales
|
||||
|
||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
namespace :admin do
|
||||
namespace :admin do
|
||||
post 'announcement/get_preview_action', to: 'announcements#get_preview_action'
|
||||
post 'announcement/preview', to: 'announcements#preview'
|
||||
post 'announcement/createfeed', to: 'announcements#createfeed'
|
||||
|
|
Loading…
Reference in New Issue