Commit 8ca880c3 authored by Phil Hughes's avatar Phil Hughes

Correctly fitlers remotely

parent 562a09c1
class GitLabDropdownFilter
BLUR_KEYCODES = [27, 40]
constructor: (@dropdown, @remote, @data, @callback) ->
constructor: (@dropdown, @remote, @query, @data, @callback) ->
@input = @dropdown.find(".dropdown-input-field")
# Key events
timeout = ""
@input.on "keyup", (e) =>
clearTimeout timeout
timeout = setTimeout =>
blur_field = @shouldBlur e.keyCode
search_text = @input.val()
......@@ -13,10 +16,11 @@ class GitLabDropdownFilter
@input.blur()
if @remote
@remote search_text, (data) =>
@query search_text, (data) =>
@callback(data)
else
@filter search_text
, 250
shouldBlur: (keyCode) ->
return BLUR_KEYCODES.indexOf(keyCode) >= 0
......@@ -38,7 +42,7 @@ class GitLabDropdownRemote
@options.beforeSend()
# Fetch the data by calling the data funcfion
@dataEndpoint (data) =>
@dataEndpoint "", (data) =>
if @options.success
@options.success(data)
......@@ -86,13 +90,14 @@ class GitLabDropdown
# Init filiterable
if @options.filterable
@filter = new GitLabDropdownFilter @dropdown, @options.query, =>
@filter = new GitLabDropdownFilter @dropdown, @options.filterRemote, @options.data, =>
return @fullData
, (data) =>
@parseData data
# Event listeners
$(@el).parent().on "shown.bs.dropdown", @opened
$(@el).parent().on "hidden.bs.dropdown", @hidden
if @options.selectable
@dropdown.on "click", "a", (e) ->
......@@ -124,6 +129,13 @@ class GitLabDropdown
if @remote
@remote.execute()
if @options.filterable
@dropdown.find(".dropdown-input-field").focus()
hidden: =>
if @options.filterable
@dropdown.find(".dropdown-input-field").blur().val("")
# Render the full menu
renderMenu: (html) ->
menu_html = ""
......
......@@ -5,7 +5,7 @@ class @LabelsSelect
selectedLabel = $(dropdown).data('selected')
$(dropdown).glDropdown(
data: (callback) ->
data: (term, callback) ->
Api.projectLabels 8, callback
renderRow: (label) ->
selected = if label.name is selectedLabel then "is-active" else ""
......
......@@ -5,11 +5,11 @@ class @MilestoneSelect
selectedMilestone = $(dropdown).data('selected')
$(dropdown).glDropdown(
data: (callback) ->
data: (term, callback) ->
Api.milestones projectId, callback
filterable: true
search:
fields: ['name']
fields: ['title']
selectable: true
fieldName: $(dropdown).data('field-name')
text: (milestone) ->
......
......@@ -6,20 +6,41 @@ class @UsersSelect
$('.js-user-search').each (i, dropdown) =>
projectId = $(dropdown).data('project-id')
showNullUser = $(dropdown).data('null-user')
showAnyUser = $(dropdown).data('any-user')
firstUser = $(dropdown).data('first-user')
selectedId = $(dropdown).data('selected')
$(dropdown).glDropdown(
data: (callback) =>
@users "", (users) =>
data: (term, callback) =>
@users term, (users) =>
if term.length is 0
if firstUser
# Move current user to the front of the list
for obj, index in users
if obj.username == firstUser
users.splice(index, 1)
users.unshift(obj)
break
if showNullUser
users.unshift(
name: 'Unassigned',
id: 0
)
if showAnyUser
name = showAnyUser
name = 'Any User' if name == true
anyUser = {
name: name,
id: null
}
users.unshift(anyUser)
# Send the data back
callback users
filterable: true
filterRemote: true
search:
fields: ['name', 'username']
selectable: true
......
......@@ -17,7 +17,7 @@ module DropdownsHelper
output += content_tag :div, class: "dropdown-title" do
title_output = content_tag(:span, title)
title_output += content_tag :button, class: "dropdown-title-button dropdown-menu-close", aria: {label: "close"} do
title_output += content_tag :button, class: "dropdown-title-button dropdown-menu-close", aria: {label: "close"}, type: "button" do
icon('times')
end.html_safe
end
......
......@@ -7,18 +7,26 @@
class: "check_all_issues left"
.issues-other-filters
.filter-item.inline
- if params[:author_id]
= hidden_field_tag(:author_id, params[:author_id])
= dropdown_tag("Author", toggle_class: "js-user-search", title: "Filter by author", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable",
placeholder: "Search authors", data: {any_user: "Any Author", first_user: true, current_user: true, project_id: @project.id, selected: params[:author_id], field_name: "author_id"})
.filter-item.inline
- if params[:assignee_id]
= hidden_field_tag(:assignee_id, params[:assignee_id])
= dropdown_tag("Assignee", toggle_class: "js-user-search", title: "Filter by assignee", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable",
placeholder: "Search assignee", data: {any_user: "Any Author", first_user: true, null_user: true, current_user: true, project_id: @project.id, selected: params[:assignee_id], field_name: "assignee_id"})
.filter-item.inline.milestone-filter
- if params[:milestone_title]
= hidden_field_tag(:milestone_title, params[:milestone_title])
= dropdown_tag("Milestone", title: "Filter by milestone", toggle_class: 'js-milestone-select', filter: true, dropdown_class: "dropdown-menu-selectable",
placeholder: "Search milestones", data: {field_name: "milestone_title", selected: params[:milestone_title], project_id: @project.id})
.filter-item.inline.labels-filter
- if params[:label_name]
= hidden_field_tag(:label_name, params[:label_name])
= dropdown_tag("Label", title: "Filter by label", toggle_class: "js-label-select", filter: true, dropdown_class: "dropdown-menu-labels dropdown-menu-selectable",
placeholder: "Search labels", footer_content: true, data: {field_name: "label_name", selected: params[:label_name], project_id: @project.id}) do
%ul.dropdown-footer-list
......
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