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

Correctly fitlers remotely

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