diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index cb8efc6..04a61a6 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -36,26 +36,62 @@ class GalleriesController < ApplicationController end def index + page = OrbitHelper.page @album_setting = AlbumSetting.first page_no = OrbitHelper.page_number data_count = OrbitHelper.page_data_count albums = Album.filter_by_categories.filter_by_tags.asc(:order).page(page_no).per(data_count) album_color_map = AlbumColor.where(:album_id.in=> albums.pluck(:id)).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h + @image_version = 'thumb' + ModuleApp.all.select{|tmp| tmp.key.to_s=='gallery'}.each do |modile_app| + @show_option_items = modile_app.show_option_items rescue nil + end + if !(@show_option_items.nil?) + I18n.with_locale(:en) do + page.select_option_items.each do |select_option_item| + case select_option_item.field_name + when @show_option_items.keys[1].to_s + value = YAML.load(select_option_item.value) + tmp = value[:en] + if tmp == t('gallery.small_size') + @image_version = 'thumb' + elsif tmp == t('gallery.medium_size') + @image_version = 'thumb_large' + elsif tmp == t('gallery.large_size') + @image_version = 'mobile' + end + end + end + end + end + galleries = albums.collect do |a| doc = Nokogiri::HTML(a.description.to_s) alt_text = doc.text.empty? ? 'gallery image' : doc.text colors = album_color_map[a.id] || [] - thumb_src = a.cover_path || "/assets/gallery/default.jpg" + thumb_src = a.cover_path(@image_version) + if thumb_src + thumb_srcs = thumb_src.split('/') + thumb_srcs[-1] = thumb_srcs[-1].sub(/^\w+_/,"") + thumb_path = thumb_srcs[0..-2].join('/') + thumb_path_name = thumb_srcs[-1] + src = "#{thumb_path}/#{thumb_path_name}" + thumb_large_src = "#{thumb_path}/thumb_large_#{thumb_path_name}" + mobile_src = "#{thumb_path}/mobile_#{thumb_path_name}" + theater_src = "#{thumb_path}/theater_#{thumb_path_name}" + else + src = thumb_src = thumb_large_src = mobile_src = theater_src = "/assets/gallery/default.jpg" + end { "album-name" => a.name, "album-description" => a.description, "alt_title" => alt_text, "link_to_show" => OrbitHelper.url_to_show(a.to_param), "thumb-src" => thumb_src, - "src" => thumb_src.sub('thumb_','') , - "thumb-large-src" => thumb_src.sub("thumb_","thumb_large_"), - "mobile-src" => thumb_src.sub("thumb_","mobile_"), - "theater-src" => thumb_src.sub("thumb_","theater_"), + "src" => src, + "thumb-large-src" => thumb_large_src, + "mobile-src" => mobile_src, + "theater-src" => theater_src, "album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'), "album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color) } diff --git a/app/models/album.rb b/app/models/album.rb index 84b8b2c..d1df3c2 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -61,7 +61,7 @@ class Album Position object at bottom-right of region """ tmp = self[:resize_gravity] - (tmp.blank? ? (AlbumSetting.first.resize_gravity.blank? ? "Center" : AlbumSetting.first.resize_gravity) : tmp) rescue 'Center' + tmp.blank? ? OrbitHelper::SharedHash['gallery'][:resize_gravity] : tmp end def self.find_by_param(input) self.find_by(uid: input.to_s) @@ -98,10 +98,17 @@ class Album end tmp end - def cover_path + def cover_path(thumb_version='thumb') tmp = self['cover_path'] - if tmp.nil? - tmp = (self.album_images.first.file.thumb.url rescue nil) + if tmp.nil? && self.album_images.first + case thumb_version + when 'thumb' + tmp = self.album_images.first.file.thumb.url + when 'thumb_large' + tmp = self.album_images.first.file.thumb_large.url + when 'mobile' + tmp = self.album_images.first.file.mobile.url + end end tmp end diff --git a/app/models/album_setting.rb b/app/models/album_setting.rb index 9d5c2a5..6215400 100644 --- a/app/models/album_setting.rb +++ b/app/models/album_setting.rb @@ -2,9 +2,17 @@ class AlbumSetting include Mongoid::Document include Mongoid::Timestamps field :limit - field :resize_gravity, type: String, default: 'center' + field :resize_gravity, type: String, default: 'Center' ResizeGravities = %w[Center NorthWest North NorthEast West East SouthWest South SouthEast] field :album_card_background_color, default: '' field :album_card_text_color, default: '#000000' field :min_order, type: Integer, default: -1 + field :thumb_process_option, type: Integer, default: 1 + + before_save do + if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash + OrbitHelper::SharedHash['gallery'][:thumb_process_option] = self.thumb_process_option + OrbitHelper::SharedHash['gallery'][:resize_gravity] = self.resize_gravity + end + end end \ No newline at end of file diff --git a/app/uploaders/gallery_uploader.rb b/app/uploaders/gallery_uploader.rb index 82bf8b7..839cd9e 100644 --- a/app/uploaders/gallery_uploader.rb +++ b/app/uploaders/gallery_uploader.rb @@ -177,12 +177,16 @@ class GalleryUploader < CarrierWave::Uploader::Base end def thumb_process(w,h) now_album = model.album - case now_album.thumb_process_option - when 0 - resize_and_pad(w, h, (transparent? ? :transparent : now_album.album_colors.first['color']), (now_album.resize_gravity rescue 'Center')) + thumb_process_option = now_album.thumb_process_option + if thumb_process_option == 0 + thumb_process_option = OrbitHelper::SharedHash['gallery'][:thumb_process_option] + end + case thumb_process_option when 1 - limit_process(w, h) + resize_and_pad(w, h, (transparent? ? :transparent : now_album.album_colors.first['color']), (now_album.resize_gravity rescue 'Center')) when 2 + limit_process(w, h) + when 3 resize_to_fill(w, h) end end diff --git a/app/views/admin/galleries/_form.html.erb b/app/views/admin/galleries/_form.html.erb index 7283f6a..14a1315 100644 --- a/app/views/admin/galleries/_form.html.erb +++ b/app/views/admin/galleries/_form.html.erb @@ -122,7 +122,7 @@ input.minicolors-input{ <%= f.fields_for :album_colors do |album_color_form| %> -