diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-13 12:08:39 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:26 -0500 |
commit | 21d2ebff6226e5438443d2eb4430736e9659b820 (patch) | |
tree | 4bbd0720726e0fac27c1e73a081ae1c4428772ed | |
parent | 44cf2470a97221955679e4975897667c21ff1727 (diff) | |
download | gitlab-ce-21d2ebff6226e5438443d2eb4430736e9659b820.tar.gz |
Render blob viewer error
-rw-r--r-- | app/helpers/blob_helper.rb | 9 | ||||
-rw-r--r-- | app/views/projects/blob/_render_error.html.haml | 16 | ||||
-rw-r--r-- | app/views/projects/blob/_too_large.html.haml | 5 |
3 files changed, 25 insertions, 5 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 095032c98e5..8921f0c444a 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -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 diff --git a/app/views/projects/blob/_render_error.html.haml b/app/views/projects/blob/_render_error.html.haml new file mode 100644 index 00000000000..56bcc2b018c --- /dev/null +++ b/app/views/projects/blob/_render_error.html.haml @@ -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. diff --git a/app/views/projects/blob/_too_large.html.haml b/app/views/projects/blob/_too_large.html.haml deleted file mode 100644 index a505f87df40..00000000000 --- a/app/views/projects/blob/_too_large.html.haml +++ /dev/null @@ -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. |