diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb
index 03661d3..2567a1e 100644
--- a/app/controllers/announcements_controller.rb
+++ b/app/controllers/announcements_controller.rb
@@ -1,68 +1,8 @@
class AnnouncementsController < ApplicationController
-
+ include AnnouncementsHelper
def index
Bulletin.remove_expired_status
- params = OrbitHelper.params
- locale = OrbitHelper.get_site_locale.to_s
- feeds_anns = []
- top_anns = []
- if !params['tags'].blank?
- announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a
- else
- if !params["source"].present?
- announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories([],false).filter_by_tags.to_a
- feeds_anns = get_feed_announcements("index")
- else
- announcements = []
- feeds_anns = get_feed_announcements("index",params["source"])
- end
- end
- # (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) &&
- if !params["source"].present?
- if !params['tags'].blank?
- top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags(params['tags']).to_a
- else
- top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags.to_a
- end
- end
-
- if !feeds_anns.blank?
- announcements = announcements.concat(feeds_anns)
- sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
- sorted = top_anns + sorted
- if params["keywords"].present?
- sorted = sorted.find_all{|anns|
- if anns["source-site"].present?
- /#{params[:keywords].to_s}/i.match anns["title"]
- else
- /#{params[:keywords].to_s}/i.match anns.title
- end
- }
- end
- if params["postdate"].present?
- sorted = sorted.find_all{|anns|
- if anns["source-site"].present?
- /#{params[:postdate].to_s}/i.match anns["postdate"].strftime("%Y-%m") if !anns["postdate"].nil?
- else
- /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") if !anns.postdate.nil?
- end
- }
- end
- sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
- else
- announcements = top_anns + announcements
- if params["keywords"].present?
- announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title}
- end
- if params["postdate"].present?
- announcements = announcements.find_all{|anns|
- if !anns.postdate.nil?
- /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m")
- end
- }
- end
- sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
- end
+ announcements,sorted = get_sorted_annc
total_pages = sorted.total_pages
anns = []
@@ -134,47 +74,6 @@ class AnnouncementsController < ApplicationController
end
- def get_feed_announcements(type,site_source=nil)
- feed_anns = OrbitHelper.get_feed_for_module(type)
- fans = []
- locale = OrbitHelper.get_site_locale.to_s
- feed_anns.each do |fa|
- next if !site_source.nil? && site_source != fa["source-site-title"]
- status = {
- "status" => "#{fa["source-site-title"]}",
- "status-class" => "status-source"
- }
-
- files = fa["bulletin_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue []
- links = fa["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue []
-
- x = {
- "bulletin_links" => links,
- "bulletin_files" => files,
- "title" => fa["title_translations"][locale],
- "subtitle" => fa["subtitle_translations"][locale],
- "statuses" => [status],
- "category" => fa["category"],
- "postdate" => fa["postdate"],
- "author" => fa["author"],
- "is_top" => 0,
- "source-site" => "#{fa["source-site-title"]}",
- "source-site-title" => fa["source-site-title"],
- "source-site-link" => fa["source-site"],
- "link_to_show" => OrbitHelper.url_to_show(fa["params"]),
- "target" => "_self",
- "img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg",
- "img_description" => fa["image_description_translations"][locale],
- "more" => t(:more_plus),
- "view_count" => ""
- }
- if (!x["title"].empty? rescue false)
- fans << x
- end
- end
- fans
- end
-
def random_announcement_widget
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb
new file mode 100644
index 0000000..0197a37
--- /dev/null
+++ b/app/helpers/announcements_helper.rb
@@ -0,0 +1,111 @@
+module AnnouncementsHelper
+ def get_feed_announcements(type,site_source=nil)
+ feed_anns = OrbitHelper.get_feed_for_module(type)
+ fans = []
+ locale = OrbitHelper.get_site_locale.to_s
+ feed_anns.each do |fa|
+ next if !site_source.nil? && site_source != fa["source-site-title"]
+ status = {
+ "status" => "#{fa["source-site-title"]}",
+ "status-class" => "status-source"
+ }
+
+ files = fa["bulletin_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue []
+ links = fa["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue []
+
+ x = {
+ "bulletin_links" => links,
+ "bulletin_files" => files,
+ "title" => fa["title_translations"][locale],
+ "subtitle" => fa["subtitle_translations"][locale],
+ "statuses" => [status],
+ "category" => fa["category"],
+ "postdate" => fa["postdate"],
+ "author" => fa["author"],
+ "is_top" => 0,
+ "source-site" => "#{fa["source-site-title"]}",
+ "source-site-title" => fa["source-site-title"],
+ "source-site-link" => fa["source-site"],
+ "link_to_show" => OrbitHelper.url_to_show(fa["params"]),
+ "target" => "_self",
+ "img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg",
+ "img_description" => fa["image_description_translations"][locale],
+ "more" => t(:more_plus),
+ "view_count" => ""
+ }
+ if (!x["title"].empty? rescue false)
+ fans << x
+ end
+ end
+ fans
+ end
+ def test
+ 123
+ end
+ def get_sorted_annc
+ params = OrbitHelper.params
+ locale = OrbitHelper.get_site_locale.to_s
+ page = Page.where(url:params['url']).first
+ feeds_anns = []
+ top_anns = []
+ tags = page.tags
+ if !tags.blank?
+ announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(tags).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a
+ else
+ if !params["source"].present?
+ announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories([],false).filter_by_tags.to_a
+ feeds_anns = get_feed_announcements("index")
+ else
+ announcements = []
+ feeds_anns = get_feed_announcements("index",params["source"])
+ end
+ end
+ # (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) &&
+ if !params["source"].present?
+ if !tags.blank?
+ top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags(tags).to_a
+ else
+ top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags.to_a
+ end
+ end
+
+ if !feeds_anns.blank?
+ announcements = announcements.concat(feeds_anns)
+ sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
+ sorted = top_anns + sorted
+ if params["keywords"].present?
+ sorted = sorted.find_all{|anns|
+ if anns["source-site"].present?
+ /#{params[:keywords].to_s}/i.match anns["title"]
+ else
+ /#{params[:keywords].to_s}/i.match anns.title
+ end
+ }
+ end
+ if params["postdate"].present?
+ sorted = sorted.find_all{|anns|
+ if anns["source-site"].present?
+ /#{params[:postdate].to_s}/i.match anns["postdate"].strftime("%Y-%m") if !anns["postdate"].nil?
+ else
+ /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") if !anns.postdate.nil?
+ end
+ }
+ end
+ sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
+ else
+ announcements = top_anns + announcements
+ if params["keywords"].present?
+ announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title}
+ end
+ if params["postdate"].present?
+ announcements = announcements.find_all{|anns|
+ if !anns.postdate.nil?
+ /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m")
+ end
+ }
+ end
+ sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
+ end
+ [announcements,sorted]
+ end
+end
diff --git a/app/views/announcements/show.html.erb b/app/views/announcements/show.html.erb
index 648b75c..d20fef9 100644
--- a/app/views/announcements/show.html.erb
+++ b/app/views/announcements/show.html.erb
@@ -1 +1,69 @@
-<%= render_view %>
\ No newline at end of file
+<%
+ require 'announcements_helper'
+ params = OrbitHelper.params
+ page = Page.where(url:params['url']).first
+ @show_back_and_next_flag = 0
+ if page.methods.include? 'select_option_items'.to_sym
+ ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app|
+ @show_option_items = modile_app.show_option_items rescue nil
+ end
+ page.select_option_items.each do |select_option_item|
+ if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys.first.to_s
+ value = YAML.load(select_option_item.value)
+ if value[I18n.locale] == t('announcement.not_show')
+ @show_back_and_next_flag = 0
+ elsif value[I18n.locale] == t('announcement.show_top')
+ @show_back_and_next_flag = 1
+ elsif value[I18n.locale] == t('announcement.show_bottom')
+ @show_back_and_next_flag = 2
+ end
+ end
+ end
+ end
+ if @show_back_and_next_flag != 0
+ uid = params['uid']
+ announcements,sorted = get_sorted_annc
+ now_index = sorted.to_enum.with_index.select{|v| v[0].uid==uid}[0][1]
+ if now_index != 0
+ prev_result = sorted[now_index-1]
+ prev_url = params['url'] + '/' + prev_result.to_param
+ prev_content = "#{t('announcement.prev')} #{prev_result['title'][I18n.locale]} #{next_result['title'][I18n.locale]}