- <%= link_to file, target: "_blank" do %>
- <%= fa_icon("file", style: "font-size: 2rem") %>
-
<%= file.filename %>
+
+ <% show_delete = policy(broadcast).destroy_file? %>
+ <% file_class = show_delete ? "col-8" : "col-12" %>
+
+
+ <% if file.variable? %>
+ <%= link_to image_tag(file.variant(resize_and_pad: [300, 300, background: "#F7F8F9"]), class: "bg-light img-thumbnail img-fluid"), file, target: "_blank" %>
+ <% else %>
+
+ <%= link_to file, target: "_blank" do %>
+ <%= fa_icon("file", style: "font-size: 2rem") %>
+
<%= file.filename %>
+ <% end %>
+
<% end %>
+
+
+ <% 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') } %>
<% end %>
-
+
\ No newline at end of file
diff --git a/app/views/broadcasts/_files_section.html.erb b/app/views/broadcasts/_files_section.html.erb
index 86865c8..17e9ee3 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", collection: files %>
+ <%= render partial: "broadcasts/file", locals: { broadcast: broadcast }, 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
new file mode 100644
index 0000000..d8fefc6
--- /dev/null
+++ b/app/views/broadcasts/_update_file_list.js.erb
@@ -0,0 +1,9 @@
+$("#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
new file mode 100644
index 0000000..6c4f45d
--- /dev/null
+++ b/app/views/broadcasts/destroy_file.js.erb
@@ -0,0 +1 @@
+<% 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 a46716a..6c4f45d 100644
--- a/app/views/broadcasts/update.js.erb
+++ b/app/views/broadcasts/update.js.erb
@@ -1,9 +1 @@
-$("#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();
+<% render "update_file_list" %>
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0031f0f..5bc2fbb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -214,6 +214,10 @@ en:
destroy:
alert: A live stream has been deleted
api_error: Something went wrong, please try again later after some time
+ file:
+ actions:
+ delete_file: Delete
+ confirm_delete: Are you sure?
index:
actions:
new: Create New Live Stream
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 00d454a..52d5faf 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -81,6 +81,10 @@ es:
do_not_copy_warning: "Do not copy (ES)"
serial_number_label: "Serial Number (ES)"
broadcasts:
+ file:
+ actions:
+ delete_file: Delete
+ confirm_delete: Are you sure? (ES)
show:
actions:
reset_url: Reset URL (ES)
diff --git a/config/routes.rb b/config/routes.rb
index 6f2e9a9..bd619ac 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -96,6 +96,9 @@ Rails.application.routes.draw do
end
resources :projects, only: [] do
resources :broadcasts, except: [:edit] do
+ member do
+ delete :destroy_file
+ end
resource :zoom_meeting, only: [:show]
end
resources :directories, except: [:index] do
diff --git a/spec/factories/broadcasts.rb b/spec/factories/broadcasts.rb
index 3b022c2..4148242 100644
--- a/spec/factories/broadcasts.rb
+++ b/spec/factories/broadcasts.rb
@@ -17,7 +17,13 @@ FactoryBot.define do
end
trait :with_files do
- files { [Rack::Test::UploadedFile.new('spec/fixtures/files/contract.pdf', 'application/pdf')] }
+ files do
+ [
+ Rack::Test::UploadedFile.new('spec/fixtures/files/contract.pdf', 'application/pdf'),
+ Rack::Test::UploadedFile.new('spec/fixtures/files/audio.mp3', 'audio/mpeg'),
+ Rack::Test::UploadedFile.new('spec/fixtures/files/video_file.mp4', 'video/mp4')
+ ]
+ end
end
after(:build) do |broadcast, evaluator|
diff --git a/spec/features/user_managing_broadcasts_spec.rb b/spec/features/user_managing_broadcasts_spec.rb
index b20cabc..5805ee2 100644
--- a/spec/features/user_managing_broadcasts_spec.rb
+++ b/spec/features/user_managing_broadcasts_spec.rb
@@ -164,6 +164,21 @@ feature 'User managing broadcasts' do
click_on add_file_button
end
+ scenario 'manager user can click delete button next to the file and delete file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 3
+
+ accept_alert do
+ first('a', text: delete_file_button).click
+ end
+
+ expect(page).to have_content delete_file_button, count: 2
+ expect(Broadcast.find(broadcast.id).files.count).to eq 2
+ end
+
scenario 'visit multi-view broadcast page', js: true do
broadcast_one = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 1', project: project)
broadcast_two = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 2', project: project)
@@ -198,6 +213,14 @@ feature 'User managing broadcasts' do
expect(page).to have_content schedule_demo
expect(page).not_to have_content create_stream
end
+
+ scenario 'associate user does not see delete button next to the file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 0
+ end
end
context 'When the user is account manager' do
@@ -209,6 +232,21 @@ feature 'User managing broadcasts' do
expect(page).to have_content schedule_demo
expect(page).to have_content create_stream
end
+
+ scenario 'account manager user can click delete button next to the file and delete file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 3
+
+ accept_alert do
+ first('a', text: delete_file_button).click
+ end
+
+ expect(page).to have_content delete_file_button, count: 2
+ expect(Broadcast.find(broadcast.id).files.count).to eq 2
+ end
end
end
@@ -262,5 +300,9 @@ feature 'User managing broadcasts' do
'Live stream is waiting to begin'
end
+ def delete_file_button
+ t 'broadcasts.file.actions.delete_file'
+ end
+
end