From 862dc144495c1750262ea07f48365a70f2c1a379 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 29 Oct 2019 14:45:45 +0800 Subject: [PATCH 1/5] auto format --- app/controllers/announcements_controller.rb | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 63ac875..99c34d8 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -20,10 +20,10 @@ class AnnouncementsController < ApplicationController # (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 + 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? @@ -76,7 +76,7 @@ class AnnouncementsController < ApplicationController 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.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 "" desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) @@ -113,7 +113,7 @@ class AnnouncementsController < ApplicationController # anns = anns.concat(feeds_anns) # total_pages = announcements.total_pages - + { "announcements" => anns, "extras" => { @@ -121,7 +121,7 @@ class AnnouncementsController < ApplicationController "title-head" => t('announcement.table.title'), "date-head" => t('announcement.table.date'), "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'), "category-head" => t('announcement.table.category'), "link-head" => t('announcement.table.link'), @@ -168,7 +168,7 @@ class AnnouncementsController < ApplicationController "more" => t(:more_plus), "view_count" => "" } - if (!x["title"].empty? rescue false) + if (!x["title"].empty? rescue false) fans << x end end @@ -226,9 +226,9 @@ class AnnouncementsController < ApplicationController feeds_anns = get_feed_announcements("widget") announcements = announcements + feeds_anns if !feeds_anns.blank? - sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } - sorted = top_anns + sorted - sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue [] + sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } + sorted = top_anns + sorted + sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue [] else announcements = top_anns + announcements 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.delete(nil) 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 + author = User.find(a.create_user_id).member_profile.name rescue "" + desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param) 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_description" => desc } - else - anns << a + else + anns << a + end end - end mp = (anns[0]["img_src"] rescue "") mpd = (anns[0]["img_description"] rescue "") @@ -322,16 +322,16 @@ class AnnouncementsController < ApplicationController } } 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.each do |file| - if file["file_url"] =="" || file["file_url"] == nil - files.delete(file) - end - end + files.each do |file| + if file["file_url"] =="" || file["file_url"] == nil + files.delete(file) + end + end 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 desc = (desc.nil? || desc == "" ? "announcement image" : desc) - + request = OrbitHelper.request meta_desc = announcement.subtitle.nil? || announcement.subtitle == "" ? announcement.text[0..200] : announcement.subtitle OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => announcement.title},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => "#{request.base_url}#{announcement.image.url}"},{"property" => "og:type", "content" => "Article"}]) @@ -368,24 +368,24 @@ class AnnouncementsController < ApplicationController I18n.locale = locale.to_sym end tags << { - "tag" => tag["name_translations"][locale], - "url" => (t.nil? ? "#" : OrbitHelper.page_for_tag(t)) - } - } + "tag" => tag["name_translations"][locale], + "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.each do |file| - if file["file_url"] =="" || file["file_url"] == nil - files.delete(file) - 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 [] + if file["file_url"] =="" || file["file_url"] == nil + files.delete(file) + 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 [] update_user = announcement["author"] desc = announcement["image_description_translations"][locale] rescue "" desc = (desc.nil? || desc == "" ? "announcement image" : desc) - + request = OrbitHelper.request if announcement["subtitle_translations"].present? meta_desc = announcement["subtitle_translations"][locale] != "" ? announcement["subtitle_translations"][locale] : announcement["text_translations"][locale][0..200] rescue "" From 82ab7c40ec80adc3768c19ed3fe0cd75eb0521d7 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 29 Oct 2019 14:48:02 +0800 Subject: [PATCH 2/5] auto format --- app/controllers/bulletins_controller.rb | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/bulletins_controller.rb b/app/controllers/bulletins_controller.rb index 2c2d357..da0b705 100644 --- a/app/controllers/bulletins_controller.rb +++ b/app/controllers/bulletins_controller.rb @@ -27,7 +27,7 @@ class BulletinsController < ApplicationController else bulletins = bulletins end - + bulletins = bulletins.where(:is_preview.in=>[false,nil]) bulletins = bulletins.where(:approved.ne => false , :rejected.ne => true) bulletins = bulletins.where(:postdate.lt=>Time.now) @@ -35,7 +35,7 @@ class BulletinsController < ApplicationController bulletins = bulletins.collect do |b| image = request.protocol + request.host_with_port + b.image.url rescue nil - + links = b.bulletin_links.collect do |bl| { "title" => bl.title_translations, @@ -44,7 +44,7 @@ class BulletinsController < ApplicationController end rescue nil 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, "description" => bf.description_translations, @@ -106,17 +106,17 @@ class BulletinsController < ApplicationController def smart_convertor(text) html_string = text links = html_string.scan(/img.*?src="(.*?)"/i) - links.each do |link| - l = link.first - new_link = nil - if l.starts_with?("/") - new_link = request.protocol + request.host_with_port + l - elsif l.starts_with?("..") - l1 = l.gsub("../","") - new_link = request.protocol + request.host_with_port + "/" + l1 - end - html_string = html_string.sub(l,new_link) if !new_link.nil? + links.each do |link| + l = link.first + new_link = nil + if l.starts_with?("/") + new_link = request.protocol + request.host_with_port + l + elsif l.starts_with?("..") + l1 = l.gsub("../","") + new_link = request.protocol + request.host_with_port + "/" + l1 end + html_string = html_string.sub(l,new_link) if !new_link.nil? + end return html_string end From c3c8e4864bc4d30ce4b4a519da009ea6a2cde0d4 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 29 Oct 2019 14:49:10 +0800 Subject: [PATCH 3/5] add subtitle_ann for front-end --- app/controllers/announcements_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 99c34d8..2d9c5db 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -342,6 +342,7 @@ class AnnouncementsController < ApplicationController "bulletin_links" => links, "data" => { "title" => announcement.title, + "subtitle_ann" => announcement.subtitle, "update_user" => update_user, "updated_at" => announcement.postdate.strftime('%Y-%m-%d %H:%M'), "body" =>announcement.text, From 810c283dc6b10f6844a5949e1605d431dc110e88 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 29 Oct 2019 15:48:05 +0800 Subject: [PATCH 4/5] add img_src for front-end --- app/controllers/announcements_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 2d9c5db..765f403 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -347,6 +347,7 @@ class AnnouncementsController < ApplicationController "updated_at" => announcement.postdate.strftime('%Y-%m-%d %H:%M'), "body" =>announcement.text, "image" => announcement.image.url, + "img_src" => announcement.image.thumb.url || "/assets/announcement-default.jpg", "alt_title" => desc }, "impressionist" => (announcement.is_preview ? nil : announcement), From d1957d6b887bd81333f6540887c2fdf08d7231c2 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 29 Oct 2019 15:51:02 +0800 Subject: [PATCH 5/5] remove trailing space --- app/controllers/announcements_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 765f403..96cdfac 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -31,7 +31,7 @@ class AnnouncementsController < ApplicationController sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } sorted = top_anns + sorted if params["keywords"].present? - sorted = sorted.find_all{|anns| + sorted = sorted.find_all{|anns| if anns["source-site"].present? /#{params[:keywords].to_s}/i.match anns["title"] else @@ -40,7 +40,7 @@ class AnnouncementsController < ApplicationController } end if params["postdate"].present? - sorted = sorted.find_all{|anns| + 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 @@ -55,9 +55,9 @@ class AnnouncementsController < ApplicationController announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title} end if params["postdate"].present? - announcements = announcements.find_all{|anns| + announcements = announcements.find_all{|anns| if !anns.postdate.nil? - /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") + /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") end } end @@ -229,7 +229,7 @@ class AnnouncementsController < ApplicationController sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } sorted = top_anns + sorted sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue [] - else + else announcements = top_anns + announcements sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.widget_data_count) rescue [] end @@ -362,7 +362,7 @@ class AnnouncementsController < ApplicationController return {} if announcement.blank? tags = [] - announcement["tags"].each{|tag| + announcement["tags"].each{|tag| t = Tag.where(:name => tag["name_translations"][locale]).first rescue nil if t.nil? I18n.locale = (locale == "en" ? :zh_tw : :en)