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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
87c6402a
Commit
87c6402a
authored
Dec 08, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass blob to webide-buttons for optimizing
In this case we won't need to load the blob every time
parent
6e896a5f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
12 deletions
+31
-12
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+3
-2
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+2
-2
app/helpers/web_ide_button_helper.rb
app/helpers/web_ide_button_helper.rb
+6
-6
app/views/shared/_web_ide_button.html.haml
app/views/shared/_web_ide_button.html.haml
+2
-2
spec/helpers/tree_helper_spec.rb
spec/helpers/tree_helper_spec.rb
+18
-0
No files found.
app/helpers/blob_helper.rb
View file @
87c6402a
...
...
@@ -332,8 +332,9 @@ module BlobHelper
end
def
readable_blob
(
options
,
path
,
project
,
ref
)
blob
=
options
.
delete
(
:blob
)
blob
||=
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
blob
=
options
.
fetch
(
:blob
)
do
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
end
blob
if
blob
&
.
readable_text?
end
...
...
app/helpers/tree_helper.rb
View file @
87c6402a
...
...
@@ -228,12 +228,12 @@ module TreeHelper
gitpod_enabled:
!
current_user
.
nil?
&&
current_user
.
gitpod_enabled
,
is_blob:
!
options
[:
blob
].
nil?
,
show_edit_button:
show_edit_button?
,
show_edit_button:
show_edit_button?
(
options
)
,
show_web_ide_button:
show_web_ide_button?
,
show_gitpod_button:
show_gitpod_button?
,
web_ide_url:
web_ide_url
,
edit_url:
edit_url
,
edit_url:
edit_url
(
options
)
,
gitpod_url:
gitpod_url
}
end
...
...
app/helpers/web_ide_button_helper.rb
View file @
87c6402a
...
...
@@ -21,8 +21,8 @@ module WebIdeButtonHelper
can_collaborate?
||
can_create_mr_from_fork?
end
def
show_edit_button?
readable_blob?
&&
show_web_ide_button?
def
show_edit_button?
(
options
=
{})
readable_blob?
(
options
)
&&
show_web_ide_button?
end
def
show_gitpod_button?
...
...
@@ -37,8 +37,8 @@ module WebIdeButtonHelper
!
project_fork
.
nil?
&&
!
can_push_code?
end
def
readable_blob?
!
readable_blob
(
{}
,
@path
,
@project
,
@ref
).
nil?
def
readable_blob?
(
options
=
{})
!
readable_blob
(
options
,
@path
,
@project
,
@ref
).
nil?
end
def
needs_to_fork?
...
...
@@ -49,8 +49,8 @@ module WebIdeButtonHelper
ide_edit_path
(
project_to_use
,
@ref
,
@path
||
''
)
end
def
edit_url
readable_blob?
?
edit_blob_path
(
@project
,
@ref
,
@path
||
''
)
:
''
def
edit_url
(
options
=
{})
readable_blob?
(
options
)
?
edit_blob_path
(
@project
,
@ref
,
@path
||
''
)
:
''
end
def
gitpod_url
...
...
app/views/shared/_web_ide_button.html.haml
View file @
87c6402a
-
type
=
blob
?
'blob'
:
'tree'
.d-inline-block
{
data:
{
options:
web_ide_button_data
(
blob:
blob
).
to_json
},
id:
"js-#{type}-web-ide-link"
}
.d-inline-block
{
data:
{
options:
web_ide_button_data
(
{
blob:
blob
}
).
to_json
},
id:
"js-#{type}-web-ide-link"
}
-
if
show_edit_button?
-
if
show_edit_button?
({
blob:
blob
})
=
render
'shared/confirm_fork_modal'
,
fork_path:
fork_and_edit_path
(
@project
,
@ref
,
@path
),
type:
'edit'
-
if
show_web_ide_button?
=
render
'shared/confirm_fork_modal'
,
fork_path:
ide_fork_and_edit_path
(
@project
,
@ref
,
@path
),
type:
'webide'
...
...
spec/helpers/tree_helper_spec.rb
View file @
87c6402a
...
...
@@ -216,6 +216,24 @@ RSpec.describe TreeHelper do
web_ide_url:
"/-/ide/project/
#{
project
.
full_path
}
/edit/
#{
sha
}
/-/
#{
@path
}
"
)
end
it
'does not load blob from repository again'
do
blob
expect
(
repository
).
not_to
receive
(
:blob_at
)
subject
end
end
context
'nil blob is passed'
do
let
(
:blob
)
{
nil
}
it
'does not load blob from repository'
do
expect
(
repository
).
not_to
receive
(
:blob_at
)
subject
end
end
context
'user does not have write access but a personal fork exists'
do
...
...
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