BigW Consortium Gitlab

Commit 2ae9c890 by Douwe Maan

Add experimental JSON format for tree controller

parent 33b622e3
......@@ -24,12 +24,19 @@ class Projects::TreeController < Projects::ApplicationController
end
end
respond_to do |format|
format.html do
@last_commit = @repository.last_commit_for_path(@commit.id, @tree.path) || @commit
end
respond_to do |format|
format.html
format.js do
# Disable cache so browser history works
format.js { no_cache_headers }
no_cache_headers
end
format.json do
render json: TreeSerializer.new(project: @project, repository: @repository, ref: @ref).represent(@tree)
end
end
end
......
......@@ -88,15 +88,15 @@ module DiffHelper
end
def submodule_link(blob, ref, repository = @repository)
tree, commit = submodule_links(blob, ref, repository)
commit_id = if commit.nil?
project_url, tree_url = submodule_links(blob, ref, repository)
commit_id = if tree_url.nil?
Commit.truncate_sha(blob.id)
else
link_to Commit.truncate_sha(blob.id), commit
link_to Commit.truncate_sha(blob.id), tree_url
end
[
content_tag(:span, link_to(truncate(blob.name, length: 40), tree)),
content_tag(:span, link_to(truncate(blob.name, length: 40), project_url)),
'@',
content_tag(:span, commit_id, class: 'commit-sha')
].join(' ').html_safe
......
module IconsHelper
extend self
include FontAwesome::Rails::IconHelper
# Creates an icon tag given icon name(s) and possible icon modifiers.
......
module SubmoduleHelper
include Gitlab::ShellAdapter
extend self
VALID_SUBMODULE_PROTOCOLS = %w[http https git ssh].freeze
......@@ -47,7 +47,7 @@ module SubmoduleHelper
return true if url_no_dotgit == [Gitlab.config.gitlab.url, '/', namespace, '/',
project].join('')
url_with_dotgit = url_no_dotgit + '.git'
url_with_dotgit == gitlab_shell.url_to_repo([namespace, '/', project].join(''))
url_with_dotgit == Gitlab::Shell.new.url_to_repo([namespace, '/', project].join(''))
end
def relative_self_url?(url)
......
class BlobEntity < Grape::Entity
include RequestAwareEntity
expose :id, :path, :name, :mode
expose :icon do |blob|
IconsHelper.file_type_icon_class('file', blob.mode, blob.name)
end
expose :url do |blob|
namespace_project_blob_path(request.project.namespace, request.project, File.join(request.ref, blob.path))
end
end
class SubmoduleEntity < Grape::Entity
include RequestAwareEntity
expose :id, :path, :name, :mode
expose :icon do |blob|
'archive'
end
expose :project_url do |blob|
submodule_links(blob, request).first
end
expose :tree_url do |blob|
submodule_links(blob, request).last
end
private
def submodule_links(blob, request)
@submodule_links ||= SubmoduleHelper.submodule_links(blob, request.ref, request.repository)
end
end
class TreeEntity < Grape::Entity
include RequestAwareEntity
expose :id, :path, :name, :mode
expose :icon do |tree|
IconsHelper.file_type_icon_class('folder', tree.mode, tree.name)
end
expose :url do |tree|
namespace_project_tree_path(request.project.namespace, request.project, File.join(request.ref, tree.path))
end
end
# TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`.
class TreeRootEntity < Grape::Entity
expose :path
expose :trees, using: TreeEntity
expose :blobs, using: BlobEntity
expose :submodules, using: SubmoduleEntity
end
class TreeSerializer < BaseSerializer
entity TreeRootEntity
end
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