diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-05-19 16:34:03 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-05-19 17:42:24 +0300 |
commit | fec88acd3fcc386eb934d9f59b227c784ddda456 (patch) | |
tree | db50b6404501d227d895fb217ad056d2007c6ced /app/controllers | |
parent | 133706525871ee68af978d6aadc18f85b68edfaf (diff) | |
download | gitlab-ci-fec88acd3fcc386eb934d9f59b227c784ddda456.tar.gz |
basic implementation of endless scroll on dashboard
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 15 |
2 files changed, 25 insertions, 4 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 316fd63..9852736 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -88,6 +88,20 @@ class ApplicationController < ActionController::Base headers['X-XSS-Protection'] = '1; mode=block' end + # JSON for infinite scroll via Pager object + def pager_json(partial, count) + html = render_to_string( + partial, + layout: false, + formats: [:html] + ) + + render json: { + html: html, + count: count + } + end + def check_config redirect_to oauth2_help_path unless valid_config? end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7051045..def84fd 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,5 +1,5 @@ class ProjectsController < ApplicationController - PROJECTS_PER_PAGE = 100 + PROJECTS_BATCH = 10 before_filter :authenticate_user!, except: [:build, :badge, :index, :show] before_filter :authenticate_public_page!, only: :show @@ -17,13 +17,20 @@ class ProjectsController < ApplicationController end def gitlab + @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i + @page = @offset == 0 ? 1 : (@offset / @limit + 1) + current_user.reset_cache if params[:reset_cache] - @page = (params[:page] || 1).to_i - @per_page = PROJECTS_PER_PAGE - @gl_projects = current_user.gitlab_projects(params[:search], @page, @per_page) + + @gl_projects = current_user.gitlab_projects(params[:search], @page, @limit) @projects = Project.where(gitlab_id: @gl_projects.map(&:id)).ordered_by_last_commit_date @total_count = @gl_projects.size @gl_projects.reject! { |gl_project| @projects.map(&:gitlab_id).include?(gl_project.id) } + respond_to do |format| + format.json do + pager_json("projects/gitlab", @total_count) + end + end rescue Network::UnauthorizedError raise rescue |