diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 98c7316..7dba55f 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -169,6 +169,49 @@ class GalleriesController < ApplicationController "extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url} } end + + def image_sort + @album_setting = AlbumSetting.first + tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags + albums = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags).to_a + album_ids = [] + albums_map = {} + albums.each do |ab| + album_ids << ab.id + albums_map[ab.id] = ab + end + album_color_map = AlbumColor.where(:album_id.in=> album_ids).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h + counts = OrbitHelper.widget_data_count + images = AlbumImage.where(:album_id.in=>album_ids).asc(:order).limit(counts) + images = images.each_with_index.collect do |a,i| + colors = album_color_map[a.album_id] || [] + alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description).text().strip) + f = a.file + ab = albums_map[a.album_id] + { + "link_text" => "", + "link_to_show" => OrbitHelper.widget_more_url + "/" + ab.to_param + "#" + a.id.to_s, + "alt_title" => alt_text, + "src" => f.url, + "thumb-src" => f.thumb.url, + "thumb-large-src" => f.thumb_large.url, + "image_description" => a.description, + "image_short_description" => a.title, + "mobile-src" => f.mobile.url, + "theater-src" => f.theater.url, + "album-name" => ab.name_translations[I18n.locale], + "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), + "sort_order" => a.order.to_i, + "i" => i + } + end + { + "images" => images, + "extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url} + } + end + def widget @album_setting = AlbumSetting.first tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags