From d578dc1fd037a25d544c42eeb9c22458d76bd8d9 Mon Sep 17 00:00:00 2001 From: icyleaf Date: Tue, 28 May 2024 07:52:59 +0000 Subject: [PATCH] refactor: extract delete all button out of bulk operation form --- app/controllers/channels_controller.rb | 16 ++++++++-------- app/views/channels/filters/_list.html.slim | 3 --- app/views/channels/filters/index.html.slim | 6 ++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 3ad657d34..2dbde88a1 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -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 diff --git a/app/views/channels/filters/_list.html.slim b/app/views/channels/filters/_list.html.slim index 5f26d9fc4..3310d356b 100644 --- a/app/views/channels/filters/_list.html.slim +++ b/app/views/channels/filters/_list.html.slim @@ -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') } diff --git a/app/views/channels/filters/index.html.slim b/app/views/channels/filters/index.html.slim index 28f2adb50..1f356ae45 100644 --- a/app/views/channels/filters/index.html.slim +++ b/app/views/channels/filters/index.html.slim @@ -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') }