From 43b14b8a7925f4c6339b0b860201356b723e3086 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 13 Jan 2020 12:55:14 +0800 Subject: [PATCH 1/3] add fields and model methods to Bulletin --- app/models/bulletin.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 6a295f3..a7d6b83 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -26,6 +26,8 @@ class Bulletin field :rejection_reason field :is_external_link, :type => Boolean, :default => false field :external_link + field :display_subtitle, :type => Boolean, :default => false + field :display_img, :type => Boolean, :default => false field :email_id field :email_sent, :type => Boolean, :default => false @@ -94,4 +96,11 @@ class Bulletin end end + def display_subtitle? + self.display_subtitle rescue false + end + + def display_img? + self.display_img rescue false + end end From 2501d578bd824e4c6d7c8919b4514cfcb1b06d0d Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 13 Jan 2020 14:51:37 +0800 Subject: [PATCH 2/3] add checkbox for display_subtitle and display_img --- app/views/admin/announcements/_form.html.erb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index c789e22..96b6587 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -67,6 +67,21 @@ + +
+ <%= f.label :display_subtitle, 'display subtitle', :class => "control-label muted" %> +
+ <%= f.check_box :display_subtitle %> +
+
+ + +
+ <%= f.label :display_img, 'display img src', :class => "control-label muted" %> +
+ <%= f.check_box :display_img %> +
+
@@ -469,4 +484,4 @@ }); -<% end %> \ No newline at end of file +<% end %> From 0cba386e89a6a7d2c6e9b22717ea949e5b2eeeaf Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 13 Jan 2020 15:16:46 +0800 Subject: [PATCH 3/3] return subtitle_ann / img_src when they are displayable --- app/controllers/announcements_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 96cdfac..576e284 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -336,18 +336,23 @@ class AnnouncementsController < ApplicationController 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"}]) + subtitle_ann = nil + img_src = nil + subtitle_ann = announcement.subtitle if announcement.display_subtitle? + img_src = (announcement.image.thumb.url || "/assets/announcement-default.jpg") if announcement.display_img? + { "tags" => tags, "bulletin_files" => files, "bulletin_links" => links, "data" => { "title" => announcement.title, - "subtitle_ann" => announcement.subtitle, + "subtitle_ann" => subtitle_ann, "update_user" => update_user, "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", + "img_src" => img_src, "alt_title" => desc }, "impressionist" => (announcement.is_preview ? nil : announcement),