Skip to content

Commit

Permalink
Extract archive rendering related controller code
Browse files Browse the repository at this point in the history
In admin attachments and admin elements controllers we use the
same code to handle the archive rendering. Either in an overlay
dialog (if a content_id is available) or as normal html index view.
  • Loading branch information
tvdeyen committed Sep 28, 2018
1 parent b532741 commit 3eb9910
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
13 changes: 1 addition & 12 deletions app/controllers/alchemy/admin/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Alchemy
module Admin
class AttachmentsController < ResourcesController
include UploaderResponses
include ArchiveOverlay

helper 'alchemy/admin/tags'

Expand Down Expand Up @@ -85,18 +86,6 @@ def handle_uploader_response(status:)
end
end

def in_overlay?
params[:content_id].present?
end

def archive_overlay
@content = Content.find_by(id: params[:content_id])
respond_to do |format|
format.html { render partial: 'archive_overlay' }
format.js { render action: 'archive_overlay' }
end
end

def attachment_attributes
params.require(:attachment).permit(:file, :name, :file_name, :tag_list)
end
Expand Down
14 changes: 1 addition & 13 deletions app/controllers/alchemy/admin/pictures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Alchemy
module Admin
class PicturesController < Alchemy::Admin::ResourcesController
include UploaderResponses
include ArchiveOverlay

helper 'alchemy/admin/tags'

Expand Down Expand Up @@ -143,19 +144,6 @@ def pictures_per_page_for_size(size)
end
end

def in_overlay?
params[:content_id].present?
end

def archive_overlay
@content = Content.find_by(id: params[:content_id])

respond_to do |format|
format.html { render partial: 'archive_overlay' }
format.js { render action: 'archive_overlay' }
end
end

def redirect_to_index
do_redirect_to admin_pictures_path(search_filter_params)
end
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/concerns/alchemy/admin/archive_overlay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Alchemy
module Admin
module ArchiveOverlay
private

def in_overlay?
params[:content_id].present?
end

def archive_overlay
@content = Content.find_by(id: params[:content_id])

respond_to do |format|
format.html { render partial: 'archive_overlay' }
format.js { render action: 'archive_overlay' }
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/admin/pictures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module Alchemy
end

context 'in overlay' do
let(:params) { {element_id: :id, size: size} }
let(:params) { {content_id: :id, size: size} }

context 'with params[:size] set to medium' do
let(:size) { 'medium' }
Expand Down

0 comments on commit 3eb9910

Please sign in to comment.