diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-02-10 11:31:36 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-02-10 11:31:36 +0300 |
commit | 22808a2221dce5826891279588b774ad58a492c0 (patch) | |
tree | 368a7a314ee0cb1c96a5d57f0acbdade0452b25b /app/assets | |
parent | 93d62bb8afb54f5ad134bdcdc2a39e08d7e7c993 (diff) | |
parent | cf8a74be5fda908fd5c50a9303c44d1f95fadfa2 (diff) |
Merge branch 'fix-explore-filter' into 'master'
Add ajax filtering to all paged project lists. Fixes #13182
See merge request !2728
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/dashboard.js.coffee | 9 | ||||
-rw-r--r-- | app/assets/javascripts/dispatcher.js.coffee | 2 | ||||
-rw-r--r-- | app/assets/javascripts/projects_list.js.coffee | 34 |
3 files changed, 25 insertions, 20 deletions
diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee index dd295088312..62143e66cfe 100644 --- a/app/assets/javascripts/dashboard.js.coffee +++ b/app/assets/javascripts/dashboard.js.coffee @@ -1,10 +1,11 @@ @Dashboard = init: -> + $(".projects-list-filter").off('keyup') this.initSearch() initSearch: -> @timer = null - $("#project-filter-form-field").on('keyup', -> + $(".projects-list-filter").on('keyup', -> clearTimeout(@timer) @timer = setTimeout(Dashboard.filterResults, 500) ) @@ -13,8 +14,8 @@ $('.projects-list-holder').fadeTo(250, 0.5) form = null - form = $("#project-filter-form") - search = $("#project-filter-form-field").val() + form = $("form#project-filter-form") + search = $(".projects-list-filter").val() project_filter_url = form.attr('action') + '?' + form.serialize() $.ajax @@ -24,7 +25,7 @@ complete: -> $('.projects-list-holder').fadeTo(250, 1) success: (data) -> - $('div.projects-list-holder').replaceWith(data.html) + $('.projects-list-holder').replaceWith(data.html) # Change url so if user reload a page - search results are saved history.replaceState {page: project_filter_url}, document.title, project_filter_url dataType: "json" diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index d4a2b74b143..b17f8e51470 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -16,6 +16,8 @@ class Dispatcher shortcut_handler = null switch page + when 'explore:projects:index', 'explore:projects:starred', 'explore:projects:trending' + Dashboard.init() when 'projects:issues:index' Issues.init() shortcut_handler = new ShortcutsNavigation() diff --git a/app/assets/javascripts/projects_list.js.coffee b/app/assets/javascripts/projects_list.js.coffee index ebf7140b7e3..eab34be652a 100644 --- a/app/assets/javascripts/projects_list.js.coffee +++ b/app/assets/javascripts/projects_list.js.coffee @@ -3,22 +3,24 @@ class @ProjectsList $(".projects-list .js-expand").on 'click', (e) -> e.preventDefault() list = $(this).closest('.projects-list') - list.find("li").show() - list.find("li.bottom").hide() - $(".projects-list-filter").keyup -> - terms = $(this).val() - uiBox = $('div.projects-list-holder') - filterSelector = $(this).data('filter-selector') || 'span.filter-title' + $("#filter_projects").on 'keyup', -> + ProjectsList.filter_results($("#filter_projects")) - if terms == "" || terms == undefined - uiBox.find("ul.projects-list li").show() - else - uiBox.find("ul.projects-list li").each (index) -> - name = $(this).find(filterSelector).text() + @filter_results: ($element) -> + terms = $element.val() + filterSelector = $element.data('filter-selector') || 'span.filter-title' - if name.toLowerCase().search(terms.toLowerCase()) == -1 - $(this).hide() - else - $(this).show() - uiBox.find("ul.projects-list li.bottom").hide() + if not terms + $(".projects-list li").show() + $('.gl-pagination').show() + else + $(".projects-list li").each (index) -> + $this = $(this) + name = $this.find(filterSelector).text() + + if name.toLowerCase().indexOf(terms.toLowerCase()) == -1 + $this.hide() + else + $this.show() + $('.gl-pagination').hide() |