Commit 14964308 authored by Arinde Eniola's avatar Arinde Eniola

add gfm autocomplete for labels

parent f0c4f727
......@@ -14,6 +14,10 @@ GitLab.GfmAutoComplete =
Members:
template: '<li>${username} <small>${title}</small></li>'
Labels:
template: '<li>${title} <div style="background-color:${color};height:15px;width:15px;display:inline-block;float:right">
</div></li>'
# Issues and MergeRequests
Issues:
template: '<li><small>${id}</small> ${title}</li>'
......@@ -94,6 +98,25 @@ GitLab.GfmAutoComplete =
title: sanitize(m.title)
search: "#{m.iid} #{m.title}"
@input.atwho
at: '~'
alias: 'labels'
searchKey: 'search'
displayTpl: @Labels.template
insertTpl: '${atwho-at}${title}'
callbacks:
beforeSave: (merges) ->
sanitizeLabelTitle = (title)->
if /\w+\s+\w+/g.test(title)
"\"#{sanitize(title)}\""
else
sanitize(title)
$.map merges, (m) ->
title: sanitizeLabelTitle(m.title)
color: m.color
search: "#{m.title}"
destroyAtWho: ->
@input.atwho('destroy')
......@@ -109,3 +132,5 @@ GitLab.GfmAutoComplete =
@input.atwho 'load', 'mergerequests', data.mergerequests
# load emojis
@input.atwho 'load', ':', data.emojis
# load labels
@input.atwho 'load', '~', data.labels
......@@ -148,6 +148,7 @@ class ProjectsController < Projects::ApplicationController
emojis: AwardEmoji.urls,
issues: autocomplete.issues,
mergerequests: autocomplete.merge_requests,
labels: autocomplete.labels,
members: participants
}
......
......@@ -7,5 +7,9 @@ module Projects
def merge_requests
@project.merge_requests.opened.select([:iid, :title])
end
def labels
@project.labels.select([:title, :color])
end
end
end
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