Commit 5cefd8ab authored by Arinde Eniola's avatar Arinde Eniola

some refactoring

parent 259970ca
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Issues.initTemplates() Issues.initTemplates()
Issues.initSearch() Issues.initSearch()
Issues.initChecks() Issues.initChecks()
Issues.toggleLabelFilters()
$("body").on "ajax:success", ".close_issue, .reopen_issue", -> $("body").on "ajax:success", ".close_issue, .reopen_issue", ->
t = $(this) t = $(this)
...@@ -20,11 +21,20 @@ ...@@ -20,11 +21,20 @@
Issue.labelRow = _.template( Issue.labelRow = _.template(
'<% _.each(labels, function(label){ %> '<% _.each(labels, function(label){ %>
<span class="label-row"> <span class="label-row">
<a href="#"><span class="label color-label" style="background-color: <%= label.color %>; color: #FFFFFF" title="<%= label.description %>" data-container="body"><%= label.title %></span></a> <a href="#"><span class="label color-label has-tooltip" style="background-color: <%= label.color %>; color: #FFFFFF" title="<%= label.description %>" data-container="body"><%= label.title %></span></a>
</span> </span>
<% }); %>' <% }); %>'
) )
toggleLabelFilters: ()->
$filteredLabels = $('.filtered-labels')
if $filteredLabels.find('.label-row').length > 0
#$filteredLabels.show()
$filteredLabels.slideDown().css({'overflow':'visible'})
else
#$filteredLabels.hide()
$filteredLabels.slideUp().css({'overflow':'visible'})
reload: -> reload: ->
Issues.initChecks() Issues.initChecks()
$('#filter_issue_search').val($('#issue_search').val()) $('#filter_issue_search').val($('#issue_search').val())
...@@ -43,13 +53,15 @@ ...@@ -43,13 +53,15 @@
paramKeys = ['author_id', 'milestone_title', 'assignee_id', 'issue_search'] paramKeys = ['author_id', 'milestone_title', 'assignee_id', 'issue_search']
for paramKey in paramKeys for paramKey in paramKeys
newParams[paramKey] = gl.utils.getUrlParameter(paramKey) or '' newParams[paramKey] = gl.utils.getParameterValues(paramKey)[0] or ''
if stateFilters.length if stateFilters.length
stateFilters.find('a').each -> stateFilters.find('a').each ->
initialUrl = gl.utils.removeParamQueryString($(this).attr('href'), 'label_name[]') initialUrl = gl.utils.removeParamQueryString($(this).attr('href'), 'label_name[]')
if gl.utils.getParamQueryString('label_name[]') labelNameValues = gl.utils.getParameterValues('label_name[]')
newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{gl.utils.getParamQueryString('label_name[]')}" if labelNameValues
labelNameQueryString = ("label_name[]=#{value}" for value in labelNameValues).join('&')
newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{labelNameQueryString}"
else else
newUrl = gl.utils.mergeUrlParams(newParams, initialUrl) newUrl = gl.utils.mergeUrlParams(newParams, initialUrl)
$(this).attr 'href', newUrl $(this).attr 'href', newUrl
...@@ -84,29 +96,24 @@ ...@@ -84,29 +96,24 @@
Issues.reload() Issues.reload()
Issues.updateStateFilters() Issues.updateStateFilters()
$filteredLabels = $('.filtered-labels') $filteredLabels = $('.filtered-labels')
$filteredLabelsSpans = $filteredLabels.find('span') $filteredLabelsSpans = $filteredLabels.find('.label-row')
gl.animate.animateEach( gl.animate.animateEach(
$filteredLabelsSpans, $filteredLabelsSpans, 'fadeOutDown', 20,
'fadeOutDown', 20, { cssStart:
cssStart: {
opacity: 1 opacity: 1
}, cssEnd:
cssEnd: {
opacity: 0 opacity: 0
} ).then( ->
}).then( ->
if typeof Issue.labelRow is 'function' if typeof Issue.labelRow is 'function'
$filteredLabels.html(Issue.labelRow(data)) $filteredLabels.html(Issue.labelRow(data))
$spans = $filteredLabels.find('span') Issues.toggleLabelFilters()
$spans.css('opacity',0) $spans = $filteredLabels.find('.label-row')
return gl.animate.animateEach($spans, 'fadeInUp', 20, { $spans.css('opacity', 0)
cssStart: { return gl.animate.animateEach $spans, 'fadeInUp', 20,
cssStart:
opacity: 0 opacity: 0
}, cssEnd:
cssEnd: {
opacity: 1 opacity: 1
}
})
) )
dataType: "json" dataType: "json"
......
...@@ -224,7 +224,7 @@ class @LabelsSelect ...@@ -224,7 +224,7 @@ class @LabelsSelect
selected_labels = $('.js-label-select').siblings('.dropdown-menu-labels').find('.is-active') selected_labels = $('.js-label-select').siblings('.dropdown-menu-labels').find('.is-active')
if selected and selected.title? if selected and selected.title?
if selected_labels and selected_labels.length > 1 if selected_labels.length > 1
"#{selected.title} +#{selected_labels.length - 1} more" "#{selected.title} +#{selected_labels.length - 1} more"
else else
selected.title selected.title
...@@ -247,7 +247,7 @@ class @LabelsSelect ...@@ -247,7 +247,7 @@ class @LabelsSelect
hidden: -> hidden: ->
page = $('body').data 'page' page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index' isIssueIndex = page is 'projects:issues:index'
isMRIndex = page is page is 'projects:merge_requests:index' isMRIndex = page is 'projects:merge_requests:index'
$selectbox.hide() $selectbox.hide()
# display:block overrides the hide-collapse rule # display:block overrides the hide-collapse rule
...@@ -256,11 +256,8 @@ class @LabelsSelect ...@@ -256,11 +256,8 @@ class @LabelsSelect
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
selectedLabels = $dropdown selectedLabels = $dropdown
.closest('form') .closest('form')
.find("input[type='hidden'][name='#{$dropdown.data('fieldName')}']") .find("input:hidden[name='#{$dropdown.data('fieldName')}']")
Issues.filterResults( Issues.filterResults $dropdown.closest('form')
$dropdown.closest('form'),
$dropdown.data('fieldName')
)
else if $dropdown.hasClass('js-filter-submit') else if $dropdown.hasClass('js-filter-submit')
$dropdown.closest('form').submit() $dropdown.closest('form').submit()
else else
...@@ -270,7 +267,7 @@ class @LabelsSelect ...@@ -270,7 +267,7 @@ class @LabelsSelect
clicked: (label) -> clicked: (label) ->
page = $('body').data 'page' page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index' isIssueIndex = page is 'projects:issues:index'
isMRIndex = page is page is 'projects:merge_requests:index' isMRIndex = page is 'projects:merge_requests:index'
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
if not $dropdown.hasClass 'js-multiselect' if not $dropdown.hasClass 'js-multiselect'
selectedLabel = label.title selectedLabel = label.title
......
...@@ -3,16 +3,20 @@ ...@@ -3,16 +3,20 @@
w.gl ?= {} w.gl ?= {}
w.gl.utils ?= {} w.gl.utils ?= {}
w.gl.utils.getUrlParameter = (sParam) -> # Returns an array containing the value(s) of the
# of the key passed as an argument
w.gl.utils.getParameterValues = (sParam) ->
sPageURL = decodeURIComponent(window.location.search.substring(1)) sPageURL = decodeURIComponent(window.location.search.substring(1))
sURLVariables = sPageURL.split('&') sURLVariables = sPageURL.split('&')
sParameterName = undefined sParameterName = undefined
values = []
i = 0 i = 0
while i < sURLVariables.length while i < sURLVariables.length
sParameterName = sURLVariables[i].split('=') sParameterName = sURLVariables[i].split('=')
if sParameterName[0] is sParam if sParameterName[0] is sParam
return if sParameterName[1] is undefined then true else sParameterName[1] values.push(sParameterName[1])
i++ i++
values
# # # #
# @param {Object} params - url keys and value to merge # @param {Object} params - url keys and value to merge
...@@ -28,14 +32,6 @@ ...@@ -28,14 +32,6 @@
newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}" newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}"
newUrl newUrl
# get parameter query string from url.
w.gl.utils.getParamQueryString = (param) ->
pageURL = decodeURIComponent(window.location.search.substring(1))
urlVariables = pageURL.split('&')
(
variables for variables in urlVariables when variables.indexOf(param) > -1
).join('&')
# removes parameter query string from url. returns the modified url # removes parameter query string from url. returns the modified url
w.gl.utils.removeParamQueryString = (url, param) -> w.gl.utils.removeParamQueryString = (url, param) ->
url = decodeURIComponent(url) url = decodeURIComponent(url)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# #
@MergeRequests = @MergeRequests =
init: -> init: ->
$('.filtered-labels').hide()
MergeRequests.initSearch() MergeRequests.initSearch()
# Make sure we trigger ajax request only after user stop typing # Make sure we trigger ajax request only after user stop typing
......
...@@ -18,22 +18,20 @@ module IssuablesHelper ...@@ -18,22 +18,20 @@ module IssuablesHelper
def multi_label_name(current_labels, default_label) def multi_label_name(current_labels, default_label)
# current_labels may be a string from before # current_labels may be a string from before
if current_labels.respond_to?('any?') if current_labels.is_a?(Array)
if current_labels.any? if current_labels.count > 1
if current_labels.count > 1 "#{current_labels[0]} +#{current_labels.count - 1} more"
"#{current_labels[0]} +#{current_labels.count - 1} more"
else
current_labels[0]
end
else else
default_label current_labels[0]
end end
else elsif current_labels.is_a?(String)
if current_labels.nil? || current_labels.empty? if current_labels.nil? || current_labels.empty?
default_label default_label
else else
current_labels current_labels
end end
else
default_label
end end
end end
......
- labels.each do |l| - labels.each do |label|
%span.label-row %span.label-row
= link_to_label(l, tooltip: false) = link_to_label(label, tooltip: false)
\ No newline at end of file \ No newline at end of file
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