From 7ef27d4c1df5cb91462fbd429d8e207a2983e0e3 Mon Sep 17 00:00:00 2001 From: Bilal Date: Fri, 24 Jul 2020 14:57:35 +0200 Subject: [PATCH] fix MR comments --- app/channels/broadcasts_channel.rb | 2 +- app/controllers/broadcasts_controller.rb | 2 +- app/views/broadcasts/_file.html.erb | 2 +- app/views/broadcasts/_files_section.html.erb | 2 +- app/views/broadcasts/_update_file_list.js.erb | 9 --------- app/views/broadcasts/destroy_file.js.erb | 1 - app/views/broadcasts/update.js.erb | 10 +++++++++- spec/channels/broadcasts_channel_spec.rb | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 app/views/broadcasts/_update_file_list.js.erb delete mode 100644 app/views/broadcasts/destroy_file.js.erb diff --git a/app/channels/broadcasts_channel.rb b/app/channels/broadcasts_channel.rb index f503c01..ad96756 100644 --- a/app/channels/broadcasts_channel.rb +++ b/app/channels/broadcasts_channel.rb @@ -37,7 +37,7 @@ class BroadcastsChannel < ApplicationCable::Channel end def self.broadcast_file_upload_updates(broadcast, files, pagination_content) - files_content = ApplicationController.render partial: "broadcasts/file", locals: { broadcast: broadcast }, collection: files + files_content = ApplicationController.render partial: "broadcasts/file", collection: files broadcast_to broadcast, { event: :file_upload_update, diff --git a/app/controllers/broadcasts_controller.rb b/app/controllers/broadcasts_controller.rb index 6f886b7..072498b 100644 --- a/app/controllers/broadcasts_controller.rb +++ b/app/controllers/broadcasts_controller.rb @@ -53,7 +53,7 @@ class BroadcastsController < ApplicationController def destroy_file authorize Broadcast file = ActiveStorage::Attachment.find(params[:file_id]) - file.purge + file.destroy update_files_section end diff --git a/app/views/broadcasts/_file.html.erb b/app/views/broadcasts/_file.html.erb index dec0579..f3b919d 100644 --- a/app/views/broadcasts/_file.html.erb +++ b/app/views/broadcasts/_file.html.erb @@ -1,4 +1,5 @@
+ <% broadcast = file.record %> <% show_delete = controller.class.module_parent.to_s == "Public" ? false : policy(broadcast).destroy_file? %> <% file_class = show_delete ? "col-8" : "col-12" %>
@@ -17,7 +18,6 @@
<% if show_delete %>
- <% broadcast = local_assigns[:broadcast] %> <% url = url_for [:destroy_file, broadcast.project, broadcast, { file_id: file.id }] %> <%= link_to fa_icon("trash fw", text: t('.actions.delete_file')), url, class: "btn btn-danger", remote: true, method: :delete, data: { confirm: t('.confirm_delete') } %>
diff --git a/app/views/broadcasts/_files_section.html.erb b/app/views/broadcasts/_files_section.html.erb index 17e9ee3..86865c8 100644 --- a/app/views/broadcasts/_files_section.html.erb +++ b/app/views/broadcasts/_files_section.html.erb @@ -8,7 +8,7 @@
    <% if files.present? %> - <%= render partial: "broadcasts/file", locals: { broadcast: broadcast }, collection: files %> + <%= render partial: "broadcasts/file", collection: files %> <% else %>
  • Files will appear here. diff --git a/app/views/broadcasts/_update_file_list.js.erb b/app/views/broadcasts/_update_file_list.js.erb deleted file mode 100644 index d8fefc6..0000000 --- a/app/views/broadcasts/_update_file_list.js.erb +++ /dev/null @@ -1,9 +0,0 @@ -$("#broadcast_file_form_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file_form", locals: { model: [@project, @broadcast], token: @broadcast.token }) %>"); - -var file_id = "#<%= dom_id(@files.first) %>" -if ($("#broadcast_file_list_<%= @broadcast.token %>").has(file_id).length == 0) { - $("#broadcast_file_list_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file", locals: { broadcast: @broadcast }, collection: @files) %>"); - $("#broadcast_files_pagination_<%= @broadcast.token %>").html("<%= j will_paginate(@files, param_name: 'files_page', params: { active_files_tab: @broadcast.token }) %>"); -} - -bsCustomFileInput.init(); diff --git a/app/views/broadcasts/destroy_file.js.erb b/app/views/broadcasts/destroy_file.js.erb deleted file mode 100644 index 6c4f45d..0000000 --- a/app/views/broadcasts/destroy_file.js.erb +++ /dev/null @@ -1 +0,0 @@ -<% render "update_file_list" %> \ No newline at end of file diff --git a/app/views/broadcasts/update.js.erb b/app/views/broadcasts/update.js.erb index 6c4f45d..f64dcc2 100644 --- a/app/views/broadcasts/update.js.erb +++ b/app/views/broadcasts/update.js.erb @@ -1 +1,9 @@ -<% render "update_file_list" %> \ No newline at end of file +$("#broadcast_file_form_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file_form", locals: { model: [@project, @broadcast], token: @broadcast.token }) %>"); + +var file_id = "#<%= dom_id(@files.first) %>" +if ($("#broadcast_file_list_<%= @broadcast.token %>").has(file_id).length == 0) { + $("#broadcast_file_list_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file", collection: @files) %>"); + $("#broadcast_files_pagination_<%= @broadcast.token %>").html("<%= j will_paginate(@files, param_name: 'files_page', params: { active_files_tab: @broadcast.token }) %>"); +} + +bsCustomFileInput.init(); \ No newline at end of file diff --git a/spec/channels/broadcasts_channel_spec.rb b/spec/channels/broadcasts_channel_spec.rb index 633ccd2..a540e3f 100644 --- a/spec/channels/broadcasts_channel_spec.rb +++ b/spec/channels/broadcasts_channel_spec.rb @@ -56,7 +56,7 @@ RSpec.describe BroadcastsChannel, type: :channel do describe ".broadcast_file_upload_updates" do it 'broadcasts to the channel with the right data' do broadcast = create(:broadcast, :with_stream, :with_files, skip_create_callback: true) - files_content = ApplicationController.render partial: "broadcasts/file", locals: { broadcast: broadcast }, collection: broadcast.files + files_content = ApplicationController.render partial: "broadcasts/file", collection: broadcast.files expect { BroadcastsChannel.broadcast_file_upload_updates(broadcast, broadcast.files, "pagination_content")