Commit 3753ace9 authored by Jacob Schatz's avatar Jacob Schatz

Add labels as proper POST arrays using new dropdown

parent 024dc807
...@@ -6,8 +6,8 @@ class @LabelsSelect ...@@ -6,8 +6,8 @@ class @LabelsSelect
labelUrl = $dropdown.data('labels') labelUrl = $dropdown.data('labels')
issueUpdateURL = $dropdown.data('issueUpdate') issueUpdateURL = $dropdown.data('issueUpdate')
selectedLabel = $dropdown.data('selected') selectedLabel = $dropdown.data('selected')
if selectedLabel if selectedLabel?
selectedLabel = selectedLabel.toString().split(',') selectedLabel = selectedLabel.split(',')
newLabelField = $('#new_label_name') newLabelField = $('#new_label_name')
newColorField = $('#new_label_color') newColorField = $('#new_label_color')
showNo = $dropdown.data('show-no') showNo = $dropdown.data('show-no')
...@@ -17,7 +17,18 @@ class @LabelsSelect ...@@ -17,7 +17,18 @@ class @LabelsSelect
$block = $selectbox.closest('.block') $block = $selectbox.closest('.block')
$value = $block.find('.value') $value = $block.find('.value')
$loading = $block.find('.block-loading').fadeOut() $loading = $block.find('.block-loading').fadeOut()
issueURLSplit = issueUpdateURL.split('/')
if newLabelField.length
$newLabelCreateButton = $('.js-new-label-btn')
$colorPreview = $('.js-dropdown-label-color-preview')
$newLabelError = $dropdown.parent().find('.js-label-error')
$newLabelError.hide()
# Suggested colors in the dropdown to chose from pre-chosen colors
$('.suggest-colors-dropdown a').on 'click', (e) ->
issueURLSplit = issueURL.split('/') if issueURL?
if issueURL
labelHTMLTemplate = _.template( labelHTMLTemplate = _.template(
'<% _.each(labels, function(label){ %>'+ '<% _.each(labels, function(label){ %>'+
'<a href="'+ '<a href="'+
...@@ -31,14 +42,8 @@ class @LabelsSelect ...@@ -31,14 +42,8 @@ class @LabelsSelect
'</a>'+ '</a>'+
'<% }); %>'); '<% }); %>');
if newLabelField.length if newLabelField.length and $dropdown.hasClass 'js-extra-options'
$newLabelCreateButton = $('.js-new-label-btn') $('.suggest-colors-dropdown a').on "click", (e) ->
$colorPreview = $('.js-dropdown-label-color-preview')
$newLabelError = $dropdown.parent().find('.js-label-error')
$newLabelError.hide()
# Suggested colors in the dropdown to chose from pre-chosen colors
$('.suggest-colors-dropdown a').on 'click', (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
newColorField newColorField
...@@ -113,6 +118,7 @@ class @LabelsSelect ...@@ -113,6 +118,7 @@ class @LabelsSelect
$.ajax( $.ajax(
url: labelUrl url: labelUrl
).done (data) -> ).done (data) ->
if $dropdown.hasClass 'js-extra-options'
if showNo if showNo
data.unshift( data.unshift(
id: 0 id: 0
...@@ -127,8 +133,8 @@ class @LabelsSelect ...@@ -127,8 +133,8 @@ class @LabelsSelect
if data.length > 2 if data.length > 2
data.splice 2, 0, 'divider' data.splice 2, 0, 'divider'
callback data callback data
renderRow: (label) -> renderRow: (label) ->
if $.isArray(selectedLabel) if $.isArray(selectedLabel)
selected = '' selected = ''
...@@ -184,16 +190,19 @@ class @LabelsSelect ...@@ -184,16 +190,19 @@ class @LabelsSelect
.closest('.selectbox') .closest('.selectbox')
.find('input[type="hidden"]') .find('input[type="hidden"]')
.val() .val()
console.log 'selected', selected
# need inline-block here instead of show, # need inline-block here instead of show,
# which will default to the element's style in this case inline. # which will default to the element's style in this case inline.
selected = if selected? then [ selected ] else ['']
console.log 'selected', selected
$loading $loading
.fadeIn() .fadeIn()
$.ajax( $.ajax(
type: 'PUT' type: 'PUT'
url: issueUpdateURL url: issueURL
data: data:
issue: issue:
label_ids: [selected] label_ids: selected
).done (data) -> ).done (data) ->
$loading.fadeOut() $loading.fadeOut()
$selectbox.hide() $selectbox.hide()
......
...@@ -21,6 +21,7 @@ class @MilestoneSelect ...@@ -21,6 +21,7 @@ class @MilestoneSelect
$.ajax( $.ajax(
url: milestonesUrl url: milestonesUrl
).done (data) -> ).done (data) ->
if $dropdown.hasClass "js-extra-options"
if showNo if showNo
data.unshift( data.unshift(
id: '0' id: '0'
...@@ -35,7 +36,6 @@ class @MilestoneSelect ...@@ -35,7 +36,6 @@ class @MilestoneSelect
if data.length > 2 if data.length > 2
data.splice 2, 0, 'divider' data.splice 2, 0, 'divider'
callback(data) callback(data)
filterable: true filterable: true
search: search:
......
...@@ -69,7 +69,13 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -69,7 +69,13 @@ class Projects::IssuesController < Projects::ApplicationController
@merge_requests = @issue.referenced_merge_requests(current_user) @merge_requests = @issue.referenced_merge_requests(current_user)
@related_branches = @issue.related_branches - @merge_requests.map(&:source_branch) @related_branches = @issue.related_branches - @merge_requests.map(&:source_branch)
respond_with(@issue) respond_to do |format|
format.html
format.json do
render json: @issue.to_json(include: [:milestone, :labels])
end
end
end end
def create def create
......
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
= dropdown_tag("Assignee", options: { toggle_class: "js-user-search js-update-assignee", title: "Assign to", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable", = dropdown_tag("Assignee", options: { toggle_class: "js-user-search js-update-assignee", title: "Assign to", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable",
placeholder: "Search authors", data: { first_user: (current_user.username if current_user), null_user: true, current_user: true, project_id: @project.id, field_name: "update[assignee_id]" } }) placeholder: "Search authors", data: { first_user: (current_user.username if current_user), null_user: true, current_user: true, project_id: @project.id, field_name: "update[assignee_id]" } })
.filter-item.inline .filter-item.inline
= dropdown_tag("Milestone", options: { title: "Assign milestone", toggle_class: 'js-milestone-select', filter: true, dropdown_class: "dropdown-menu-selectable dropdown-menu-milestone", = dropdown_tag("Milestone", options: { title: "Assign milestone", toggle_class: 'js-milestone-select js-extra-options', filter: true, dropdown_class: "dropdown-menu-selectable dropdown-menu-milestone", placeholder: "Search milestones", data: { show_no: true, field_name: "update[milestone_id]", project_id: @project.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), use_id: true } })
placeholder: "Search milestones", data: { show_no: true, field_name: "update[milestone_id]", project_id: @project.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), use_id: true } })
= hidden_field_tag 'update[issues_ids]', [] = hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :state_event, params[:state_event] = hidden_field_tag :state_event, params[:state_event]
.filter-item.inline .filter-item.inline
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
.light None .light None
.selectbox.hide-collapsed .selectbox.hide-collapsed
.dropdown .dropdown
%button.dropdown-menu-toggle.js-label-select{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: params[:label_name], project_id: (@project.id if @project), issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json), labels: (namespace_project_labels_path(@project.namespace, @project, :json) if @project)}} %button.dropdown-menu-toggle.js-label-select.js-multiselect{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: issuable.label_names.join(","), project_id: (@project.id if @project), issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json), labels: (namespace_project_labels_path(@project.namespace, @project, :json) if @project)}}
%span.dropdown-toggle-text %span.dropdown-toggle-text
Label Label
= icon('chevron-down') = icon('chevron-down')
......
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