diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 8404892..f6a953c 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -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 diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index e4a99d1..9b9e3e9 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -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) + ("
+
+
" + + event_carousel_images.collect do |e| + "
+ \"#{e['description_text']}\" +
+

#{e['description']}

+
+
+
" + end.join+ + "
+ + +
+
+

1/#{data['carousel_count']}

+ + +
+
").html_safe + end end diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index d799367..015c0c4 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -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 diff --git a/app/models/bulletin_feed.rb b/app/models/bulletin_feed.rb index 0fcaa9e..6a60d28 100644 --- a/app/models/bulletin_feed.rb +++ b/app/models/bulletin_feed.rb @@ -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 diff --git a/app/models/bulletin_feed_cache.rb b/app/models/bulletin_feed_cache.rb index 91672f0..6260884 100644 --- a/app/models/bulletin_feed_cache.rb +++ b/app/models/bulletin_feed_cache.rb @@ -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 diff --git a/app/models/bulletin_file.rb b/app/models/bulletin_file.rb index 4d70e74..811d1b7 100644 --- a/app/models/bulletin_file.rb +++ b/app/models/bulletin_file.rb @@ -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? diff --git a/config/locales/en.yml b/config/locales/en.yml index e84df53..d973396 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -164,4 +164,19 @@ en: status: top: Important hot: Hot - hidden: Hidden \ No newline at end of file + 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}" + \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index ff95c97..76d1b7a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -167,4 +167,5 @@ zh_tw: status: top: 重要 hot: 熱門 - hidden: 隱藏 \ No newline at end of file + hidden: 隱藏 + calendar_title: "%{year}年%{month}月" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d68962a..c13d760 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'