Skip to content

Commit

Permalink
refactor: extract delete all button out of bulk operation form
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed May 28, 2024
1 parent 607d163 commit d578dc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions app/controllers/channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def destroy

def destroy_releases
channel = Channel.friendly.find(params[:name] || params[:id])
# authorize channel

# if params[:channel].blank?
# channel.releases.destroy_all
# else
# delete_params = params.require(:channel).permit(release_ids: [])
# channel.releases.where(id: delete_params[:release_ids]).destroy_all
# end
authorize channel

if params[:channel].blank?
channel.releases.destroy_all
else
delete_params = params.require(:channel).permit(release_ids: [])
channel.releases.where(id: delete_params[:release_ids]).destroy_all
end

redirect_to friendly_channel_versions_path(channel), status: :see_other
end
Expand Down
3 changes: 0 additions & 3 deletions app/views/channels/filters/_list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@

- if current_user&.manage?(app: channel.app)
.actions
.float-right
= button_to t('.delete_all'), bulk_delete_url(channel), class: 'btn btn-danger', \
method: :delete, data: { turbo_confirm: t('channels.messages.confirm.destroy') }
.buttons
= f.submit t('.delete'), class: 'btn btn-danger', \
data: { bulk_operation_target: 'destroyButton', turbo_confirm: t('channels.messages.confirm.destroy') }
Expand Down
6 changes: 6 additions & 0 deletions app/views/channels/filters/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
= t('links.back_to_list')

== render 'channels/filters/list', releases: @releases, channel: @channel

- if @releases.present? && current_user&.manage?(app: @channel.app)
.card
.card-body
= button_to t('channels.filters.list.delete_all'), bulk_delete_url(@channel), class: 'btn btn-danger', \
method: :delete, data: { turbo_confirm: t('channels.messages.confirm.destroy') }

0 comments on commit d578dc1

Please sign in to comment.