Commit 3898bffd authored by Alfredo Sumaran's avatar Alfredo Sumaran

Code improvements

parent 79a4292f
...@@ -20,7 +20,7 @@ class GitLabDropdownFilter ...@@ -20,7 +20,7 @@ class GitLabDropdownFilter
blur_field = @shouldBlur e.keyCode blur_field = @shouldBlur e.keyCode
search_text = @input.val() search_text = @input.val()
if blur_field && @filterInputBlur if blur_field and @filterInputBlur
@input.blur() @input.blur()
if @options.remote if @options.remote
...@@ -88,7 +88,7 @@ class GitLabDropdown ...@@ -88,7 +88,7 @@ class GitLabDropdown
# Set Defaults # Set Defaults
{ {
# If no input is passed create a default one # If no input is passed create a default one
@filterInput = @$(FILTER_INPUT) @filterInput = @getElement(FILTER_INPUT)
@highlight = false @highlight = false
@filterInputBlur = true @filterInputBlur = true
} = @options } = @options
...@@ -97,8 +97,7 @@ class GitLabDropdown ...@@ -97,8 +97,7 @@ class GitLabDropdown
# If selector was passed # If selector was passed
if _.isString(@filterInput) if _.isString(@filterInput)
@filterInput = @$(@filterInput) @filterInput = @getElement(@filterInput)
search_fields = if @options.search then @options.search.fields else []; search_fields = if @options.search then @options.search.fields else [];
...@@ -156,8 +155,9 @@ class GitLabDropdown ...@@ -156,8 +155,9 @@ class GitLabDropdown
if self.options.clicked if self.options.clicked
self.options.clicked() self.options.clicked()
$: (selector) -> # Finds an element inside wrapper element
$(selector, @dropdown) getElement: (selector) ->
@dropdown.find selector
toggleLoading: -> toggleLoading: ->
$('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS $('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS
...@@ -268,12 +268,9 @@ class GitLabDropdown ...@@ -268,12 +268,9 @@ class GitLabDropdown
highlightTextMatches: (text, term) -> highlightTextMatches: (text, term) ->
occurrences = fuzzaldrinPlus.match(text, term) occurrences = fuzzaldrinPlus.match(text, term)
textArr = text.split('') text.split('').map((character, i) ->
textArr.forEach (character, i, textArr) -> if i in occurrences then "<b>#{character}</b>" else character
if i in occurrences ).join('')
textArr[i] = "<b>#{character}</b>"
textArr.join ''
noResults: -> noResults: ->
html = "<li>" html = "<li>"
......
...@@ -20,15 +20,15 @@ class @SearchAutocomplete ...@@ -20,15 +20,15 @@ class @SearchAutocomplete
# Dropdown Element # Dropdown Element
@dropdown = @wrap.find('.dropdown') @dropdown = @wrap.find('.dropdown')
@locationBadgeEl = @$('.search-location-badge') @locationBadgeEl = @getElement('.search-location-badge')
@locationText = @$('.location-text') @locationText = @getElement('.location-text')
@scopeInputEl = @$('#scope') @scopeInputEl = @getElement('#scope')
@searchInput = @$('.search-input') @searchInput = @getElement('.search-input')
@projectInputEl = @$('#search_project_id') @projectInputEl = @getElement('#search_project_id')
@groupInputEl = @$('#group_id') @groupInputEl = @getElement('#group_id')
@searchCodeInputEl = @$('#search_code') @searchCodeInputEl = @getElement('#search_code')
@repositoryInputEl = @$('#repository_ref') @repositoryInputEl = @getElement('#repository_ref')
@scopeInputEl = @$('#scope') @scopeInputEl = @getElement('#scope')
@saveOriginalState() @saveOriginalState()
...@@ -36,7 +36,8 @@ class @SearchAutocomplete ...@@ -36,7 +36,8 @@ class @SearchAutocomplete
@bindEvents() @bindEvents()
$: (selector) -> # Finds an element inside wrapper element
getElement: (selector) ->
@wrap.find(selector) @wrap.find(selector)
saveOriginalState: -> saveOriginalState: ->
...@@ -60,11 +61,9 @@ class @SearchAutocomplete ...@@ -60,11 +61,9 @@ class @SearchAutocomplete
@searchInput.on 'blur', @onSearchInputBlur @searchInput.on 'blur', @onSearchInputBlur
enableAutocomplete: -> enableAutocomplete: ->
self = @ dropdownMenu = @dropdown.find('.dropdown-menu')
@query = "?project_id=" + @projectId + "&project_ref=" + @projectRef _this = @
dropdownMenu = self.dropdown.find('.dropdown-menu') @searchInput.glDropdown
@searchInput.glDropdown(
filterInputBlur: false filterInputBlur: false
filterable: true filterable: true
filterRemote: true filterRemote: true
...@@ -73,13 +72,11 @@ class @SearchAutocomplete ...@@ -73,13 +72,11 @@ class @SearchAutocomplete
search: search:
fields: ['text'] fields: ['text']
data: (term, callback) -> data: (term, callback) ->
$.ajax $.get(_this.autocompletePath, {
url: self.autocompletePath + self.query project_id: _this.projectId
data: project_ref: _this.projectRef
term: term term: term
beforeSend: -> }, (response) ->
# dropdownMenu.addClass 'is-loading'
success: (response) ->
data = [] data = []
# Save groups ordering according to server response # Save groups ordering according to server response
...@@ -101,16 +98,12 @@ class @SearchAutocomplete ...@@ -101,16 +98,12 @@ class @SearchAutocomplete
data.push data.push
text: item.label text: item.label
url: item.url url: item.url
callback(data) callback(data)
complete: ->
# dropdownMenu.removeClass 'is-loading'
) )
@dropdown.addClass('open') @dropdown.addClass('open')
@searchInput.removeClass('disabled') @searchInput.removeClass('disabled')
@autocomplete = true; @autocomplete = true
onDropdownOpen: (e) => onDropdownOpen: (e) =>
@dropdown.dropdown('toggle') @dropdown.dropdown('toggle')
...@@ -158,7 +151,7 @@ class @SearchAutocomplete ...@@ -158,7 +151,7 @@ class @SearchAutocomplete
inputs = Object.keys @originalState inputs = Object.keys @originalState
for input in inputs for input in inputs
@$("##{input}").val(@originalState[input]) @getElement("##{input}").val(@originalState[input])
if @originalState._location is '' if @originalState._location is ''
...@@ -200,6 +193,6 @@ class @SearchAutocomplete ...@@ -200,6 +193,6 @@ class @SearchAutocomplete
@resetSearchState() @resetSearchState()
disableAutocomplete: -> disableAutocomplete: ->
if @autocomplete isnt undefined if @autocomplete?
@searchInput.addClass('disabled') @searchInput.addClass('disabled')
@autocomplete = undefined @autocomplete = null
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