Render blob viewer error

This commit is contained in:
Douwe Maan 2017-04-13 12:08:39 -05:00
parent 44cf2470a9
commit 21d2ebff62
3 changed files with 25 additions and 5 deletions

View file

@ -217,4 +217,13 @@ module BlobHelper
def open_raw_file_button(path)
link_to icon('file-code-o'), path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: 'Open raw', data: { container: 'body' }
end
def blob_render_error_reason(viewer, error)
case error
when :too_large
"it is larger than #{number_to_human_size(viewer.relevant_max_size)}"
when :server_side_but_stored_in_lfs
"it is stored in LFS"
end
end
end

View file

@ -0,0 +1,16 @@
- 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
.nothing-here-block
The #{viewer.switcher_title} could not be displayed because #{reason}.
You can
= options.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').html_safe
instead.

View file

@ -1,5 +0,0 @@
.file-content.code
.nothing-here-block
The file could not be displayed as it is too large, you can
#{link_to('view the raw file', namespace_project_raw_path(@project.namespace, @project, @id), target: '_blank', rel: 'noopener noreferrer')}
instead.