From 3f323c70fc0bc6f749614ff90efc8d06e0d2e2af Mon Sep 17 00:00:00 2001 From: Bohung Date: Fri, 11 Jun 2021 17:15:51 +0800 Subject: [PATCH] Fix bug. Add carousel image width setting. --- app/controllers/announcements_controller.rb | 4 ++-- app/models/announcement_setting.rb | 2 +- app/models/bulletin.rb | 4 ++++ app/views/admin/announcements/_form.html.erb | 6 ++++++ app/views/admin/announcements/settings.html.erb | 6 ++++++ config/locales/en.yml | 3 +++ config/locales/zh_tw.yml | 3 +++ modules/announcement/show.html.erb | 17 ++++++++++++++++- 8 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 78c1fb9..ccbd0df 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -596,7 +596,7 @@ class AnnouncementsController < ApplicationController "pause_btn_title" => pause_btn_title, "prev_btn_title" => prev_btn_title, "next_btn_title" => next_btn_title, - "carousel_display_style" => (bulletin_carousel_images.count == 0 ? 'display: none' : 'width: 50%;margin: auto;'), + "carousel_display_style" => (bulletin_carousel_images.count == 0 ? 'display: none' : "width: #{announcement.carousel_image_width};margin: auto;"), "carousel_count" => bulletin_carousel_images.count }, "comments" => announcement.comments, @@ -680,7 +680,7 @@ class AnnouncementsController < ApplicationController "pause_btn_title" => pause_btn_title, "prev_btn_title" => prev_btn_title, "next_btn_title" => next_btn_title, - "carousel_display_style" => (bulletin_carousel_images.count == 0 ? 'display: none' : 'width: 50%;margin: auto;'), + "carousel_display_style" => (bulletin_carousel_images.count == 0 ? 'display: none' : "width: #{AnnouncementSetting.last.carousel_image_width};margin: auto;"), "carousel_count" => bulletin_carousel_images.count }, "comments" => [], diff --git a/app/models/announcement_setting.rb b/app/models/announcement_setting.rb index e4a7810..3f19b45 100644 --- a/app/models/announcement_setting.rb +++ b/app/models/announcement_setting.rb @@ -1,7 +1,7 @@ class AnnouncementSetting include Mongoid::Document include Mongoid::Timestamps - + field :carousel_image_width, type: String, :default => "75%" field :top_limit, type: Integer, :default => 0 field :pro_enabled, type: Boolean, :default => false field :approvers, type: Array, :default => [] diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index a669e03..1076a5f 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -26,6 +26,7 @@ class Bulletin before_destroy do AnnsCache.all.destroy end + field :custom_carousel_image_width, type: String, default: "" field :image_display_class, type: String, default: "full-size-img" #3 choices: full-size-img , pull-left , pull-right field :add_to_calendar,type: Boolean,default: false field :calendar_start_date, :type => DateTime @@ -222,4 +223,7 @@ class Bulletin def hidden_text I18n.t("announcement.status.hidden") end + def carousel_image_width + (self.custom_carousel_image_width.blank? ? AnnouncementSetting.last.carousel_image_width : self.custom_carousel_image_width) + end end diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index 6d8954c..68a8732 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -303,6 +303,12 @@