summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/concerns/renders_blob.rb34
-rw-r--r--app/controllers/projects/blob_controller.rb26
-rw-r--r--app/helpers/blob_helper.rb6
-rw-r--r--app/models/blob_viewer/base.rb2
-rw-r--r--app/models/blob_viewer/server_side.rb2
-rw-r--r--app/views/projects/_files.html.haml3
-rw-r--r--app/views/projects/blob/_blob.html.haml2
-rw-r--r--app/views/projects/blob/show.html.haml20
-rw-r--r--app/views/projects/blob/viewers/_balsamiq.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_download.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_image.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_notebook.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_pdf.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_sketch.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_stl.html.haml2
-rw-r--r--app/views/projects/blob/viewers/_video.html.haml2
-rw-r--r--app/views/projects/tree/_tree_content.html.haml3
-rw-r--r--app/views/projects/tree/_tree_header.html.haml2
-rw-r--r--app/views/projects/tree/show.html.haml2
-rw-r--r--app/views/shared/repo/_repo.html.haml2
-rw-r--r--yarn.lock2
21 files changed, 68 insertions, 54 deletions
diff --git a/app/controllers/concerns/renders_blob.rb b/app/controllers/concerns/renders_blob.rb
index 5a1b1d9f929..ba7adcfea86 100644
--- a/app/controllers/concerns/renders_blob.rb
+++ b/app/controllers/concerns/renders_blob.rb
@@ -1,7 +1,7 @@
module RendersBlob
extend ActiveSupport::Concern
- def render_blob_json(blob)
+ def blob_json(blob)
viewer =
case params[:viewer]
when 'rich'
@@ -11,27 +11,19 @@ module RendersBlob
else
blob.simple_viewer
end
-
- return render_404 unless viewer
- if blob.binary?
- render json: {
- binary: true,
- mime_type: blob.mime_type,
- name: blob.name,
- extension: blob.extension,
- size: blob.raw_size
- }
- else
- render json: {
- html: view_to_html_string("projects/blob/_viewer", viewer: viewer, load_async: false),
- plain: blob.data,
- name: blob.name,
- extension: blob.extension,
- size: blob.raw_size,
- mime_type: blob.mime_type
- }
- end
+ return unless viewer
+
+ {
+ html: view_to_html_string("projects/blob/_viewer", viewer: viewer, load_async: false)
+ }
+ end
+
+ def render_blob_json(blob)
+ json = blob_json(blob)
+ return render_404 unless json
+
+ render json: json
end
def conditionally_expand_blob(blob)
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index 721e174d587..7a8fad436ac 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -4,7 +4,6 @@ class Projects::BlobController < Projects::ApplicationController
include CreatesCommit
include RendersBlob
include ActionView::Helpers::SanitizeHelper
- include ApplicationHelper
# Raised when given an invalid file path
InvalidPathError = Class.new(StandardError)
@@ -38,17 +37,32 @@ class Projects::BlobController < Projects::ApplicationController
respond_to do |format|
format.html do
- assign_ref_vars
-
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
@environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last
- @last_commit = @repository.last_commit_for_path(@commit.id, tree.path) || @commit
+ @last_commit = @repository.last_commit_for_path(@commit.id, @blob.path)
- show_new_repo? ? render('projects/tree/show') : render('show')
+ render 'show'
end
format.json do
- render_blob_json(@blob)
+ json = blob_json(@blob)
+ return render_404 unless json
+
+ render json: json.merge(
+ path: blob.path,
+ name: blob.name,
+ extension: blob.extension,
+ size: blob.raw_size,
+ mime_type: blob.mime_type,
+ binary: blob.raw_binary?,
+ simple_viewer: blob.simple_viewer&.class&.partial_name,
+ rich_viewer: blob.rich_viewer&.class&.partial_name,
+ show_viewer_switcher: !!blob.show_viewer_switcher?,
+ raw_path: project_raw_path(project, @id),
+ blame_path: project_blame_path(project, @id),
+ commits_path: project_commits_path(project, @id),
+ permalink: project_blob_path(project, File.join(@commit.id, @path)),
+ )
end
end
end
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index e964d7a5e16..18075ee8be7 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -118,7 +118,7 @@ module BlobHelper
icon("#{file_type_icon_class('file', mode, name)} fw")
end
- def blob_raw_url
+ def blob_raw_path
if @build && @entry
raw_project_job_artifacts_path(@project, @build, path: @entry.path)
elsif @snippet
@@ -235,7 +235,7 @@ module BlobHelper
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' }
+ link_to icon, blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
end
def blob_render_error_reason(viewer)
@@ -270,7 +270,7 @@ module BlobHelper
options << link_to('view the source', '#', class: 'js-blob-viewer-switch-btn', data: { viewer: 'simple' })
end
- options << link_to('download it', blob_raw_url, target: '_blank', rel: 'noopener noreferrer')
+ options << link_to('download it', blob_raw_path, target: '_blank', rel: 'noopener noreferrer')
options
end
diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb
index 35965d01692..bf3453b3063 100644
--- a/app/models/blob_viewer/base.rb
+++ b/app/models/blob_viewer/base.rb
@@ -82,7 +82,7 @@ module BlobViewer
# format of the blob.
#
# Prefer to implement a client-side viewer, where the JS component loads the
- # binary from `blob_raw_url` and does its own format validation and error
+ # binary from `blob_raw_path` and does its own format validation and error
# rendering, especially for potentially large binary formats.
def render_error
if too_large?
diff --git a/app/models/blob_viewer/server_side.rb b/app/models/blob_viewer/server_side.rb
index fbc1b520c01..86afcc86aa0 100644
--- a/app/models/blob_viewer/server_side.rb
+++ b/app/models/blob_viewer/server_side.rb
@@ -17,7 +17,7 @@ module BlobViewer
# build artifacts, can only be rendered using a client-side viewer,
# since we do not want to read large amounts of data into memory on the
# server side. Client-side viewers use JS and can fetch the file from
- # `blob_raw_url` using AJAX.
+ # `blob_raw_path` using AJAX.
return :server_side_but_stored_externally if blob.stored_externally?
super
diff --git a/app/views/projects/_files.html.haml b/app/views/projects/_files.html.haml
index 2f73216ac68..3a7a99462a6 100644
--- a/app/views/projects/_files.html.haml
+++ b/app/views/projects/_files.html.haml
@@ -1,6 +1,7 @@
- commit = local_assigns.fetch(:commit) { @repository.commit }
- ref = local_assigns.fetch(:ref) { current_ref }
- project = local_assigns.fetch(:project) { @project }
+- content_url = local_assigns.fetch(:content_url) { @tree.readme ? project_blob_path(@project, tree_join(@ref, @tree.readme.path)) : project_tree_path(@project, @ref) }
#tree-holder.tree-holder.clearfix
.nav-block
@@ -9,4 +10,4 @@
- if !show_new_repo? && commit
= render 'shared/commit_well', commit: commit, ref: ref, project: project
- = render 'projects/tree/tree_content', tree: @tree
+ = render 'projects/tree/tree_content', tree: @tree, content_url: content_url
diff --git a/app/views/projects/blob/_blob.html.haml b/app/views/projects/blob/_blob.html.haml
index facadddcd9e..11929e9e3b9 100644
--- a/app/views/projects/blob/_blob.html.haml
+++ b/app/views/projects/blob/_blob.html.haml
@@ -8,7 +8,7 @@
= render "projects/blob/auxiliary_viewer", blob: blob
#blob-content-holder.blob-content-holder
- - if !show_new_repo?
+ - unless show_new_repo?
%article.file-holder
= render 'projects/blob/header', blob: blob
= render 'projects/blob/content', blob: blob
diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml
index ae3fbc93633..240e62d5ac5 100644
--- a/app/views/projects/blob/show.html.haml
+++ b/app/views/projects/blob/show.html.haml
@@ -6,16 +6,22 @@
- content_for :page_specific_javascripts do
= webpack_bundle_tag 'blob'
- = webpack_bundle_tag 'common_vue'
+
+ - if show_new_repo?
+ = webpack_bundle_tag 'common_vue'
+ = webpack_bundle_tag 'repo'
= render 'projects/last_push'
%div{ class: container_class }
- #tree-holder.tree-holder
- = render 'blob', blob: @blob
+ - if show_new_repo?
+ = render 'projects/files', commit: @last_commit, project: @project, ref: @ref, content_url: project_blob_path(@project, @id)
+ - else
+ #tree-holder.tree-holder
+ = render 'blob', blob: @blob
- - if can_modify_blob?(@blob)
- = render 'projects/blob/remove'
+ - if can_modify_blob?(@blob)
+ = render 'projects/blob/remove'
- - title = "Replace #{@blob.name}"
- = render 'projects/blob/upload', title: title, placeholder: title, button_title: 'Replace file', form_path: project_update_blob_path(@project, @id), method: :put
+ - title = "Replace #{@blob.name}"
+ = render 'projects/blob/upload', title: title, placeholder: title, button_title: 'Replace file', form_path: project_update_blob_path(@project, @id), method: :put
diff --git a/app/views/projects/blob/viewers/_balsamiq.html.haml b/app/views/projects/blob/viewers/_balsamiq.html.haml
index 28670e7de97..1e7c461f02e 100644
--- a/app/views/projects/blob/viewers/_balsamiq.html.haml
+++ b/app/views/projects/blob/viewers/_balsamiq.html.haml
@@ -1,4 +1,4 @@
- content_for :page_specific_javascripts do
= page_specific_javascript_bundle_tag('balsamiq_viewer')
-.file-content.balsamiq-viewer#js-balsamiq-viewer{ data: { endpoint: blob_raw_url } }
+.file-content.balsamiq-viewer#js-balsamiq-viewer{ data: { endpoint: blob_raw_path } }
diff --git a/app/views/projects/blob/viewers/_download.html.haml b/app/views/projects/blob/viewers/_download.html.haml
index 684240d02c7..6d1138f7959 100644
--- a/app/views/projects/blob/viewers/_download.html.haml
+++ b/app/views/projects/blob/viewers/_download.html.haml
@@ -1,6 +1,6 @@
.file-content.blob_file.blob-no-preview
.center
- = link_to blob_raw_url do
+ = link_to blob_raw_path do
%h1.light
= icon('download')
%h4
diff --git a/app/views/projects/blob/viewers/_image.html.haml b/app/views/projects/blob/viewers/_image.html.haml
index 5fd22a59217..26ea028c5d7 100644
--- a/app/views/projects/blob/viewers/_image.html.haml
+++ b/app/views/projects/blob/viewers/_image.html.haml
@@ -1,2 +1,2 @@
.file-content.image_file
- = image_tag(blob_raw_url, alt: viewer.blob.name)
+ = image_tag(blob_raw_path, alt: viewer.blob.name)
diff --git a/app/views/projects/blob/viewers/_notebook.html.haml b/app/views/projects/blob/viewers/_notebook.html.haml
index 2399fb16265..8a41bc53004 100644
--- a/app/views/projects/blob/viewers/_notebook.html.haml
+++ b/app/views/projects/blob/viewers/_notebook.html.haml
@@ -2,4 +2,4 @@
= page_specific_javascript_bundle_tag('common_vue')
= page_specific_javascript_bundle_tag('notebook_viewer')
-.file-content#js-notebook-viewer{ data: { endpoint: blob_raw_url } }
+.file-content#js-notebook-viewer{ data: { endpoint: blob_raw_path } }
diff --git a/app/views/projects/blob/viewers/_pdf.html.haml b/app/views/projects/blob/viewers/_pdf.html.haml
index 1dd179c4fdc..ec2b18bd4ab 100644
--- a/app/views/projects/blob/viewers/_pdf.html.haml
+++ b/app/views/projects/blob/viewers/_pdf.html.haml
@@ -2,4 +2,4 @@
= page_specific_javascript_bundle_tag('common_vue')
= page_specific_javascript_bundle_tag('pdf_viewer')
-.file-content#js-pdf-viewer{ data: { endpoint: blob_raw_url } }
+.file-content#js-pdf-viewer{ data: { endpoint: blob_raw_path } }
diff --git a/app/views/projects/blob/viewers/_sketch.html.haml b/app/views/projects/blob/viewers/_sketch.html.haml
index 49f716c2c59..775e4584f77 100644
--- a/app/views/projects/blob/viewers/_sketch.html.haml
+++ b/app/views/projects/blob/viewers/_sketch.html.haml
@@ -2,6 +2,6 @@
= page_specific_javascript_bundle_tag('common_vue')
= page_specific_javascript_bundle_tag('sketch_viewer')
-.file-content#js-sketch-viewer{ data: { endpoint: blob_raw_url } }
+.file-content#js-sketch-viewer{ data: { endpoint: blob_raw_path } }
.js-loading-icon.text-center.prepend-top-default.append-bottom-default.js-loading-icon{ 'aria-label' => 'Loading Sketch preview' }
= icon('spinner spin 2x', 'aria-hidden' => 'true');
diff --git a/app/views/projects/blob/viewers/_stl.html.haml b/app/views/projects/blob/viewers/_stl.html.haml
index e4e9d746176..6578d826ace 100644
--- a/app/views/projects/blob/viewers/_stl.html.haml
+++ b/app/views/projects/blob/viewers/_stl.html.haml
@@ -2,7 +2,7 @@
= page_specific_javascript_bundle_tag('stl_viewer')
.file-content.is-stl-loading
- .text-center#js-stl-viewer{ data: { endpoint: blob_raw_url } }
+ .text-center#js-stl-viewer{ data: { endpoint: blob_raw_path } }
= icon('spinner spin 2x', class: 'prepend-top-default append-bottom-default', 'aria-hidden' => 'true', 'aria-label' => 'Loading')
.text-center.prepend-top-default.append-bottom-default.stl-controls
.btn-group
diff --git a/app/views/projects/blob/viewers/_video.html.haml b/app/views/projects/blob/viewers/_video.html.haml
index 595a890a27d..36039c08d52 100644
--- a/app/views/projects/blob/viewers/_video.html.haml
+++ b/app/views/projects/blob/viewers/_video.html.haml
@@ -1,2 +1,2 @@
.file-content.video
- %video{ src: blob_raw_url, controls: true, data: { setup: '{}' } }
+ %video{ src: blob_raw_path, controls: true, data: { setup: '{}' } }
diff --git a/app/views/projects/tree/_tree_content.html.haml b/app/views/projects/tree/_tree_content.html.haml
index 0ad4ab14139..a4bdd67209d 100644
--- a/app/views/projects/tree/_tree_content.html.haml
+++ b/app/views/projects/tree/_tree_content.html.haml
@@ -1,4 +1,5 @@
+- content_url = local_assigns.fetch(:content_url, nil)
- if show_new_repo?
- = render 'shared/repo/repo', project: @project
+ = render 'shared/repo/repo', project: @project, content_url: content_url
- else
= render 'projects/tree/old_tree_content', tree: tree
diff --git a/app/views/projects/tree/_tree_header.html.haml b/app/views/projects/tree/_tree_header.html.haml
index 5c317721651..427b059cb82 100644
--- a/app/views/projects/tree/_tree_header.html.haml
+++ b/app/views/projects/tree/_tree_header.html.haml
@@ -5,7 +5,7 @@
= icon('long-arrow-right', title: 'to target branch')
= render 'shared/target_switcher', destination: 'tree', path: @path
- - if !show_new_repo?
+ - unless show_new_repo?
= render 'projects/tree/old_tree_header'
.tree-controls
diff --git a/app/views/projects/tree/show.html.haml b/app/views/projects/tree/show.html.haml
index c5a73e4c53e..375e6764add 100644
--- a/app/views/projects/tree/show.html.haml
+++ b/app/views/projects/tree/show.html.haml
@@ -15,4 +15,4 @@
%div{ class: [container_class, ("limit-container-width" unless fluid_layout)] }
= render 'projects/last_push'
- = render 'projects/files', commit: @last_commit, project: @project, ref: @ref
+ = render 'projects/files', commit: @last_commit, project: @project, ref: @ref, content_url: project_tree_path(@project, @id)
diff --git a/app/views/shared/repo/_repo.html.haml b/app/views/shared/repo/_repo.html.haml
index 919904a81a7..f85fa57db09 100644
--- a/app/views/shared/repo/_repo.html.haml
+++ b/app/views/shared/repo/_repo.html.haml
@@ -1 +1 @@
-#repo{ data: { url: repo_url(project), project_name: project.name, refs_url: refs_project_path(project, format: :json), project_url: project_path(project), project_id: project.id } }
+#repo{ data: { url: content_url, project_name: project.name, refs_url: refs_project_path(project, format: :json), project_url: project_path(project), project_id: project.id } }
diff --git a/yarn.lock b/yarn.lock
index 7af7f6d8554..d624873a97a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2616,7 +2616,7 @@ got@^7.0.0:
url-parse-lax "^1.0.0"
url-to-options "^1.0.1"
-graceful-fs@^4.1.11, graceful-fs@^4.1.2:
+graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"