Adjust code style.

This commit is contained in:
BoHung Chiu 2023-04-24 10:44:50 +08:00
parent 20f893e5b9
commit 6a877c8e2d
1 changed files with 75 additions and 73 deletions

View File

@ -110,10 +110,10 @@ class Admin::GalleriesController < OrbitAdminController
begin begin
variable.progress_filename = image[:file].to_s variable.progress_filename = image[:file].to_s
all_version.each do |version| all_version.each do |version|
if !(version.to_s == 'resized' && crop_but_no_backup(image)) if !(version.to_s == 'resized' && crop_but_no_backup(image))
image.file.recreate_versions! version image.file.recreate_versions! version
image.save! image.save!
end end
end end
rescue => e rescue => e
variable.progress_filename = e.inspect.to_s variable.progress_filename = e.inspect.to_s
@ -123,9 +123,9 @@ class Admin::GalleriesController < OrbitAdminController
end end
variable.finish = true variable.finish = true
variable.save! variable.save!
end end
rescue => e rescue => e
puts e.inspect puts e.inspect
end end
redirect_to :controller=> 'images' ,:action => 'crop_process' redirect_to :controller=> 'images' ,:action => 'crop_process'
end end
@ -147,40 +147,40 @@ class Admin::GalleriesController < OrbitAdminController
variable.save! variable.save!
Thread.new do Thread.new do
variable = AlbumVariable.first variable = AlbumVariable.first
image_ids= images.pluck(:id) image_ids= images.pluck(:id)
image_ids.each_with_index do |image_id,index| image_ids.each_with_index do |image_id,index|
image = AlbumImage.find(image_id) image = AlbumImage.find(image_id)
cord = cords[index] cord = cords[index]
if image.album_crops.first.nil? 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]) image.album_crops.create(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3])
else else
image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) 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.progress_percent = (index*100.0/count).floor.to_s+'%' variable.progress_percent = (index*100.0/count).floor.to_s+'%'
all_version = image.file.versions.map{|k,v| k} all_version = image.file.versions.map{|k,v| k}
begin begin
#org_fname = image.file.path #org_fname = image.file.path
#org_extname = File.extname(org_fname) #org_extname = File.extname(org_fname)
#org_fname.slice! org_extname #org_fname.slice! org_extname
#FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname) #FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname)
variable.progress_filename = image[:file].to_s variable.progress_filename = image[:file].to_s
all_version.each do |version| all_version.each do |version|
if !(version.to_s == 'resized' && crop_but_no_backup(image)) if !(version.to_s == 'resized' && crop_but_no_backup(image))
image.file.recreate_versions! version image.file.recreate_versions! version
image.save! image.save!
end
end end
rescue => e
variable.progress_filename = e.inspect.to_s
puts e.inspect
end end
variable.save! rescue => e
variable.progress_filename = e.inspect.to_s
puts e.inspect
end
variable.save!
end end
variable.finish = true variable.finish = true
variable.save! variable.save!
end end
rescue => e rescue => e
puts e.inspect puts e.inspect
end end
redirect_url = "/admin/galleries/crop_process" redirect_url = "/admin/galleries/crop_process"
render :json => {'href' => redirect_url}.to_json render :json => {'href' => redirect_url}.to_json
@ -356,13 +356,13 @@ class Admin::GalleriesController < OrbitAdminController
end end
def edit def edit
@album = Album.find(params[:id]) @album = Album.find(params[:id])
if can_edit_or_delete?(@album) if can_edit_or_delete?(@album)
@tags = @module_app.tags @tags = @module_app.tags
@categories = @module_app.categories @categories = @module_app.categories
else else
render_401 render_401
end end
end end
def import def import
@ -465,8 +465,10 @@ class Admin::GalleriesController < OrbitAdminController
image_title: image.title, image_title: image.title,
image_description: image.description, image_description: image.description,
image_file: { url: "http://#{request.host_with_port}#{@image_file}", image_file: { url: "http://#{request.host_with_port}#{@image_file}",
thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"}, thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"
image_tag_names: tags} },
image_tag_names: tags
}
end end
render :json=>JSON.pretty_generate(output) render :json=>JSON.pretty_generate(output)
@ -487,7 +489,7 @@ class Admin::GalleriesController < OrbitAdminController
order: values.order, order: values.order,
tags: values.tags} tags: values.tags}
end end
render :json=>{"images" => @output, "tags" => @album.tags}.to_json render :json=>{"images" => @output, "tags" => @album.tags}.to_json
end end
@ -547,19 +549,19 @@ class Admin::GalleriesController < OrbitAdminController
files = params['files'] files = params['files']
album_unprocess = AlbumUnprocess.new() album_unprocess = AlbumUnprocess.new()
files.each do |file| files.each do |file|
image = album.album_images.new image = album.album_images.new
image.tags = (album.tags rescue []) image.tags = (album.tags rescue [])
if(AlbumVariable.first.count==1 rescue true) if(AlbumVariable.first.count==1 rescue true)
image.file = file image.file = file
else else
album_unprocess.image_id = image.id album_unprocess.image_id = image.id
album_unprocess.upload_success = false album_unprocess.upload_success = false
album_unprocess.save_var = file album_unprocess.save_var = file
album_unprocess.save! album_unprocess.save!
ObjectSpace.undefine_finalizer(file.tempfile) ObjectSpace.undefine_finalizer(file.tempfile)
request.set_header(Rack::RACK_TEMPFILES, []) if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically. request.set_header(Rack::RACK_TEMPFILES, []) if RackTempMiddleExist # Avoid Rack::TempfileReaper Middleware to unlink temp files automatically.
end end
image.save! image.save!
end end
render :json=>{"files"=>[{}]}.to_json render :json=>{"files"=>[{}]}.to_json
end end
@ -620,26 +622,26 @@ class Admin::GalleriesController < OrbitAdminController
end end
def update_children_image_tag(album,tagsToDestroy,tagsToAdd) def update_children_image_tag(album,tagsToDestroy,tagsToAdd)
# tagsToDestroy will contain all tag ids which have to be deleted from the galley_images # tagsToDestroy will contain all tag ids which have to be deleted from the galley_images
# tagsToAdd will contain all tag ids which ve to be added in tall album_images # tagsToAdd will contain all tag ids which ve to be added in tall album_images
images = album.album_images images = album.album_images
images.each do |image| images.each do |image|
image_tags = image.tag_ids.map(&:to_s) image_tags = image.tag_ids.map(&:to_s)
tagsToAdd.each do |tag| tagsToAdd.each do |tag|
image_tags << tag image_tags << tag
end
tagsToDestroy.each do |tag|
if image_tags.include?tag
image_tags.delete(tag)
end
end
image.tags = image_tags
image.save
end end
tagsToDestroy.each do |tag|
if image_tags.include?tag
image_tags.delete(tag)
end
end
image.tags = image_tags
image.save
end
end end
private private
def crop_but_no_backup image def crop_but_no_backup(image)
fname = image.file.path fname = image.file.path
extension = File.extname(fname) extension = File.extname(fname)
base_name = fname.chomp(extension) base_name = fname.chomp(extension)