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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
1f5fcb63
Commit
1f5fcb63
authored
May 11, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dropdown implementation
parent
fab9dbb3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
20 deletions
+96
-20
CHANGELOG
CHANGELOG
+2
-0
app/assets/javascripts/blob/blob_gitignore_selector.js.coffee
...assets/javascripts/blob/blob_gitignore_selector.js.coffee
+2
-1
app/assets/javascripts/gl_dropdown.js.coffee
app/assets/javascripts/gl_dropdown.js.coffee
+53
-14
app/assets/stylesheets/pages/editor.scss
app/assets/stylesheets/pages/editor.scss
+1
-1
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+7
-1
app/views/projects/blob/_editor.html.haml
app/views/projects/blob/_editor.html.haml
+1
-3
spec/features/projects/files/gitignore_dropdown_spec.rb
spec/features/projects/files/gitignore_dropdown_spec.rb
+30
-0
No files found.
CHANGELOG
View file @
1f5fcb63
...
@@ -71,6 +71,8 @@ v 8.7.6
...
@@ -71,6 +71,8 @@ v 8.7.6
- Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko)
- Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko)
- Fix import from GitLab.com to a private instance failure. !4181
- Fix import from GitLab.com to a private instance failure. !4181
- Fix external imports not finding the import data. !4106
- Fix external imports not finding the import data. !4106
- Fix import from gitlab.com to a private instance failure
- When creating a .gitignore file a dropdown with templates will be provided
v 8.7.5
v 8.7.5
- Fix relative links in wiki pages. !4050
- Fix relative links in wiki pages. !4050
...
...
app/assets/javascripts/blob/blob_gitignore_selector.js.coffee
View file @
1f5fcb63
...
@@ -29,7 +29,8 @@ class @BlobGitIgnoreSelector
...
@@ -29,7 +29,8 @@ class @BlobGitIgnoreSelector
filename
=
@
fileNameInput
.
val
()
or
$
(
'.editor-file-name'
).
text
().
trim
()
filename
=
@
fileNameInput
.
val
()
or
$
(
'.editor-file-name'
).
text
().
trim
()
@
wrapper
.
toggleClass
'hidden'
,
filename
isnt
'.gitignore'
@
wrapper
.
toggleClass
'hidden'
,
filename
isnt
'.gitignore'
onClick
:
(
item
)
->
onClick
:
(
item
,
el
,
e
)
->
e
.
preventDefault
()
@
requestIgnoreFile
(
item
.
text
)
@
requestIgnoreFile
(
item
.
text
)
requestIgnoreFile
:
(
name
)
->
requestIgnoreFile
:
(
name
)
->
...
...
app/assets/javascripts/gl_dropdown.js.coffee
View file @
1f5fcb63
...
@@ -60,9 +60,23 @@ class GitLabDropdownFilter
...
@@ -60,9 +60,23 @@ class GitLabDropdownFilter
results
=
data
results
=
data
if
search_text
isnt
''
if
search_text
isnt
''
results
=
fuzzaldrinPlus
.
filter
(
data
,
search_text
,
# handle groups
key
:
@
options
.
keys
if
_
.
isArray
(
data
)
)
results
=
fuzzaldrinPlus
.
filter
(
data
,
search_text
,
key
:
@
options
.
keys
)
else
if
_
.
isObject
(
data
)
results
=
{}
for
key
,
group
of
data
tmp
=
fuzzaldrinPlus
.
filter
(
group
,
search_text
,
key
:
@
options
.
keys
)
if
tmp
.
length
results
[
key
]
=
[]
tmp
.
map
(
item
)
->
results
[
key
].
push
item
@
options
.
callback
results
@
options
.
callback
results
else
else
...
@@ -141,8 +155,9 @@ class GitLabDropdown
...
@@ -141,8 +155,9 @@ class GitLabDropdown
searchFields
=
if
@
options
.
search
then
@
options
.
search
.
fields
else
[];
searchFields
=
if
@
options
.
search
then
@
options
.
search
.
fields
else
[];
if
@
options
.
data
if
@
options
.
data
# If data is an array
# If we provided data
if
_
.
isArray
@
options
.
data
# data could be an array of objects or a group of arrays
if
_
.
isObject
(
@
options
.
data
)
and
not
_
.
isFunction
(
@
options
.
data
)
@
fullData
=
@
options
.
data
@
fullData
=
@
options
.
data
@
parseData
@
options
.
data
@
parseData
@
options
.
data
else
else
...
@@ -230,19 +245,33 @@ class GitLabDropdown
...
@@ -230,19 +245,33 @@ class GitLabDropdown
parseData
:
(
data
)
->
parseData
:
(
data
)
->
@
renderedData
=
data
@
renderedData
=
data
# Render each row
html
=
$
.
map
data
,
(
obj
)
=>
return
@
renderItem
(
obj
)
if
@
options
.
filterable
and
data
.
length
is
0
if
@
options
.
filterable
and
data
.
length
is
0
# render no matching results
# render no matching results
html
=
[
@
noResults
()]
html
=
[
@
noResults
()]
else
# Handle array groups
if
String
(
data
)
is
"[object Object]"
html
=
[]
for
name
,
groupData
of
data
# Add header for each group
html
.
push
(
@
renderItem
(
header
:
name
,
name
))
@
renderData
(
groupData
,
name
)
.
map
(
item
)
->
html
.
push
item
else
# Render each row
html
=
@
renderData
(
data
)
# Render the full menu
# Render the full menu
full_html
=
@
renderMenu
(
html
.
join
(
""
))
full_html
=
@
renderMenu
(
html
.
join
(
""
))
@
appendMenu
(
full_html
)
@
appendMenu
(
full_html
)
renderData
:
(
data
,
group
=
false
)
->
$
.
map
data
,
(
obj
,
index
)
=>
return
@
renderItem
(
obj
,
group
,
index
)
shouldPropagate
:
(
e
)
=>
shouldPropagate
:
(
e
)
=>
if
@
options
.
multiSelect
if
@
options
.
multiSelect
$target
=
$
(
e
.
target
)
$target
=
$
(
e
.
target
)
...
@@ -299,11 +328,10 @@ class GitLabDropdown
...
@@ -299,11 +328,10 @@ class GitLabDropdown
selector
=
'.dropdown-content'
selector
=
'.dropdown-content'
if
@
dropdown
.
find
(
".dropdown-toggle-page"
).
length
if
@
dropdown
.
find
(
".dropdown-toggle-page"
).
length
selector
=
".dropdown-page-one .dropdown-content"
selector
=
".dropdown-page-one .dropdown-content"
$
(
selector
,
@
dropdown
).
html
html
$
(
selector
,
@
dropdown
).
html
html
# Render the row
# Render the row
renderItem
:
(
data
)
->
renderItem
:
(
data
,
group
=
false
,
index
=
false
)
->
html
=
""
html
=
""
# Divider
# Divider
...
@@ -346,8 +374,13 @@ class GitLabDropdown
...
@@ -346,8 +374,13 @@ class GitLabDropdown
if
@
highlight
if
@
highlight
text
=
@
highlightTextMatches
(
text
,
@
filterInput
.
val
())
text
=
@
highlightTextMatches
(
text
,
@
filterInput
.
val
())
if
group
groupAttrs
=
"data-group='
#{
group
}
' data-index='
#{
index
}
'"
else
groupAttrs
=
''
html
=
"<li>
html
=
"<li>
<a href='
#{
url
}
' class='
#{
cssClass
}
'>
<a href='
#{
url
}
'
#{
groupAttrs
}
class='
#{
cssClass
}
'>
#{
text
}
#{
text
}
</a>
</a>
</li>"
</li>"
...
@@ -377,9 +410,15 @@ class GitLabDropdown
...
@@ -377,9 +410,15 @@ class GitLabDropdown
rowClicked
:
(
el
)
->
rowClicked
:
(
el
)
->
fieldName
=
@
options
.
fieldName
fieldName
=
@
options
.
fieldName
selectedIndex
=
el
.
parent
().
index
()
if
@
renderedData
if
@
renderedData
selectedObject
=
@
renderedData
[
selectedIndex
]
groupName
=
el
.
data
(
'group'
)
if
groupName
selectedIndex
=
el
.
data
(
'index'
)
selectedObject
=
@
renderedData
[
groupName
][
selectedIndex
]
else
selectedIndex
=
el
.
parent
().
index
()
selectedObject
=
@
renderedData
[
selectedIndex
]
value
=
if
@
options
.
id
then
@
options
.
id
(
selectedObject
,
el
)
else
selectedObject
.
id
value
=
if
@
options
.
id
then
@
options
.
id
(
selectedObject
,
el
)
else
selectedObject
.
id
field
=
@
dropdown
.
parent
().
find
(
"input[name='
#{
fieldName
}
'][value='
#{
value
}
']"
)
field
=
@
dropdown
.
parent
().
find
(
"input[name='
#{
fieldName
}
'][value='
#{
value
}
']"
)
if
el
.
hasClass
(
ACTIVE_CLASS
)
if
el
.
hasClass
(
ACTIVE_CLASS
)
...
...
app/assets/stylesheets/pages/editor.scss
View file @
1f5fcb63
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
line-height
:
21px
;
line-height
:
21px
;
}
}
.dropdown-menu-toggle
{
.dropdown-menu-toggle
{
vertical-align
:
top
;
vertical-align
:
top
;
width
:
220px
;
width
:
220px
;
}
}
...
...
app/helpers/blob_helper.rb
View file @
1f5fcb63
...
@@ -186,6 +186,12 @@ module BlobHelper
...
@@ -186,6 +186,12 @@ module BlobHelper
end
end
def
gitignores_for_select
def
gitignores_for_select
@gitignores_for_select
||=
Gitlab
::
Gitignore
.
all
return
@gitignores_for_select
if
defined?
(
@gitignores_for_select
)
@gitignores_for_select
=
{
Global
:
Gitlab
::
Gitignore
.
global
.
map
{
|
v
|
{
text:
v
.
name
}
},
# Note that the key here doesn't cover it really
Languages
:
Gitlab
::
Gitignore
.
languages_frameworks
.
map
{
|
v
|
{
text:
v
.
name
}
}
}
end
end
end
end
app/views/projects/blob/_editor.html.haml
View file @
1f5fcb63
...
@@ -17,9 +17,7 @@
...
@@ -17,9 +17,7 @@
=
select_tag
:license_type
,
grouped_options_for_select
(
licenses_for_select
,
@project
.
repository
.
license_key
),
include_blank:
true
,
class:
'select2 license-select'
,
data:
{
placeholder:
'Choose a license template'
,
project:
@project
.
name
,
fullname:
@project
.
namespace
.
human_name
}
=
select_tag
:license_type
,
grouped_options_for_select
(
licenses_for_select
,
@project
.
repository
.
license_key
),
include_blank:
true
,
class:
'select2 license-select'
,
data:
{
placeholder:
'Choose a license template'
,
project:
@project
.
name
,
fullname:
@project
.
namespace
.
human_name
}
.gitignore-selector.hidden
.gitignore-selector.hidden
=
dropdown_tag
(
"Choose a .gitignore template"
,
options:
{
toggle_class:
'js-gitignore-selector'
,
title:
"Choose a template"
,
filter:
true
,
placeholder:
"Filter projects"
,
data:
{
filenames:
Gitlab
::
Gitignore
.
all
.
map
.
with_index
{
|
v
|
{
text:
v
.
name
}
}
}
}
)
=
dropdown_tag
(
"Choose a .gitignore template"
,
options:
{
toggle_class:
'js-gitignore-selector'
,
title:
"Choose a template"
,
filter:
true
,
placeholder:
"Filter"
,
data:
{
filenames:
gitignores_for_select
}
}
)
-# = select_tag :gitignore_template, options_for_select(Gitlab::Gitignore.all.map(&:name)), include_blank: true, class: 'select2 gitignore-select', data: {placeholder: 'Choose a .gitignore template'}
.encoding-selector
.encoding-selector
=
select_tag
:encoding
,
options_for_select
([
"base64"
,
"text"
],
"text"
),
class:
'select2'
=
select_tag
:encoding
,
options_for_select
([
"base64"
,
"text"
],
"text"
),
class:
'select2'
...
...
spec/features/projects/files/gitignore_dropdown_spec.rb
0 → 100644
View file @
1f5fcb63
require
'spec_helper'
feature
'User wants to add a .gitignore file'
,
feature:
true
do
include
WaitForAjax
before
do
user
=
create
(
:user
)
project
=
create
(
:project
)
project
.
team
<<
[
user
,
:master
]
login_as
user
visit
namespace_project_new_blob_path
(
project
.
namespace
,
project
,
'master'
,
file_name:
'.gitignore'
)
end
scenario
'user can see .gitignore dropdown'
do
expect
(
page
).
to
have_css
(
'.gitignore-selector'
)
end
scenario
'user can pick a .gitignore file from the dropdown'
,
js:
true
do
find
(
'.js-gitignore-selector'
).
click
wait_for_ajax
within
'.gitignore-selector'
do
find
(
'.dropdown-input-field'
).
set
(
'rails'
)
find
(
'.dropdown-content li'
,
text:
'Rails'
).
click
end
wait_for_ajax
expect
(
page
).
to
have_content
(
'/.bundle'
)
expect
(
page
).
to
have_content
(
'# Gemfile.lock, .ruby-version, .ruby-gemset'
)
end
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