Skip to content

enhancement: preview file attachment without download #3681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f688aa0
add open attachment without download
Nevelito Feb 21, 2025
227ba54
fix standardrb spec
Nevelito Feb 21, 2025
04add95
fix specs
Nevelito Feb 21, 2025
3a5238d
fix standardrb spec fails
Nevelito Feb 21, 2025
ff44672
delete changes in yarn lock
Nevelito Feb 21, 2025
88fc94c
request changes
Nevelito Mar 6, 2025
a759251
Merge branch 'main' into open_field_attachments
Paul-Bob Mar 13, 2025
ecc62c3
request changes
Nevelito Mar 13, 2025
7597bbe
fix bug
Nevelito Mar 13, 2025
b99dbde
fix spec
Nevelito Mar 13, 2025
c22904d
fix spec
Nevelito Mar 13, 2025
e5f1ab6
fix spec
Nevelito Mar 13, 2025
898f26b
tweak
Paul-Bob Mar 14, 2025
f77cfe3
Merge branch 'main' into open_field_attachments
Paul-Bob Mar 31, 2025
a94cc41
Merge branch 'main' into open_field_attachments
Paul-Bob Apr 16, 2025
6a5e72b
fix spec bugs
Nevelito Apr 28, 2025
02accc0
fix standardb fails
Nevelito Apr 28, 2025
4360823
fix error in rails 7.1 and 8.0
Nevelito Apr 28, 2025
96ce7c0
fix spec error
Nevelito Apr 28, 2025
99438d1
Merge branch 'main' into open_field_attachments
Nevelito Apr 28, 2025
e851739
different test approach
Paul-Bob Apr 29, 2025
1dea0ea
Merge branch 'main' into open_field_attachments
Paul-Bob Apr 29, 2025
8047b66
wip
Paul-Bob Apr 29, 2025
03cb3fe
Merge branch 'open_field_attachments' of github.com:Nevelito/avo into…
Paul-Bob Apr 29, 2025
ec842db
debug
Paul-Bob Apr 29, 2025
310072c
debug
Paul-Bob Apr 29, 2025
77908ed
mock representable?
Paul-Bob Apr 29, 2025
2d4ef14
debug
Paul-Bob Apr 29, 2025
70df76c
mock
Paul-Bob Apr 29, 2025
ae2a32b
debug
Paul-Bob Apr 29, 2025
c0d540d
mock order
Paul-Bob Apr 29, 2025
2259d63
rm debugger
Paul-Bob Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
<% elsif is_video? %>
<%= video_tag(helpers.main_app.url_for(file), controls: true, preload: false, class: 'w-full') %>
<% else %>
<div class="relative flex flex-col justify-evenly items-center px-2 rounded-lg border bg-white border-gray-500 min-h-24">
<a
<% if can_download_file? %>href="<%= helpers.main_app.url_for(file) %>" target="_blank" rel="noopener noreferrer"<% end %>
class="relative flex flex-col justify-evenly items-center px-2 rounded-lg border bg-white border-gray-500 min-h-24 <%= 'hover:bg-gray-100 transition' if can_download_file? %>"
>
<div class="flex flex-col justify-center items-center w-full">
<%= helpers.svg "heroicons/outline/document-text", class: 'h-10 text-gray-600 mb-2' %>
</div>
</div>
</a>
<% end %>
<% if @field.display_filename %>
<span class="text-gray-500 mt-1 text-sm truncate" title="<%= file.filename %>"><%= file.filename %></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Avo::Fields::Common::Files::ViewType::GridItemComponent < Avo::BaseComponent
include Avo::Fields::Concerns::FileAuthorization

prop :field
prop :resource
prop :file
Expand Down
Empty file.
26 changes: 26 additions & 0 deletions spec/system/avo/open_field_attachment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

RSpec.describe "OpenFieldAttachment", type: :system do
let!(:user) { User.first }
let!(:cv_file) { Rails.root.join("app", "assets", "pdfs", "cv_sample.pdf") }
let(:path) { "/admin/resources/field_discovery_users/#{user.slug}" }

before do
user.cv.attach(io: File.open(cv_file), filename: "cv_sample.pdf", content_type: "application/pdf")
end

def test_open_field_attachment(path)
visit path

link = find('a[rel="noopener noreferrer"][target="_blank"]', visible: :all)
expect(link).to be_present
link.click

expect(page.driver.browser.current_url).not_to include("download")
expect(page.driver.browser.window_handles.length).to eq 2
end

it "opens attachment in new window without download" do
test_open_field_attachment(path)
end
end
Loading