Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions app/controllers/admin/edition_images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ def create
@images.each { |image| @edition.images.delete(image) }
end

render :index
if @images.many?
render :index
else
# @images.first.image_data.file.cache!
# binding.pry
@images.first.image_data.file.cache_stored_file!

redirect_to edit_admin_edition_image_path(@edition, @images.first.id)
end
end

def create_image(image)
Expand All @@ -76,14 +84,16 @@ def edit
private

def image_url
return unless image&.image_data&.original_uploaded?

image_data = image.image_data
unless image_data.file.cached?
image_data.file.download! image_data.file.url
if image&.image_data&.original_uploaded?
unless image_data.file.cached?
image_data.file.download! image_data.file.url
end
img_data = Base64.strict_encode64(image_data.file.read)
else
image_file = CarrierWave::SanitizedFile.new(File.join(image.image_data.file.root, image.image_data.file.path))
img_data = Base64.strict_encode64(image_file.read)
end
img_data = Base64.strict_encode64(image_data.file.read)

"data:#{image_data.file.content_type};base64,#{img_data}"
end
helper_method :image_url
Expand Down Expand Up @@ -118,6 +128,10 @@ def enforce_permissions!
end
end

def action_on_upload
@action_on_upload = params[:action_on_upload]
end

def images_params
params.fetch(:images, []).map { |image| image.permit(image_data: %i[file]) }
end
Expand Down
4 changes: 4 additions & 0 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ImageUploader < WhitehallUploader
config.validate_integrity = true
end

def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def downloader
# this overloads the downloader from Carrierwave::Uploader::Base
# so that `download!` can be used in development and test environments
Expand Down
7 changes: 7 additions & 0 deletions app/uploaders/storage/previewable_storage.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
class Storage::PreviewableStorage < CarrierWave::Storage::Abstract
def store!(carrierwave_file)
path = ::File.expand_path(uploader.store_path, uploader.root)
if uploader.move_to_store
carrierwave_file.move_to(path, uploader.permissions, uploader.directory_permissions)
else
carrierwave_file.copy_to(path, uploader.permissions, uploader.directory_permissions)
end

original_file = carrierwave_file.to_file
temporary_location = Whitehall::AssetManagerStorage::TempStorage.store!(original_file)

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/edition_images/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<%= hidden_field_tag("image[image_data][image_kind]", image.image_data.image_kind) %>

<% if image.can_be_cropped? && image.image_data&.original_uploaded? %>
<% if image.can_be_cropped? && image_url %>
<%= render "components/image_cropper", {
name: "image[image_data][crop_data]",
src: image_url,
Expand Down
Loading