Merge branch 'master' into 'master'

return subtitle and image for templates

add subtitle and image to return value(hash)

See merge request !4
This commit is contained in:
EricTYL 2019-11-04 12:27:13 +08:00
commit 56822ed38c
2 changed files with 53 additions and 51 deletions

View File

@ -20,10 +20,10 @@ class AnnouncementsController < ApplicationController
# (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) && # (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) &&
if !params["source"].present? if !params["source"].present?
if !params['tags'].blank? 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 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 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 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
end end
if !feeds_anns.blank? if !feeds_anns.blank?
@ -76,7 +76,7 @@ class AnnouncementsController < ApplicationController
end end
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
files.delete(nil) files.delete(nil)
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] 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 "" author = User.find(a.create_user_id).member_profile.name rescue ""
desc = a.image_description desc = a.image_description
desc = (desc.nil? || desc == "" ? "announcement image" : desc) desc = (desc.nil? || desc == "" ? "announcement image" : desc)
@ -121,7 +121,7 @@ class AnnouncementsController < ApplicationController
"title-head" => t('announcement.table.title'), "title-head" => t('announcement.table.title'),
"date-head" => t('announcement.table.date'), "date-head" => t('announcement.table.date'),
"status-head" => t('announcement.table.status'), "status-head" => t('announcement.table.status'),
"author-head" => t('announcement.table.author'), "author-head" => t('announcement.table.author'),
"subtitle-head" => t('announcement.table.sub_title'), "subtitle-head" => t('announcement.table.sub_title'),
"category-head" => t('announcement.table.category'), "category-head" => t('announcement.table.category'),
"link-head" => t('announcement.table.link'), "link-head" => t('announcement.table.link'),
@ -168,7 +168,7 @@ class AnnouncementsController < ApplicationController
"more" => t(:more_plus), "more" => t(:more_plus),
"view_count" => "" "view_count" => ""
} }
if (!x["title"].empty? rescue false) if (!x["title"].empty? rescue false)
fans << x fans << x
end end
end end
@ -226,9 +226,9 @@ class AnnouncementsController < ApplicationController
feeds_anns = get_feed_announcements("widget") feeds_anns = get_feed_announcements("widget")
announcements = announcements + feeds_anns announcements = announcements + feeds_anns
if !feeds_anns.blank? if !feeds_anns.blank?
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
sorted = top_anns + sorted sorted = top_anns + sorted
sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue [] sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue []
else else
announcements = top_anns + announcements announcements = top_anns + announcements
sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.widget_data_count) rescue [] sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.widget_data_count) rescue []
@ -245,8 +245,8 @@ class AnnouncementsController < ApplicationController
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
files.delete(nil) files.delete(nil)
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] 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 "" author = User.find(a.create_user_id).member_profile.name rescue ""
desc = a.image_description desc = a.image_description
desc = (desc.nil? || desc == "" ? "announcement image" : desc) desc = (desc.nil? || desc == "" ? "announcement image" : desc)
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param) link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param)
target = a.is_external_link ? "_blank" : "_self" target = a.is_external_link ? "_blank" : "_self"
@ -267,10 +267,10 @@ class AnnouncementsController < ApplicationController
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg", "img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
"img_description" => desc "img_description" => desc
} }
else else
anns << a anns << a
end
end end
end
mp = (anns[0]["img_src"] rescue "") mp = (anns[0]["img_src"] rescue "")
mpd = (anns[0]["img_description"] rescue "") mpd = (anns[0]["img_description"] rescue "")
@ -322,11 +322,11 @@ class AnnouncementsController < ApplicationController
} } rescue [] } } rescue []
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
files.delete(nil) files.delete(nil)
files.each do |file| files.each do |file|
if file["file_url"] =="" || file["file_url"] == nil if file["file_url"] =="" || file["file_url"] == nil
files.delete(file) files.delete(file)
end end
end end
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] 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 "" update_user = announcement.update_user.member_profile.name rescue ""
desc = announcement.image_description desc = announcement.image_description
@ -342,10 +342,12 @@ class AnnouncementsController < ApplicationController
"bulletin_links" => links, "bulletin_links" => links,
"data" => { "data" => {
"title" => announcement.title, "title" => announcement.title,
"subtitle_ann" => announcement.subtitle,
"update_user" => update_user, "update_user" => update_user,
"updated_at" => announcement.postdate.strftime('%Y-%m-%d %H:%M'), "updated_at" => announcement.postdate.strftime('%Y-%m-%d %H:%M'),
"body" =>announcement.text, "body" =>announcement.text,
"image" => announcement.image.url, "image" => announcement.image.url,
"img_src" => announcement.image.thumb.url || "/assets/announcement-default.jpg",
"alt_title" => desc "alt_title" => desc
}, },
"impressionist" => (announcement.is_preview ? nil : announcement), "impressionist" => (announcement.is_preview ? nil : announcement),
@ -368,19 +370,19 @@ class AnnouncementsController < ApplicationController
I18n.locale = locale.to_sym I18n.locale = locale.to_sym
end end
tags << { tags << {
"tag" => tag["name_translations"][locale], "tag" => tag["name_translations"][locale],
"url" => (t.nil? ? "#" : OrbitHelper.page_for_tag(t)) "url" => (t.nil? ? "#" : OrbitHelper.page_for_tag(t))
} }
} }
files = announcement["bulletin_files"].map{|file| { "file_url" => file["url"], "file_title" => (file["title_translations"][locale] == "" ? URI.unescape(File.basename(file["url"])) : file["title_translations"][locale] rescue '') } } rescue [] files = announcement["bulletin_files"].map{|file| { "file_url" => file["url"], "file_title" => (file["title_translations"][locale] == "" ? URI.unescape(File.basename(file["url"])) : file["title_translations"][locale] rescue '') } } rescue []
files.each do |file| files.each do |file|
if file["file_url"] =="" || file["file_url"] == nil if file["file_url"] =="" || file["file_url"] == nil
files.delete(file) files.delete(file)
end end
end end
links = announcement["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale] == "" ? link["url"] : link["title_translations"][locale]) } } rescue [] links = announcement["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale] == "" ? link["url"] : link["title_translations"][locale]) } } rescue []
update_user = announcement["author"] update_user = announcement["author"]
desc = announcement["image_description_translations"][locale] rescue "" desc = announcement["image_description_translations"][locale] rescue ""

