Commit 14964308 authored by Arinde Eniola's avatar Arinde Eniola

add gfm autocomplete for labels

parent f0c4f727
...@@ -14,6 +14,10 @@ GitLab.GfmAutoComplete = ...@@ -14,6 +14,10 @@ GitLab.GfmAutoComplete =
Members: Members:
template: '<li>${username} <small>${title}</small></li>' 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 and MergeRequests
Issues: Issues:
template: '<li><small>${id}</small> ${title}</li>' template: '<li><small>${id}</small> ${title}</li>'
...@@ -94,6 +98,25 @@ GitLab.GfmAutoComplete = ...@@ -94,6 +98,25 @@ GitLab.GfmAutoComplete =
title: sanitize(m.title) title: sanitize(m.title)
search: "#{m.iid} #{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: -> destroyAtWho: ->
@input.atwho('destroy') @input.atwho('destroy')
...@@ -109,3 +132,5 @@ GitLab.GfmAutoComplete = ...@@ -109,3 +132,5 @@ GitLab.GfmAutoComplete =
@input.atwho 'load', 'mergerequests', data.mergerequests @input.atwho 'load', 'mergerequests', data.mergerequests
# load emojis # load emojis
@input.atwho 'load', ':', data.emojis @input.atwho 'load', ':', data.emojis
# load labels
@input.atwho 'load', '~', data.labels
...@@ -148,6 +148,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -148,6 +148,7 @@ class ProjectsController < Projects::ApplicationController
emojis: AwardEmoji.urls, emojis: AwardEmoji.urls,
issues: autocomplete.issues, issues: autocomplete.issues,
mergerequests: autocomplete.merge_requests, mergerequests: autocomplete.merge_requests,
labels: autocomplete.labels,
members: participants members: participants
} }
......
...@@ -7,5 +7,9 @@ module Projects ...@@ -7,5 +7,9 @@ module Projects
def merge_requests def merge_requests
@project.merge_requests.opened.select([:iid, :title]) @project.merge_requests.opened.select([:iid, :title])
end end
def labels
@project.labels.select([:title, :color])
end
end 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