Commit c69a0779 authored by Douwe Maan's avatar Douwe Maan

Address feedback

parent fed9dcd9
...@@ -224,4 +224,20 @@ module BlobHelper ...@@ -224,4 +224,20 @@ module BlobHelper
"it is stored in LFS" "it is stored in LFS"
end end
end end
def blob_render_error_options(viewer, error)
options = []
if error == :too_large && viewer.can_override_max_size?
options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, override_max_size: true, format: nil)))
end
if viewer.rich? && viewer.blob.rendered_as_text?(override_max_size: true)
options << link_to('view the source', '#', class: 'js-blob-viewer-switcher', data: { viewer: 'simple' })
end
options << link_to('download it', blob_raw_url, target: '_blank', rel: 'noopener noreferrer')
options
end
end end
...@@ -107,11 +107,9 @@ class Blob < SimpleDelegator ...@@ -107,11 +107,9 @@ class Blob < SimpleDelegator
end end
def rich_viewer_class def rich_viewer_class
if invalid_lfs_pointer? || empty? return if invalid_lfs_pointer? || empty?
nil
else rich_viewers_classes.find { |viewer_class| viewer_class.can_render?(self) }
rich_viewers_classes.find { |viewer_class| viewer_class.can_render?(self) }
end
end end
def simple_viewer def simple_viewer
......
...@@ -2,7 +2,7 @@ module BlobViewer ...@@ -2,7 +2,7 @@ module BlobViewer
class Base class Base
class_attribute :partial_name, :type, :extensions, :client_side, :text_based, :switcher_icon, :switcher_title, :max_size, :absolute_max_size class_attribute :partial_name, :type, :extensions, :client_side, :text_based, :switcher_icon, :switcher_title, :max_size, :absolute_max_size
delegate :partial_path, :rich?, :simple?, :client_side?, :text_based?, to: :class delegate :partial_path, :rich?, :simple?, :client_side?, :server_side?, :text_based?, to: :class
attr_reader :blob attr_reader :blob
...@@ -26,7 +26,7 @@ module BlobViewer ...@@ -26,7 +26,7 @@ module BlobViewer
client_side client_side
end end
def server_side? def self.server_side?
!client_side? !client_side?
end end
......
module BlobViewer module BlobViewer
class Download < Base class Download < Base
include Simple include Simple
# We pretend the Download viewer is rendered client-side so that it doesn't # We treat the Download viewer as if it renders the content client-side,
# attempt to load the entire blob contents. # so that it doesn't attempt to load the entire blob contents and is
# rendered synchronously instead of loaded asynchronously.
include ClientSide include ClientSide
self.partial_name = 'download' self.partial_name = 'download'
......
- simple_viewer = blob.simple_viewer - simple_viewer = blob.simple_viewer
- rich_viewer = blob.rich_viewer - rich_viewer = blob.rich_viewer
- active_viewer = rich_viewer && params[:viewer] != 'simple' ? :rich : :simple - rich_viewer_active = rich_viewer && params[:viewer] != 'simple'
= render 'projects/blob/viewer_wrapper', viewer: simple_viewer, hidden: (active_viewer != :simple) = render 'projects/blob/viewer_wrapper', viewer: simple_viewer, hidden: rich_viewer_active
- if rich_viewer - if rich_viewer
= render 'projects/blob/viewer_wrapper', viewer: rich_viewer, hidden: (active_viewer != :rich) = render 'projects/blob/viewer_wrapper', viewer: rich_viewer, hidden: !rich_viewer_active
- reason = blob_render_error_reason(viewer, error)
- options = []
- if error == :too_large && viewer.can_override_max_size?
- options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, override_max_size: true, format: nil)))
- if viewer.rich? && viewer.blob.rendered_as_text?(override_max_size: true)
- options << link_to('view the source', '#', class: 'js-blob-viewer-switcher', data: { viewer: 'simple' })
- options << link_to('download it', blob_raw_url, target: '_blank', rel: 'noopener noreferrer')
.file-content.code .file-content.code
.nothing-here-block .nothing-here-block
The #{viewer.switcher_title} could not be displayed because #{reason}. The #{viewer.switcher_title} could not be displayed because #{blob_render_error_reason(viewer, error)}.
You can You can
= options.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').html_safe = blob_render_error_options(viewer, error).to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').html_safe
instead. instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment