Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
d9b15661
Commit
d9b15661
authored
May 26, 2017
by
Douwe Maan
Committed by
Jacob Schatz
Jun 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add experimental JSON format for tree controller
parent
0037cf63
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
11 deletions
+79
-11
app/controllers/projects/tree_controller.rb
app/controllers/projects/tree_controller.rb
+12
-5
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+4
-4
app/helpers/icons_helper.rb
app/helpers/icons_helper.rb
+1
-0
app/helpers/submodule_helper.rb
app/helpers/submodule_helper.rb
+2
-2
app/serializers/blob_entity.rb
app/serializers/blob_entity.rb
+13
-0
app/serializers/submodule_entity.rb
app/serializers/submodule_entity.rb
+23
-0
app/serializers/tree_entity.rb
app/serializers/tree_entity.rb
+13
-0
app/serializers/tree_root_entity.rb
app/serializers/tree_root_entity.rb
+8
-0
app/serializers/tree_serializer.rb
app/serializers/tree_serializer.rb
+3
-0
No files found.
app/controllers/projects/tree_controller.rb
View file @
d9b15661
...
...
@@ -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
...
...
app/helpers/diff_helper.rb
View file @
d9b15661
...
...
@@ -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
...
...
app/helpers/icons_helper.rb
View file @
d9b15661
module
IconsHelper
extend
self
include
FontAwesome
::
Rails
::
IconHelper
# Creates an icon tag given icon name(s) and possible icon modifiers.
...
...
app/helpers/submodule_helper.rb
View file @
d9b15661
module
SubmoduleHelper
include
Gitlab
::
ShellAdapter
extend
self
VALID_SUBMODULE_PROTOCOLS
=
%w[http https git ssh]
.
freeze
...
...
@@ -59,7 +59,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
)
...
...
app/serializers/blob_entity.rb
0 → 100644
View file @
d9b15661
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
app/serializers/submodule_entity.rb
0 → 100644
View file @
d9b15661
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
app/serializers/tree_entity.rb
0 → 100644
View file @
d9b15661
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
app/serializers/tree_root_entity.rb
0 → 100644
View file @
d9b15661
# 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
app/serializers/tree_serializer.rb
0 → 100644
View file @
d9b15661
class
TreeSerializer
<
BaseSerializer
entity
TreeRootEntity
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment