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) + ("