Skip to content

Commit

Permalink
flatten ifs in catalog_controller image processing
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Oct 25, 2024
1 parent 1bec024 commit d1858bb
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,31 +534,28 @@ def st_upload_image

err = false
identify_catalog(params[:id])
image_file = params.dig(:upload, :image)
if params[:pressed]
@record.picture = nil
@record.save
msg = _("Custom Image successfully removed")
elsif params[:upload] && params[:upload][:image] &&
params[:upload][:image].respond_to?(:read)
ext = params[:upload][:image].original_filename.split(".").last.downcase
if !valid_image_file?(params[:upload][:image])
msg = _("Custom Image must be a .png or .jpg file")
err = true
else
picture = {:content => params[:upload][:image].read,
:extension => ext}
if @record.picture.nil?
@record.picture = Picture.new(picture)
else
@record.picture.update(picture)
end
@record.save
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
{:name => params[:upload][:image].original_filename}
end
else
elsif !image_file&.respond_to?(:read)
msg = _("Use the Choose file button to locate a .png or .jpg image file")
err = true
elsif !valid_image_file?(image_file)
msg = _("Custom Image must be a .png or .jpg file")
err = true
else
ext = File.extname(image_file.original_filename).downcase
picture = {:content => image_file.read, :extension => ext}
if @record.picture.nil?
@record.picture = Picture.new(picture)
else
@record.picture.update(picture)
end
@record.save
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
{:name => image_file.original_filename}
end
params[:id] = x_build_node_id(@record) # Get the tree node id
add_flash(msg, err == true ? :error : nil)
Expand Down

0 comments on commit d1858bb

Please sign in to comment.