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
Tatuya Kamada
gitlab-ce
Commits
ee2cfded
Commit
ee2cfded
authored
Jul 17, 2016
by
Alfredo Sumaran
Committed by
Phil Hughes
Jul 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor label toggling for Labels dropdown
parent
4ffe142f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
25 deletions
+61
-25
app/assets/javascripts/gl_dropdown.js.coffee
app/assets/javascripts/gl_dropdown.js.coffee
+9
-11
app/assets/javascripts/labels_select.js.coffee
app/assets/javascripts/labels_select.js.coffee
+52
-14
No files found.
app/assets/javascripts/gl_dropdown.js.coffee
View file @
ee2cfded
...
@@ -486,7 +486,7 @@ class GitLabDropdown
...
@@ -486,7 +486,7 @@ class GitLabDropdown
# Toggle the dropdown label
# Toggle the dropdown label
if
@
options
.
toggleLabel
if
@
options
.
toggleLabel
@
updateLabel
(
selectedObject
,
el
,
@
,
false
)
@
updateLabel
(
selectedObject
,
el
,
@
)
else
else
selectedObject
selectedObject
else
if
el
.
hasClass
(
INDETERMINATE_CLASS
)
else
if
el
.
hasClass
(
INDETERMINATE_CLASS
)
...
@@ -513,9 +513,6 @@ class GitLabDropdown
...
@@ -513,9 +513,6 @@ class GitLabDropdown
# Toggle active class for the tick mark
# Toggle active class for the tick mark
el
.
addClass
ACTIVE_CLASS
el
.
addClass
ACTIVE_CLASS
# Toggle the dropdown label
if
@
options
.
toggleLabel
@
updateLabel
(
selectedObject
,
el
,
@
,
true
)
if
value
?
if
value
?
if
!
field
.
length
and
fieldName
if
!
field
.
length
and
fieldName
@
addInput
(
fieldName
,
value
)
@
addInput
(
fieldName
,
value
)
...
@@ -524,6 +521,10 @@ class GitLabDropdown
...
@@ -524,6 +521,10 @@ class GitLabDropdown
.
val
value
.
val
value
.
trigger
'change'
.
trigger
'change'
# Toggle the dropdown label
if
@
options
.
toggleLabel
@
updateLabel
(
selectedObject
,
el
,
@
)
return
selectedObject
return
selectedObject
addInput
:
(
fieldName
,
value
)
->
addInput
:
(
fieldName
,
value
)
->
...
@@ -616,15 +617,12 @@ class GitLabDropdown
...
@@ -616,15 +617,12 @@ class GitLabDropdown
# Scroll the dropdown content up
# Scroll the dropdown content up
$dropdownContent
.
scrollTop
(
listItemTop
-
dropdownContentTop
)
$dropdownContent
.
scrollTop
(
listItemTop
-
dropdownContentTop
)
updateLabel
:
(
selected
=
null
,
el
=
null
,
instance
=
null
,
added
=
false
)
=>
updateLabel
:
(
selected
=
null
,
el
=
null
,
instance
=
null
)
=>
$toggleText
=
$
(
@
el
).
find
(
".dropdown-toggle-text"
)
$toggleText
=
@
getElement
'.dropdown-toggle-text'
$toggleText
.
text
@
options
.
toggleLabel
(
selected
,
el
,
instance
,
added
)
$toggleText
.
text
@
options
.
toggleLabel
(
selected
,
el
,
instance
)
if
@
options
.
defaultLabel
if
@
options
.
defaultLabel
if
$toggleText
.
text
().
trim
()
is
@
options
.
defaultLabel
$toggleText
.
toggleClass
(
'is-default'
,
$toggleText
.
text
().
trim
()
is
@
options
.
defaultLabel
)
$toggleText
.
addClass
(
'is-default'
)
else
$toggleText
.
removeClass
(
'is-default'
)
$
.
fn
.
glDropdown
=
(
opts
)
->
$
.
fn
.
glDropdown
=
(
opts
)
->
return
@
.
each
->
return
@
.
each
->
...
...
app/assets/javascripts/labels_select.js.coffee
View file @
ee2cfded
...
@@ -278,23 +278,61 @@ class @LabelsSelect
...
@@ -278,23 +278,61 @@ class @LabelsSelect
fields
:
[
'title'
]
fields
:
[
'title'
]
selectable
:
true
selectable
:
true
filterable
:
true
filterable
:
true
toggleLabel
:
(
selected
,
el
,
e
,
added
)
->
toggleLabel
:
(
selected
,
$el
,
glDropdownInstance
)
->
if
added
# When comes from a triggered event handle it VERY differently
selectedLabels
.
push
selected
.
title
if
selected
instanceof
jQuery
.
Event
$dropdownParent
=
$dropdown
.
closest
'.labels-filter'
$labelInputs
=
$dropdownParent
.
find
"input[name='
#{
@
fieldName
}
']"
numberSelectedLabels
=
$labelInputs
.
length
firstLabel
=
_
.
pluck
(
$labelInputs
,
'value'
)[
0
]
if
numberSelectedLabels
is
1
firstLabel
else
if
numberSelectedLabels
>
1
"
#{
firstLabel
}
+
#{
numberSelectedLabels
-
1
}
more"
else
defaultLabel
# when clicking on a dropdown option
else
else
index
=
selectedLabels
.
indexOf
selected
.
title
# Return when clicking "No Label"
selectedLabels
.
splice
index
,
1
return
if
selected
.
id
is
0
return
'Any Label'
if
selected
.
isAny
is
true
if
selected
.
id
?
and
selected
.
id
is
0
if
glDropdownInstance
?
selectedLabels
=
[]
$dropdownParent
=
glDropdownInstance
.
dropdown
.
closest
'.issuable-form-select-holder, .labels-filter'
else
$dropdownParent
=
$
()
if
selectedLabels
.
length
>
1
$labelInputs
=
$dropdownParent
.
find
"input[name='
#{
@
fieldName
}
']"
"
#{
selectedLabels
[
0
]
}
+
#{
selectedLabels
.
length
-
1
}
more"
else
if
selectedLabels
.
length
is
1
# Find the label by its attribute according the dropdown settings
selectedLabels
[
0
]
if
$dropdown
.
hasClass
'js-issuable-form-dropdown'
else
# When settings labels to a issuable we find the label for its ID
console
.
log
selectedLabels
.
length
,
defaultLabel
whereQuery
=
{
id
:
parseInt
$labelInputs
.
first
().
val
()
}
defaultLabel
else
# When filtering issuables we find the label for its title
whereQuery
=
{
title
:
$labelInputs
.
first
().
val
()
}
firstLabel
=
_
.
findWhere
glDropdownInstance
.
fullData
,
whereQuery
# Better rely on inputs since filtering may returns invalid number of active labels
numberSelectedLabels
=
$labelInputs
.
length
# If we are adding a label
if
$el
.
is
'.is-active'
if
numberSelectedLabels
is
1
selected
.
title
else
"
#{
selected
.
title
}
+
#{
numberSelectedLabels
-
1
}
more"
# otherwise we are removing a label
else
if
numberSelectedLabels
is
1
firstLabel
.
title
else
if
numberSelectedLabels
>
1
"
#{
firstLabel
.
title
}
+
#{
numberSelectedLabels
-
1
}
more"
else
defaultLabel
defaultLabel
:
defaultLabel
defaultLabel
:
defaultLabel
fieldName
:
$dropdown
.
data
(
'field-name'
)
fieldName
:
$dropdown
.
data
(
'field-name'
)
id
:
(
label
)
->
id
:
(
label
)
->
...
...
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