add new feature: let user can choose whether to show next and prev
option
This commit is contained in:
parent
5c7dfb0d53
commit
31b331d852
|
@ -1,68 +1,8 @@
|
||||||
class AnnouncementsController < ApplicationController
|
class AnnouncementsController < ApplicationController
|
||||||
|
include AnnouncementsHelper
|
||||||
def index
|
def index
|
||||||
Bulletin.remove_expired_status
|
Bulletin.remove_expired_status
|
||||||
params = OrbitHelper.params
|
announcements,sorted = get_sorted_annc
|
||||||
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
|
|
||||||
total_pages = sorted.total_pages
|
total_pages = sorted.total_pages
|
||||||
|
|
||||||
anns = []
|
anns = []
|
||||||
|
@ -134,47 +74,6 @@ class AnnouncementsController < ApplicationController
|
||||||
|
|
||||||
end
|
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" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
||||||
"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" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
||||||
"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
|
def random_announcement_widget
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
uid = OrbitHelper.params[:uid] rescue ""
|
||||||
tags = OrbitHelper.widget_tags
|
tags = OrbitHelper.widget_tags
|
||||||
|
|
|
@ -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" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
||||||
|
"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" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
||||||
|
"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
|
|
@ -1 +1,69 @@
|
||||||
<%= render_view %>
|
<%
|
||||||
|
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 = "<a href='#{prev_url}' class='prev'><b>#{t('announcement.prev')}</b><p>#{prev_result['title'][I18n.locale]}</p></a>"
|
||||||
|
end
|
||||||
|
if now_index != sorted.length-1
|
||||||
|
next_result = sorted[now_index+1]
|
||||||
|
next_url = params['url'] + '/' + next_result.to_param
|
||||||
|
next_content = "<a href='#{next_url}' class='next'><b>#{t('announcement.next')}</b><p>#{next_result['title'][I18n.locale]}</p></a>"
|
||||||
|
end
|
||||||
|
content = "<div class='see_more_boxTitle'>#{prev_content}#{next_content}</div>".html_safe
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<% if @show_back_and_next_flag!=0 %>
|
||||||
|
<style type="text/css">
|
||||||
|
.see_more_boxTitle{
|
||||||
|
display: flex;
|
||||||
|
margin: 1em 0em;
|
||||||
|
padding: 1em;
|
||||||
|
border: 0.2em solid;
|
||||||
|
}
|
||||||
|
a.prev, a.next{
|
||||||
|
width: 50%;
|
||||||
|
border: 0.2em solid;
|
||||||
|
padding: 1em;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
a.next{
|
||||||
|
margin-left: 1em;
|
||||||
|
}
|
||||||
|
a.prev{
|
||||||
|
margin-right: 1em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @show_back_and_next_flag==1 %>
|
||||||
|
<%= content %>
|
||||||
|
<% end %>
|
||||||
|
<%= render_view %>
|
||||||
|
<% if @show_back_and_next_flag==2 %>
|
||||||
|
<%= content %>
|
||||||
|
<% end %>
|
|
@ -7,6 +7,12 @@ en:
|
||||||
orignal_size: Original Size
|
orignal_size: Original Size
|
||||||
small_size: Small Size
|
small_size: Small Size
|
||||||
medium_size: Medium Size
|
medium_size: Medium Size
|
||||||
|
showing_back_and_next: Show back and next
|
||||||
|
not_show: Not show
|
||||||
|
show_top: Show at top
|
||||||
|
show_bottom: Show at bottom
|
||||||
|
prev: previous
|
||||||
|
next: next
|
||||||
table:
|
table:
|
||||||
title : Title
|
title : Title
|
||||||
date : Date
|
date : Date
|
||||||
|
|
|
@ -7,6 +7,12 @@ zh_tw:
|
||||||
orignal_size: 原圖大小
|
orignal_size: 原圖大小
|
||||||
small_size: 小張縮圖
|
small_size: 小張縮圖
|
||||||
medium_size: 中等縮圖
|
medium_size: 中等縮圖
|
||||||
|
showing_back_and_next: 顯示上下則
|
||||||
|
not_show: 不顯示
|
||||||
|
show_top: 顯示在最上面
|
||||||
|
show_bottom: 顯示在最下面
|
||||||
|
prev: 上一則
|
||||||
|
next: 下一則
|
||||||
table:
|
table:
|
||||||
title : 標題
|
title : 標題
|
||||||
date : 張貼日期
|
date : 張貼日期
|
||||||
|
|
|
@ -15,6 +15,18 @@ module Announcement
|
||||||
value3[t_data.keys[0]] = t_data.values[0]['announcement']['orignal_size']
|
value3[t_data.keys[0]] = t_data.values[0]['announcement']['orignal_size']
|
||||||
end
|
end
|
||||||
data[key1] = [value1,value2,value3]
|
data[key1] = [value1,value2,value3]
|
||||||
|
data_item = {}
|
||||||
|
key_item1 = {}
|
||||||
|
value_item1 = {}
|
||||||
|
value_item2 = {}
|
||||||
|
value_item3 = {}
|
||||||
|
translate_data.each do |t_data|
|
||||||
|
key_item1[t_data.keys[0]] = t_data.values[0]['announcement']['showing_back_and_next']
|
||||||
|
value_item1[t_data.keys[0]] = t_data.values[0]['announcement']['not_show']
|
||||||
|
value_item2[t_data.keys[0]] = t_data.values[0]['announcement']['show_bottom']
|
||||||
|
value_item3[t_data.keys[0]] = t_data.values[0]['announcement']['show_top']
|
||||||
|
end
|
||||||
|
data_item[key_item1] = [value_item1,value_item2,value_item3]
|
||||||
OrbitApp.registration "Announcement", :type => "ModuleApp" do
|
OrbitApp.registration "Announcement", :type => "ModuleApp" do
|
||||||
module_label "announcement.announcement"
|
module_label "announcement.announcement"
|
||||||
base_url File.expand_path File.dirname(__FILE__)
|
base_url File.expand_path File.dirname(__FILE__)
|
||||||
|
@ -28,6 +40,7 @@ module Announcement
|
||||||
data_count 1..30
|
data_count 1..30
|
||||||
begin
|
begin
|
||||||
show_options data
|
show_options data
|
||||||
|
show_option_items data_item
|
||||||
rescue => e
|
rescue => e
|
||||||
puts ['there_was_no_show_option_method',e]
|
puts ['there_was_no_show_option_method',e]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue