Commit 9bf85c01 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'paginate-dashboard-projects' into 'master'

Page project list on dashboard



See merge request !2689
parents 0c449e36 f1102b33
class @Dashboard @Dashboard =
constructor: -> init: ->
new ProjectsList() this.initSearch()
initSearch: ->
@timer = null
$("#project-filter-form-field").on('keyup', ->
clearTimeout(@timer)
@timer = setTimeout(Dashboard.filterResults, 500)
)
filterResults: =>
$('.projects-list-holder').fadeTo(250, 0.5)
form = null
form = $("#project-filter-form")
search = $("#project-filter-form-field").val()
project_filter_url = form.attr('action') + '?' + form.serialize()
$.ajax
type: "GET"
url: form.attr('action')
data: form.serialize()
complete: ->
$('.projects-list-holder').fadeTo(250, 1)
success: (data) ->
$('div.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"
...@@ -58,7 +58,7 @@ class Dispatcher ...@@ -58,7 +58,7 @@ class Dispatcher
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
MergeRequests.init() MergeRequests.init()
when 'dashboard:show', 'root:show' when 'dashboard:show', 'root:show'
new Dashboard() Dashboard.init()
when 'dashboard:activity' when 'dashboard:activity'
new Activities() new Activities()
when 'dashboard:projects:starred' when 'dashboard:projects:starred'
......
...@@ -22,5 +22,3 @@ class @ProjectsList ...@@ -22,5 +22,3 @@ class @ProjectsList
else else
$(this).show() $(this).show()
uiBox.find("ul.projects-list li.bottom").hide() uiBox.find("ul.projects-list li.bottom").hide()
...@@ -277,9 +277,10 @@ class ApplicationController < ActionController::Base ...@@ -277,9 +277,10 @@ class ApplicationController < ActionController::Base
} }
end end
def view_to_html_string(partial) def view_to_html_string(partial, locals = {})
render_to_string( render_to_string(
partial, partial,
locals: locals,
layout: false, layout: false,
formats: [:html] formats: [:html]
) )
......
...@@ -5,6 +5,14 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -5,6 +5,14 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@projects = current_user.authorized_projects.sorted_by_activity.non_archived @projects = current_user.authorized_projects.sorted_by_activity.non_archived
@projects = @projects.sort(@sort = params[:sort]) @projects = @projects.sort(@sort = params[:sort])
@projects = @projects.includes(:namespace) @projects = @projects.includes(:namespace)
terms = params['filter_projects']
if terms.present?
@projects = @projects.search(terms)
end
@projects = @projects.page(params[:page]).per(PER_PAGE)
@last_push = current_user.recent_push @last_push = current_user.recent_push
respond_to do |format| respond_to do |format|
...@@ -14,6 +22,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -14,6 +22,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
load_events load_events
render layout: false render layout: false
end end
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end end
end end
...@@ -21,6 +34,14 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -21,6 +34,14 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@projects = current_user.starred_projects @projects = current_user.starred_projects
@projects = @projects.includes(:namespace, :forked_from_project, :tags) @projects = @projects.includes(:namespace, :forked_from_project, :tags)
@projects = @projects.sort(@sort = params[:sort]) @projects = @projects.sort(@sort = params[:sort])
terms = params['filter_projects']
if terms.present?
@projects = @projects.search(terms)
end
@projects = @projects.page(params[:page]).per(PER_PAGE)
@last_push = current_user.recent_push @last_push = current_user.recent_push
@groups = [] @groups = []
...@@ -28,8 +49,9 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -28,8 +49,9 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
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
end end
end end
......
...@@ -11,14 +11,14 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -11,14 +11,14 @@ class Explore::ProjectsController < Explore::ApplicationController
end end
def trending def trending
@trending_projects = TrendingProjectsFinder.new.execute(current_user) @projects = TrendingProjectsFinder.new.execute(current_user)
@trending_projects = @trending_projects.non_archived @projects = @projects.non_archived
@trending_projects = @trending_projects.page(params[:page]).per(PER_PAGE) @projects = @projects.page(params[:page]).per(PER_PAGE)
end end
def starred def starred
@starred_projects = ProjectsFinder.new.execute(current_user) @projects = ProjectsFinder.new.execute(current_user)
@starred_projects = @starred_projects.reorder('star_count DESC') @projects = @projects.reorder('star_count DESC')
@starred_projects = @starred_projects.page(params[:page]).per(PER_PAGE) @projects = @projects.page(params[:page]).per(PER_PAGE)
end end
end end
...@@ -41,6 +41,7 @@ class GroupsController < Groups::ApplicationController ...@@ -41,6 +41,7 @@ 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)
respond_to do |format| respond_to do |format|
format.html format.html
......
...@@ -4,8 +4,9 @@ class UsersController < ApplicationController ...@@ -4,8 +4,9 @@ class UsersController < ApplicationController
def show def show
@contributed_projects = contributed_projects.joined(@user).reject(&:forked?) @contributed_projects = contributed_projects.joined(@user).reject(&:forked?)
@projects = PersonalProjectsFinder.new(@user).execute(current_user) @projects = PersonalProjectsFinder.new(@user).execute(current_user)
@projects = @projects.page(params[:page]).per(PER_PAGE)
@groups = @user.groups.order_id_desc @groups = @user.groups.order_id_desc
......
...@@ -49,7 +49,7 @@ class Event < ActiveRecord::Base ...@@ -49,7 +49,7 @@ class Event < ActiveRecord::Base
scope :code_push, -> { where(action: PUSHED) } scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(projects) do scope :in_projects, ->(projects) do
where(project_id: projects.select(:id).reorder(nil)).recent where(project_id: projects.map(&:id)).recent
end end
scope :with_associations, -> { includes(project: :namespace) } scope :with_associations, -> { includes(project: :namespace) }
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
Explore Projects Explore Projects
.nav-controls .nav-controls
= search_field_tag :filter_projects, nil, placeholder: 'Filter by name...', class: 'projects-list-filter form-control hidden-xs input-short', spellcheck: false = 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'
= 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
......
.projects-list-holder .projects-list-holder
= render 'shared/projects/list', projects: @projects, ci: true = render 'shared/projects/list', projects: @projects, ci: true
:javascript
Dashboard.init()
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
= render 'explore/head' = render 'explore/head'
= render 'explore/projects/nav' = render 'explore/projects/nav'
= render 'projects', projects: @starred_projects = render 'projects', projects: @projects
= paginate @starred_projects, theme: 'gitlab' = paginate @projects, theme: 'gitlab' if @projects
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
= render 'explore/head' = render 'explore/head'
= render 'explore/projects/nav' = render 'explore/projects/nav'
= render 'projects', projects: @trending_projects = render 'projects', projects: @projects
...@@ -4,7 +4,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear ...@@ -4,7 +4,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear
xml.link href: namespace_project_url(@project.namespace, @project, format: :atom, private_token: current_user.try(:private_token)), rel: "self", type: "application/atom+xml" xml.link href: namespace_project_url(@project.namespace, @project, format: :atom, private_token: current_user.try(:private_token)), rel: "self", type: "application/atom+xml"
xml.link href: namespace_project_url(@project.namespace, @project), rel: "alternate", type: "text/html" xml.link href: namespace_project_url(@project.namespace, @project), rel: "alternate", type: "text/html"
xml.id namespace_project_url(@project.namespace, @project) xml.id namespace_project_url(@project.namespace, @project)
xml.updated @events[0].updated_at.xmlschema if @events[0? xml.updated @events[0].updated_at.xmlschema if @events[0]
@events.each do |event| @events.each do |event|
event_to_atom(xml, event) event_to_atom(xml, event)
......
...@@ -8,18 +8,22 @@ ...@@ -8,18 +8,22 @@
- show_last_commit_as_description = false unless local_assigns[:show_last_commit_as_description] == true - show_last_commit_as_description = false unless local_assigns[:show_last_commit_as_description] == true
%ul.projects-list %ul.projects-list
- projects.each_with_index do |project, i| - if projects.any?
- css_class = (i >= projects_limit) ? 'hide' : nil - projects.each_with_index do |project, i|
= render "shared/projects/project", project: project, skip_namespace: skip_namespace, - css_class = (i >= projects_limit) ? 'hide' : nil
avatar: avatar, stars: stars, css_class: css_class, ci: ci, use_creator_avatar: use_creator_avatar, = render "shared/projects/project", project: project, skip_namespace: skip_namespace,
forks: forks, show_last_commit_as_description: show_last_commit_as_description avatar: avatar, stars: stars, css_class: css_class, ci: ci, use_creator_avatar: use_creator_avatar,
forks: forks, show_last_commit_as_description: show_last_commit_as_description
- if projects.size > projects_limit - if projects.size > projects_limit && projects.kind_of?(Array)
%li.bottom.center %li.bottom.center
.light .light
#{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)
- else
%h3 No projects found
:javascript :javascript
new ProjectsList(); new ProjectsList();
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