From 54040ce0662c71cfaee3cc12305b5ab021beafbb Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 13 Apr 2017 12:11:52 -0500 Subject: Show Raw button as Download for binary files --- app/helpers/blob_helper.rb | 14 ++++++++++++-- app/views/projects/blob/_header.html.haml | 4 ++-- app/views/shared/snippets/_blob.html.haml | 2 +- features/steps/project/source/browse_files.rb | 2 +- spec/features/projects/blobs/blob_show_spec.rb | 24 ++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 0b80747f001..377b080b3c6 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -217,11 +217,21 @@ module BlobHelper end def copy_blob_source_button(blob) + return unless blob.rendered_as_text?(ignore_errors: false) + clipboard_button(target: ".blob-content[data-blob-id='#{blob.id}']", class: "btn btn-sm js-copy-blob-source-btn", title: "Copy source to clipboard") end - def open_raw_blob_button - link_to icon('file-code-o'), blob_raw_url, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: 'Open raw', data: { container: 'body' } + def open_raw_blob_button(blob) + if blob.raw_binary? + icon = icon('download') + title = 'Download' + else + icon = icon('file-code-o') + title = 'Open raw' + end + + link_to icon, blob_raw_url, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' } end def blob_render_error_reason(viewer) diff --git a/app/views/projects/blob/_header.html.haml b/app/views/projects/blob/_header.html.haml index 638f8cef3bd..219dc14645b 100644 --- a/app/views/projects/blob/_header.html.haml +++ b/app/views/projects/blob/_header.html.haml @@ -15,8 +15,8 @@ = render 'projects/blob/viewer_switcher', blob: blob unless blame .btn-group{ role: "group" }< - = copy_blob_source_button(blob) if !blame && blob.rendered_as_text?(ignore_errors: false) - = open_raw_blob_button + = copy_blob_source_button(blob) unless blame + = open_raw_blob_button(blob) = view_on_environment_button(@commit.sha, @path, @environment) if @environment .btn-group{ role: "group" }< diff --git a/app/views/shared/snippets/_blob.html.haml b/app/views/shared/snippets/_blob.html.haml index 0c481120969..67d186e2874 100644 --- a/app/views/shared/snippets/_blob.html.haml +++ b/app/views/shared/snippets/_blob.html.haml @@ -16,7 +16,7 @@ .btn-group{ role: "group" }< = copy_blob_source_button(blob) - = open_raw_blob_button + = open_raw_blob_button(blob) - if defined?(download_path) && download_path = link_to icon('download'), download_path, class: "btn btn-sm has-tooltip", title: 'Download', data: { container: 'body' } diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index 36fe21a047c..ef09bddddd8 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -367,7 +367,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps step 'I should see buttons for allowed commands' do page.within '.content' do - expect(page).to have_link 'Open raw' + expect(page).to have_link 'Download' expect(page).to have_content 'History' expect(page).to have_content 'Permalink' expect(page).not_to have_content 'Edit' diff --git a/spec/features/projects/blobs/blob_show_spec.rb b/spec/features/projects/blobs/blob_show_spec.rb index 8613b850203..6a6f8b4f4d5 100644 --- a/spec/features/projects/blobs/blob_show_spec.rb +++ b/spec/features/projects/blobs/blob_show_spec.rb @@ -24,6 +24,9 @@ feature 'File blob', :js, feature: true do # shows an enabled copy button expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + + # shows a raw button + expect(page).to have_link('Open raw') end end end @@ -50,6 +53,9 @@ feature 'File blob', :js, feature: true do # shows a disabled copy button expect(page).to have_selector('.js-copy-blob-source-btn.disabled') + + # shows a raw button + expect(page).to have_link('Open raw') end end @@ -160,6 +166,9 @@ feature 'File blob', :js, feature: true do # does not show a copy button expect(page).not_to have_selector('.js-copy-blob-source-btn') + + # shows a raw button + expect(page).to have_link('Open raw') end end @@ -203,6 +212,9 @@ feature 'File blob', :js, feature: true do # shows an enabled copy button expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + + # shows a raw button + expect(page).to have_link('Open raw') end end end @@ -237,6 +249,9 @@ feature 'File blob', :js, feature: true do # does not show a copy button expect(page).not_to have_selector('.js-copy-blob-source-btn') + + # shows a download button + expect(page).to have_link('Download') end end end @@ -262,6 +277,9 @@ feature 'File blob', :js, feature: true do # does not show a copy button expect(page).not_to have_selector('.js-copy-blob-source-btn') + + # shows a download button + expect(page).to have_link('Download') end end end @@ -283,6 +301,9 @@ feature 'File blob', :js, feature: true do # shows an enabled copy button expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + + # shows a raw button + expect(page).to have_link('Open raw') end end end @@ -305,6 +326,9 @@ feature 'File blob', :js, feature: true do # does not show a copy button expect(page).not_to have_selector('.js-copy-blob-source-btn') + + # shows a download button + expect(page).to have_link('Download') end end end -- cgit v1.2.1 From 1686ce039c6823e7974ee5813d00f54e7067aa48 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sun, 30 Apr 2017 14:22:52 -0500 Subject: Add changelog --- changelogs/unreleased/dm-blob-download-button.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased/dm-blob-download-button.yml diff --git a/changelogs/unreleased/dm-blob-download-button.yml b/changelogs/unreleased/dm-blob-download-button.yml new file mode 100644 index 00000000000..bd31137b670 --- /dev/null +++ b/changelogs/unreleased/dm-blob-download-button.yml @@ -0,0 +1,4 @@ +--- +title: Show Raw button as Download for binary files +merge_request: +author: -- cgit v1.2.1