Commit 22808a22 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-explore-filter' into 'master'

Add ajax filtering to all paged project lists. Fixes #13182



See merge request !2728
parents 93d62bb8 cf8a74be
@Dashboard = @Dashboard =
init: -> init: ->
$(".projects-list-filter").off('keyup')
this.initSearch() this.initSearch()
initSearch: -> initSearch: ->
@timer = null @timer = null
$("#project-filter-form-field").on('keyup', -> $(".projects-list-filter").on('keyup', ->
clearTimeout(@timer) clearTimeout(@timer)
@timer = setTimeout(Dashboard.filterResults, 500) @timer = setTimeout(Dashboard.filterResults, 500)
) )
...@@ -13,8 +14,8 @@ ...@@ -13,8 +14,8 @@
$('.projects-list-holder').fadeTo(250, 0.5) $('.projects-list-holder').fadeTo(250, 0.5)
form = null form = null
form = $("#project-filter-form") form = $("form#project-filter-form")
search = $("#project-filter-form-field").val() search = $(".projects-list-filter").val()
project_filter_url = form.attr('action') + '?' + form.serialize() project_filter_url = form.attr('action') + '?' + form.serialize()
$.ajax $.ajax
...@@ -24,7 +25,7 @@ ...@@ -24,7 +25,7 @@
complete: -> complete: ->
$('.projects-list-holder').fadeTo(250, 1) $('.projects-list-holder').fadeTo(250, 1)
success: (data) -> 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 # Change url so if user reload a page - search results are saved
history.replaceState {page: project_filter_url}, document.title, project_filter_url history.replaceState {page: project_filter_url}, document.title, project_filter_url
dataType: "json" dataType: "json"
...@@ -16,6 +16,8 @@ class Dispatcher ...@@ -16,6 +16,8 @@ class Dispatcher
shortcut_handler = null shortcut_handler = null
switch page switch page
when 'explore:projects:index', 'explore:projects:starred', 'explore:projects:trending'
Dashboard.init()
when 'projects:issues:index' when 'projects:issues:index'
Issues.init() Issues.init()
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
......
...@@ -3,22 +3,24 @@ class @ProjectsList ...@@ -3,22 +3,24 @@ class @ProjectsList
$(".projects-list .js-expand").on 'click', (e) -> $(".projects-list .js-expand").on 'click', (e) ->
e.preventDefault() e.preventDefault()
list = $(this).closest('.projects-list') list = $(this).closest('.projects-list')
list.find("li").show()
list.find("li.bottom").hide()
$(".projects-list-filter").keyup -> $("#filter_projects").on 'keyup', ->
terms = $(this).val() ProjectsList.filter_results($("#filter_projects"))
uiBox = $('div.projects-list-holder')
filterSelector = $(this).data('filter-selector') || 'span.filter-title'
if terms == "" || terms == undefined @filter_results: ($element) ->
uiBox.find("ul.projects-list li").show() terms = $element.val()
else filterSelector = $element.data('filter-selector') || 'span.filter-title'
uiBox.find("ul.projects-list li").each (index) ->
name = $(this).find(filterSelector).text()
if name.toLowerCase().search(terms.toLowerCase()) == -1 if not terms
$(this).hide() $(".projects-list li").show()
else $('.gl-pagination').show()
$(this).show() else
uiBox.find("ul.projects-list li.bottom").hide() $(".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()
...@@ -12,7 +12,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -12,7 +12,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@projects = @projects.search(terms) @projects = @projects.search(terms)
end end
@projects = @projects.page(params[:page]).per(PER_PAGE) @projects = @projects.page(params[:page]).per(PER_PAGE) if terms.blank?
@last_push = current_user.recent_push @last_push = current_user.recent_push
respond_to do |format| respond_to do |format|
...@@ -41,7 +41,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -41,7 +41,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@projects = @projects.search(terms) @projects = @projects.search(terms)
end end
@projects = @projects.page(params[:page]).per(PER_PAGE) @projects = @projects.page(params[:page]).per(PER_PAGE) if terms.blank?
@last_push = current_user.recent_push @last_push = current_user.recent_push
@groups = [] @groups = []
......
...@@ -6,19 +6,49 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -6,19 +6,49 @@ class Explore::ProjectsController < Explore::ApplicationController
@projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present? @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
@projects = @projects.non_archived @projects = @projects.non_archived
@projects = @projects.search(params[:search]) if params[:search].present? @projects = @projects.search(params[:search]) if params[:search].present?
@projects = @projects.search(params[:filter_projects]) if params[:filter_projects].present?
@projects = @projects.sort(@sort = params[:sort]) @projects = @projects.sort(@sort = params[:sort])
@projects = @projects.includes(:namespace).page(params[:page]).per(PER_PAGE) @projects = @projects.includes(:namespace).page(params[:page]).per(PER_PAGE) if params[:filter_projects].blank?
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end end
def trending def trending
@projects = TrendingProjectsFinder.new.execute(current_user) @projects = TrendingProjectsFinder.new.execute(current_user)
@projects = @projects.non_archived @projects = @projects.non_archived
@projects = @projects.page(params[:page]).per(PER_PAGE) @projects = @projects.search(params[:filter_projects]) if params[:filter_projects].present?
@projects = @projects.page(params[:page]).per(PER_PAGE) if params[:filter_projects].blank?
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end end
def starred def starred
@projects = ProjectsFinder.new.execute(current_user) @projects = ProjectsFinder.new.execute(current_user)
@projects = @projects.search(params[:filter_projects]) if params[:filter_projects].present?
@projects = @projects.reorder('star_count DESC') @projects = @projects.reorder('star_count DESC')
@projects = @projects.page(params[:page]).per(PER_PAGE) @projects = @projects.page(params[:page]).per(PER_PAGE) if params[:filter_projects].blank?
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end end
end end
...@@ -14,7 +14,7 @@ class GroupsController < Groups::ApplicationController ...@@ -14,7 +14,7 @@ class GroupsController < Groups::ApplicationController
# Load group projects # Load group projects
before_action :load_projects, except: [:index, :new, :create, :projects, :edit, :update, :autocomplete] before_action :load_projects, except: [:index, :new, :create, :projects, :edit, :update, :autocomplete]
before_action :event_filter, only: :show before_action :event_filter, only: [:show, :events]
layout :determine_layout layout :determine_layout
...@@ -41,14 +41,16 @@ class GroupsController < Groups::ApplicationController ...@@ -41,14 +41,16 @@ class GroupsController < Groups::ApplicationController
def show def show
@last_push = current_user.recent_push if current_user @last_push = current_user.recent_push if current_user
@projects = @projects.includes(:namespace) @projects = @projects.includes(:namespace)
@projects = @projects.page(params[:page]).per(PER_PAGE) @projects = @projects.search(params[:filter_projects]) if params[:filter_projects].present?
@projects = @projects.page(params[:page]).per(PER_PAGE) if params[:filter_projects].blank?
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
load_events render json: {
pager_json("events/_events", @events.count) html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end end
format.atom do format.atom do
...@@ -58,6 +60,15 @@ class GroupsController < Groups::ApplicationController ...@@ -58,6 +60,15 @@ class GroupsController < Groups::ApplicationController
end end
end end
def events
respond_to do |format|
format.json do
load_events
pager_json("events/_events", @events.count)
end
end
end
def edit def edit
end end
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
.nav-controls .nav-controls
= form_tag request.original_url, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f| = form_tag request.original_url, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f|
= search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'project-filter-form-field form-control input-short', spellcheck: false, id: 'project-filter-form-field' = search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'project-filter-form-field form-control input-short projects-list-filter', spellcheck: false, id: 'project-filter-form-field'
= render 'explore/projects/dropdown' = render 'explore/projects/dropdown'
- if current_user.can_create_project? - if current_user.can_create_project?
= link_to new_project_path, class: 'btn btn-new' do = link_to new_project_path, class: 'btn btn-new' do
......
.pull-left
= form_tag explore_projects_filter_path, method: :get, class: 'form-inline form-tiny' do |f|
.form-group
= search_field_tag :search, params[:search], placeholder: "Filter by name", class: "form-control search-text-input", id: "projects_search", spellcheck: false
= hidden_field_tag :sort, @sort
.form-group
= button_tag 'Search', class: "btn"
.pull-right.hidden-sm.hidden-xs .pull-right.hidden-sm.hidden-xs
- if current_user - if current_user
.dropdown.inline.append-right-10 .dropdown.inline.append-right-10
......
- if projects.any? - if projects.any?
.public-projects .projects-list-holder
= render 'shared/projects/list', projects: projects = render 'shared/projects/list', projects: projects
- else - else
.nothing-here-block .nothing-here-block
......
.projects-list-holder.prepend-top-default .top-area
.input-group .nav-controls
= search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'projects-list-filter form-control', spellcheck: false = form_tag request.original_url, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f|
- if can? current_user, :create_projects, @group = search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'input-short project-filter-form-field form-control projects-list-filter', spellcheck: false, id: 'project-filter-form-field'
%span.input-group-btn - if current_user && current_user.can_create_project?
= link_to new_project_path(namespace_id: @group.id), class: 'btn btn-new' do = link_to new_project_path, class: 'btn btn-new' do
= icon('plus') = icon('plus')
New Project New Project
.projects-list-holder
= render 'shared/projects/list', projects: @projects, projects_limit: 20, stars: false, skip_namespace: true = render 'shared/projects/list', projects: @projects, projects_limit: 20, stars: false, skip_namespace: true
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
= render 'shared/event_filter' = render 'shared/event_filter'
.content_list .content_list{data: {href: events_group_path}}
= spinner = spinner
.tab-pane#projects .tab-pane#projects
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
== #{pluralize(@all_forks.size, 'fork')}: #{full_count_title} == #{pluralize(@all_forks.size, 'fork')}: #{full_count_title}
.nav-controls .nav-controls
= search_field_tag :filter_projects, nil, placeholder: 'Search forks', class: 'projects-list-filter form-control input-short', = search_field_tag :filter_projects, nil, placeholder: 'Search forks', class: 'projects-list-filter project-filter-form-field form-control input-short',
spellcheck: false, data: { 'filter-selector' => 'span.namespace-name' } spellcheck: false, data: { 'filter-selector' => 'span.namespace-name' }
.dropdown .dropdown
......
...@@ -21,9 +21,10 @@ ...@@ -21,9 +21,10 @@
#{projects_limit} of #{pluralize(projects.count, 'project')} displayed. #{projects_limit} of #{pluralize(projects.count, 'project')} displayed.
= link_to '#', class: 'js-expand' do = link_to '#', class: 'js-expand' do
Show all Show all
= paginate projects, theme: "gitlab" if !projects.kind_of?(Array) = paginate projects, theme: "gitlab" if projects.respond_to? :total_pages
- else - else
%h3 No projects found %h3 No projects found
:javascript :javascript
new ProjectsList(); new ProjectsList();
Dashboard.init();
...@@ -352,6 +352,7 @@ Rails.application.routes.draw do ...@@ -352,6 +352,7 @@ Rails.application.routes.draw do
get :issues get :issues
get :merge_requests get :merge_requests
get :projects get :projects
get :events
end end
scope module: :groups do scope module: :groups 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