diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index 1568466..ae08ddc 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -60,10 +60,19 @@ class Admin::GalleriesController < OrbitAdminController def rotate_images begin image_ids = params['image_ids'].split(',') - images = AlbumImage.find(image_ids) - count = images.length + count = image_ids.count rot_ang = params[:rotate_angle].to_i - images.each_with_index do |image,index| + variable = AlbumVariable.first + if variable.nil? + variable = AlbumVariable.new + end + variable.finish = false + variable.save! + Thread.new do + variable = AlbumVariable.first + image_ids.each_with_index do |image_id,index| + image = AlbumImage.find(image_id) rescue nil + next if image.nil? if !(image.album_crops.first.nil?) w_and_h = image.file.get_w_and_h cords = image.album_crops.map{|v| [[v.crop_x.to_f,v.crop_y.to_f], @@ -94,16 +103,6 @@ class Admin::GalleriesController < OrbitAdminController end image.album_crops.first.update_attributes(crop_x: all_x.min,crop_y: all_y.min,crop_w: all_x.max - all_x.min,crop_h: all_y.max - all_y.min) end - end - variable = AlbumVariable.first - if variable.nil? - variable = AlbumVariable.new - end - variable.finish = false - variable.save! - Thread.new do - variable = AlbumVariable.first - images.each_with_index do |image,index| variable.progress_percent = (index*100.0/count).floor.to_s+'%' image.file.rotate_ang(rot_ang) all_version = image.file.versions.map{|k,v| k} @@ -132,22 +131,13 @@ class Admin::GalleriesController < OrbitAdminController def save_crop begin - images = AlbumImage.all.select{|value| params[:id].include? value.id.to_s} - id = images.first.album_id.to_s + images = AlbumImage.where(:id.in => Array(params[:id])) x = params['x'] y = params['y'] w = params['w'] h = params['h'] cords = x.zip(y,w,h) count = cords.length - images.each_with_index do |image,index| - cord = cords[index] - if image.album_crops.first.nil? - image.album_crops.create(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) - else - image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) - end - end variable = AlbumVariable.first if variable.nil? variable = AlbumVariable.new @@ -156,8 +146,16 @@ class Admin::GalleriesController < OrbitAdminController variable.save! Thread.new do variable = AlbumVariable.first - images.each_with_index do |image,index| - variable.progress_percent = (index*100.0/count).floor.to_s+'%' + image_ids= images.pluck(:id) + image_ids.each_with_index do |image_id,index| + image = AlbumImage.find(image_id) + cord = cords[index] + if image.album_crops.first.nil? + image.album_crops.create(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) + else + image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) + end + variable.progress_percent = (index*100.0/count).floor.to_s+'%' all_version = image.file.versions.map{|k,v| k} begin #org_fname = image.file.path @@ -201,7 +199,7 @@ class Admin::GalleriesController < OrbitAdminController variable.finish = false variable.save! choice_ids = params['album_id'].split(',') - albums = Album.all.select { |value| (choice_ids.include? value.id.to_s)} + albums = Album.where(:id.in => choice_ids) if !(params['use_default']=='true') color = params['color_choice'].to_s.empty? ? 'transparent' : params['color_choice'] albums.each do |album| @@ -212,14 +210,15 @@ class Admin::GalleriesController < OrbitAdminController end end end - count = 0 - albums.each{|album| count+=album.album_images.count } + count = albums.reduce(0){|x,i| i.album_images.count+x} Thread.new do i = 0 - album_ids = albums.map{|v| v.id}.clone + album_ids = albums.pluck(:id) album_ids.each do |album_id| album = Album.find(album_id) rescue Album.new() - album.album_images.each do |image| + album_image_ids = album.album_images.pluck(:id) + album_image_ids.each do |image_id| + image = AlbumImage.find(image_id) error = nil all_version = image.file.versions.map{|k,v| k} begin