From 2af947931d0c0095d37124b76428f4a1fc6d2545 Mon Sep 17 00:00:00 2001 From: Arinde Eniola <eniolaarinde1@gmail.com> Date: Wed, 20 Apr 2016 11:41:10 +0100 Subject: [PATCH] increase the speed of the labels animation ans aslo refactor some part fo issue.js --- app/assets/javascripts/issues.js.coffee | 47 +++++++++++-------- .../javascripts/labels_select.js.coffee | 13 ++--- .../javascripts/lib/url_utility.js.coffee | 16 +++---- .../javascripts/merge_requests.js.coffee | 1 + app/helpers/issuables_helper.rb | 16 +++---- app/views/shared/_labels_row.html.haml | 4 +- 6 files changed, 48 insertions(+), 49 deletions(-) diff --git a/app/assets/javascripts/issues.js.coffee b/app/assets/javascripts/issues.js.coffee index a3d9ce03875..8711c255350 100644 --- a/app/assets/javascripts/issues.js.coffee +++ b/app/assets/javascripts/issues.js.coffee @@ -3,6 +3,7 @@ Issues.initTemplates() Issues.initSearch() Issues.initChecks() + Issues.toggleLabelFilters() $("body").on "ajax:success", ".close_issue, .reopen_issue", -> t = $(this) @@ -20,11 +21,20 @@ Issue.labelRow = _.template( '<% _.each(labels, function(label){ %> <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> <% }); %>' ) + 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: -> Issues.initChecks() $('#filter_issue_search').val($('#issue_search').val()) @@ -43,13 +53,15 @@ paramKeys = ['author_id', 'milestone_title', 'assignee_id', 'issue_search'] for paramKey in paramKeys - newParams[paramKey] = gl.utils.getUrlParameter(paramKey) or '' + newParams[paramKey] = gl.utils.getParameterValues(paramKey)[0] or '' if stateFilters.length stateFilters.find('a').each -> initialUrl = gl.utils.removeParamQueryString($(this).attr('href'), 'label_name[]') - if gl.utils.getParamQueryString('label_name[]') - newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{gl.utils.getParamQueryString('label_name[]')}" + labelNameValues = gl.utils.getParameterValues('label_name[]') + if labelNameValues + labelNameQueryString = ("label_name[]=#{value}" for value in labelNameValues).join('&') + newUrl = "#{gl.utils.mergeUrlParams(newParams, initialUrl)}&#{labelNameQueryString}" else newUrl = gl.utils.mergeUrlParams(newParams, initialUrl) $(this).attr 'href', newUrl @@ -84,29 +96,24 @@ Issues.reload() Issues.updateStateFilters() $filteredLabels = $('.filtered-labels') - $filteredLabelsSpans = $filteredLabels.find('span') + $filteredLabelsSpans = $filteredLabels.find('.label-row') gl.animate.animateEach( - $filteredLabelsSpans, - 'fadeOutDown', 20, { - cssStart: { + $filteredLabelsSpans, 'fadeOutDown', 5, + cssStart: opacity: 1 - }, - cssEnd: { + cssEnd: opacity: 0 - } - }).then( -> + ).then( -> if typeof Issue.labelRow is 'function' $filteredLabels.html(Issue.labelRow(data)) - $spans = $filteredLabels.find('span') - $spans.css('opacity',0) - return gl.animate.animateEach($spans, 'fadeInUp', 20, { - cssStart: { + Issues.toggleLabelFilters() + $spans = $filteredLabels.find('.label-row') + $spans.css('opacity', 0) + return gl.animate.animateEach $spans, 'fadeInUp', 5, + cssStart: opacity: 0 - }, - cssEnd: { + cssEnd: opacity: 1 - } - }) ) dataType: "json" diff --git a/app/assets/javascripts/labels_select.js.coffee b/app/assets/javascripts/labels_select.js.coffee index 83e3062d222..6a89817e647 100644 --- a/app/assets/javascripts/labels_select.js.coffee +++ b/app/assets/javascripts/labels_select.js.coffee @@ -224,7 +224,7 @@ class @LabelsSelect selected_labels = $('.js-label-select').siblings('.dropdown-menu-labels').find('.is-active') 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" else selected.title @@ -247,7 +247,7 @@ class @LabelsSelect hidden: -> page = $('body').data 'page' isIssueIndex = page is 'projects:issues:index' - isMRIndex = page is page is 'projects:merge_requests:index' + isMRIndex = page is 'projects:merge_requests:index' $selectbox.hide() # display:block overrides the hide-collapse rule @@ -256,11 +256,8 @@ class @LabelsSelect if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) selectedLabels = $dropdown .closest('form') - .find("input[type='hidden'][name='#{$dropdown.data('fieldName')}']") - Issues.filterResults( - $dropdown.closest('form'), - $dropdown.data('fieldName') - ) + .find("input:hidden[name='#{$dropdown.data('fieldName')}']") + Issues.filterResults $dropdown.closest('form') else if $dropdown.hasClass('js-filter-submit') $dropdown.closest('form').submit() else @@ -270,7 +267,7 @@ class @LabelsSelect clicked: (label) -> page = $('body').data 'page' 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 not $dropdown.hasClass 'js-multiselect' selectedLabel = label.title diff --git a/app/assets/javascripts/lib/url_utility.js.coffee b/app/assets/javascripts/lib/url_utility.js.coffee index c2e3c807e5e..6a00932c028 100644 --- a/app/assets/javascripts/lib/url_utility.js.coffee +++ b/app/assets/javascripts/lib/url_utility.js.coffee @@ -3,16 +3,20 @@ w.gl ?= {} 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)) sURLVariables = sPageURL.split('&') sParameterName = undefined + values = [] i = 0 while i < sURLVariables.length sParameterName = sURLVariables[i].split('=') if sParameterName[0] is sParam - return if sParameterName[1] is undefined then true else sParameterName[1] + values.push(sParameterName[1]) i++ + values # # # @param {Object} params - url keys and value to merge @@ -28,14 +32,6 @@ newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}" 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 w.gl.utils.removeParamQueryString = (url, param) -> url = decodeURIComponent(url) diff --git a/app/assets/javascripts/merge_requests.js.coffee b/app/assets/javascripts/merge_requests.js.coffee index b3c73ffce5d..203def58783 100644 --- a/app/assets/javascripts/merge_requests.js.coffee +++ b/app/assets/javascripts/merge_requests.js.coffee @@ -3,6 +3,7 @@ # @MergeRequests = init: -> + $('.filtered-labels').hide() MergeRequests.initSearch() # Make sure we trigger ajax request only after user stop typing diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index b363ed3076c..5baa4f53bb9 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -18,22 +18,20 @@ module IssuablesHelper def multi_label_name(current_labels, default_label) # current_labels may be a string from before - if current_labels.respond_to?('any?') - if current_labels.any? - if current_labels.count > 1 - "#{current_labels[0]} +#{current_labels.count - 1} more" - else - current_labels[0] - end + if current_labels.is_a?(Array) + if current_labels.count > 1 + "#{current_labels[0]} +#{current_labels.count - 1} more" else - default_label + current_labels[0] end - else + elsif current_labels.is_a?(String) if current_labels.nil? || current_labels.empty? default_label else current_labels end + else + default_label end end diff --git a/app/views/shared/_labels_row.html.haml b/app/views/shared/_labels_row.html.haml index f81a04a3c86..09dc6d97d10 100644 --- a/app/views/shared/_labels_row.html.haml +++ b/app/views/shared/_labels_row.html.haml @@ -1,3 +1,3 @@ -- labels.each do |l| +- labels.each do |label| %span.label-row - = link_to_label(l, tooltip: false) \ No newline at end of file + = link_to_label(label, tooltip: false) \ No newline at end of file -- GitLab