View File

@ -44,7 +44,7 @@ class BulletinsController < ApplicationController
end rescue nil end rescue nil
files = b.bulletin_files.collect do |bf| files = b.bulletin_files.collect do |bf|
file = request.protocol + request.host_with_port + bf.file.url rescue nil file = request.protocol + request.host_with_port + bf.file.url rescue nil
{ {
"title" => bf.title_translations, "title" => bf.title_translations,
"description" => bf.description_translations, "description" => bf.description_translations,
@ -106,17 +106,17 @@ class BulletinsController < ApplicationController
def smart_convertor(text) def smart_convertor(text)
html_string = text html_string = text
links = html_string.scan(/img.*?src="(.*?)"/i) links = html_string.scan(/img.*?src="(.*?)"/i)
links.each do |link| links.each do |link|
l = link.first l = link.first
new_link = nil new_link = nil
if l.starts_with?("/") if l.starts_with?("/")
new_link = request.protocol + request.host_with_port + l new_link = request.protocol + request.host_with_port + l
elsif l.starts_with?("..") elsif l.starts_with?("..")
l1 = l.gsub("../","") l1 = l.gsub("../","")
new_link = request.protocol + request.host_with_port + "/" + l1 new_link = request.protocol + request.host_with_port + "/" + l1
end
html_string = html_string.sub(l,new_link) if !new_link.nil?
end end
html_string = html_string.sub(l,new_link) if !new_link.nil?
end
return html_string return html_string
end end