add option for user can change image version at subpart

This commit is contained in:
chiu 2020-01-21 22:31:59 +08:00
parent 9883c41966
commit 5c7dfb0d53
4 changed files with 54 additions and 3 deletions

View File

@ -223,6 +223,25 @@ class AnnouncementsController < ApplicationController
def pack_data(announcements, top_anns = [])
page = Page.where(:module => "announcement").first rescue nil
subpart = OrbitHelper.get_current_widget
@image_version = 'thumb'
if subpart.methods.include? 'select_options'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app|
@show_options = modile_app.show_options rescue nil
end
subpart.select_options.each do |select_option|
if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s
value = YAML.load(select_option.value)
if value[I18n.locale] == t('announcement.small_size')
@image_version = 'thumb'
elsif value[I18n.locale] == t('announcement.medium_size')
@image_version = 'mobile'
elsif value[I18n.locale] == t('announcement.orignal_size')
@image_version = 'orignal'
end
end
end
end
feeds_anns = get_feed_announcements("widget")
announcements = announcements + feeds_anns
if !feeds_anns.blank?
@ -250,6 +269,13 @@ class AnnouncementsController < ApplicationController
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"
if @image_version == 'thumb'
image_url = a.image.thumb.url
elsif @image_version == 'mobile'
image_url = a.image.mobile.url
else
image_url = a.image.url
end
anns << {
"bulletin_links" => links,
"bulletin_files" => files,
@ -264,7 +290,7 @@ class AnnouncementsController < ApplicationController
"author" => author,
"link_to_show" => link_to_show,
"target" => target,
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
"img_src" => image_url || "/assets/announcement-default.jpg",
"img_description" => desc
}
else

View File

@ -3,6 +3,10 @@ en:
feed: Feed
import: Import
announcement:
picture_showing_size: Picture Showing Size
orignal_size: Original Size
small_size: Small Size
medium_size: Medium Size
table:
title : Title
date : Date

View File

@ -3,6 +3,10 @@ zh_tw:
feed: 供給
import: 匯入
announcement:
picture_showing_size: 圖片顯示大小
orignal_size: 原圖大小
small_size: 小張縮圖
medium_size: 中等縮圖
table:
title : 標題
date : 張貼日期

View File

@ -2,6 +2,19 @@ require "yaml"
module Announcement
class Engine < ::Rails::Engine
initializer "announcement" do
translate_data = Dir["#{Announcement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {}
key1 = {}
value1 = {}
value2 = {}
value3 = {}
translate_data.each do |t_data|
key1[t_data.keys[0]] = t_data.values[0]['announcement']['picture_showing_size']
value1[t_data.keys[0]] = t_data.values[0]['announcement']['small_size']
value2[t_data.keys[0]] = t_data.values[0]['announcement']['medium_size']
value3[t_data.keys[0]] = t_data.values[0]['announcement']['orignal_size']
end
data[key1] = [value1,value2,value3]
OrbitApp.registration "Announcement", :type => "ModuleApp" do
module_label "announcement.announcement"
base_url File.expand_path File.dirname(__FILE__)
@ -13,7 +26,11 @@ module Announcement
frontend_enabled
feeds_url "/xhr/announcements/feeds"
data_count 1..30
begin
show_options data
rescue => e
puts ['there_was_no_show_option_method',e]
end
side_bar do
head_label_i18n 'announcement.announcement', icon_class: "icons-megaphone"
available_for "users"