Commit deca5ef2 authored by Phil Hughes's avatar Phil Hughes

Refs dropdown is now loaded async

parent 0aab84c7
...@@ -58,7 +58,7 @@ class GitLabDropdownFilter ...@@ -58,7 +58,7 @@ class GitLabDropdownFilter
filter: (search_text) -> filter: (search_text) ->
data = @options.data() data = @options.data()
if data? if data? and not @options.filterByText
results = data results = data
if search_text isnt '' if search_text isnt ''
...@@ -102,6 +102,7 @@ class GitLabDropdownFilter ...@@ -102,6 +102,7 @@ class GitLabDropdownFilter
$el = $(@) $el = $(@)
matches = fuzzaldrinPlus.match($el.text().trim(), search_text) matches = fuzzaldrinPlus.match($el.text().trim(), search_text)
if $el.is(':not(.dropdown-header)')
if matches.length if matches.length
$el.show() $el.show()
else else
...@@ -191,6 +192,7 @@ class GitLabDropdown ...@@ -191,6 +192,7 @@ class GitLabDropdown
if @options.filterable if @options.filterable
@filter = new GitLabDropdownFilter @filterInput, @filter = new GitLabDropdownFilter @filterInput,
filterInputBlur: @filterInputBlur filterInputBlur: @filterInputBlur
filterByText: @options.filterByText
remote: @options.filterRemote remote: @options.filterRemote
query: @options.data query: @options.data
keys: searchFields keys: searchFields
......
...@@ -19,6 +19,7 @@ class @Project ...@@ -19,6 +19,7 @@ class @Project
$('.clone').text(url) $('.clone').text(url)
# Ref switcher # Ref switcher
@initRefSwitcher()
$('.project-refs-select').on 'change', -> $('.project-refs-select').on 'change', ->
$(@).parents('form').submit() $(@).parents('form').submit()
...@@ -50,3 +51,37 @@ class @Project ...@@ -50,3 +51,37 @@ class @Project
changeProject: (url) -> changeProject: (url) ->
window.location = url window.location = url
initRefSwitcher: ->
$('.js-project-refs-dropdown').each ->
$dropdown = $(@)
selected = $dropdown.data('selected')
$dropdown.glDropdown(
data: (term, callback) ->
$.ajax(
url: $dropdown.data('refs-url')
).done (refs) ->
callback(refs)
selectable: true
filterable: true
filterByText: true
fieldName: 'ref'
renderRow: (ref) ->
if ref.header?
"<li class='dropdown-header'>#{ref.header}</li>"
else
isActiveClass = if ref is selected then 'is-active' else ''
"<li>
<a href='#' data-ref='#{ref}' class='#{isActiveClass}'>
#{ref}
</a>
</li>"
id: (obj, $el) ->
$el.data('ref')
toggleLabel: (obj, $el) ->
$el.text().trim()
clicked: (e) ->
$dropdown.closest('form').submit()
)
...@@ -165,11 +165,6 @@ ...@@ -165,11 +165,6 @@
background-size: 16px 16px !important; background-size: 16px 16px !important;
} }
/** Branch/tag selector **/
.project-refs-form .select2-container {
width: 160px !important;
}
.select2-results .select2-no-results, .select2-results .select2-no-results,
.select2-results .select2-searching, .select2-results .select2-searching,
.select2-results .select2-ajax-error, .select2-results .select2-ajax-error,
......
...@@ -616,3 +616,9 @@ pre.light-well { ...@@ -616,3 +616,9 @@ pre.light-well {
color: $gl-text-green; color: $gl-text-green;
} }
} }
.project-refs-form {
.dropdown-menu {
width: 300px;
}
}
...@@ -251,6 +251,22 @@ class ProjectsController < Projects::ApplicationController ...@@ -251,6 +251,22 @@ class ProjectsController < Projects::ApplicationController
} }
end end
def refs
repository = @project.repository
options = {
'Branches' => repository.branch_names,
'Tags' => VersionSorter.rsort(repository.tag_names)
}
# If reference is commit id - we should add it to branch/tag selectbox
if @ref && !options.flatten.include?(@ref) && @ref =~ /\A[0-9a-zA-Z]{6,52}\z/
options << {'Commits' => @ref}
end
render json: options.to_json
end
private private
def determine_layout def determine_layout
......
= form_tag switch_namespace_project_refs_path(@project.namespace, @project), method: :get, class: "project-refs-form" do = form_tag switch_namespace_project_refs_path(@project.namespace, @project), method: :get, class: "project-refs-form" do
= select_tag "ref", grouped_options_refs, class: "project-refs-select select2 select2-sm"
= hidden_field_tag :destination, destination = hidden_field_tag :destination, destination
- if defined?(path) - if defined?(path)
= hidden_field_tag :path, path = hidden_field_tag :path, path
- @options && @options.each do |key, value| - @options && @options.each do |key, value|
= hidden_field_tag key, value, id: nil = hidden_field_tag key, value, id: nil
.dropdown
= dropdown_toggle @ref || @project.default_branch, { toggle: "dropdown", selected: @ref || @project.default_branch, refs_url: refs_namespace_project_path(@project.namespace, @project) }, { toggle_class: "js-project-refs-dropdown" }
.dropdown-menu.dropdown-menu-selectable
= dropdown_title "Switch branch/tag"
= dropdown_filter "Search branches and tags"
= dropdown_content
= dropdown_loading
-# = select_tag "ref", grouped_options_refs, class: "project-refs-select select2 select2-sm"
...@@ -479,6 +479,7 @@ Rails.application.routes.draw do ...@@ -479,6 +479,7 @@ Rails.application.routes.draw do
get :download_export get :download_export
get :autocomplete_sources get :autocomplete_sources
get :activity get :activity
get :refs
end end
scope module: :projects do scope module: :projects do
......
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