fix MR comments

This commit is contained in:
Bilal
2020-07-24 14:57:35 +02:00
parent f8bdc5bce5
commit 7ef27d4c1d
8 changed files with 14 additions and 16 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -1,4 +1,5 @@
<div class="row">
<% 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" %>
<div class="<%= file_class %>">
@@ -17,7 +18,6 @@
</div>
<% if show_delete %>
<div class="col-4 align-self-center p-0 m-0">
<% 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') } %>
</div>

View File

@@ -8,7 +8,7 @@
<div class="overflow-auto mh-30">
<ul class="list-unstyled d-flex flex-column align-items-center text-center" id="broadcast_file_list_<%= broadcast.token %>">
<% if files.present? %>
<%= render partial: "broadcasts/file", locals: { broadcast: broadcast }, collection: files %>
<%= render partial: "broadcasts/file", collection: files %>
<% else %>
<li class="my-3">
Files will appear here.

View File

@@ -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();

View File

@@ -1 +0,0 @@
<% render "update_file_list" %>

View File

@@ -1 +1,9 @@
<% render "update_file_list" %>
$("#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();

View File

@@ -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")