From 5eecbfdb10f97a216b585e7bddcbbd68f71f6ccc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Nov 2011 14:26:06 +0200 Subject: [PATCH] commit paging fixes --- app/assets/javascripts/commits.js | 48 +++++++++++++++++++++++++ app/controllers/commits_controller.rb | 5 +-- app/views/commits/_commits.html.haml | 1 - app/views/commits/index.html.haml | 12 ++++++- app/views/commits/index.js.erb | 2 -- app/views/commits/index.js.haml | 3 ++ app/views/layouts/application.html.haml | 11 ++---- 7 files changed, 68 insertions(+), 14 deletions(-) delete mode 100644 app/views/commits/index.js.erb create mode 100644 app/views/commits/index.js.haml diff --git a/app/assets/javascripts/commits.js b/app/assets/javascripts/commits.js index a62e9330..bef7ed74 100644 --- a/app/assets/javascripts/commits.js +++ b/app/assets/javascripts/commits.js @@ -7,3 +7,51 @@ $(document).ready(function(){ } }); }); + + + +var CommitsList = { + +ref:null, +limit:0, +offset:0, + +init: + function(ref, limit) { + this.ref=ref; + this.limit=limit; + this.offset=limit; + this.initLoadMore(); + $('.loading').show(); + }, + +getOld: + function() { + $('.loading').show(); + $.ajax({ + type: "GET", + url: location.href, + data: "limit=" + this.limit + "&offset=" + this.offset + "&ref=" + this.ref, + complete: function(){ $('.loading').hide()}, + dataType: "script"}); + }, + +append: + function(count, html) { + $("#commits_list").append(html); + if(count > 0) { + this.offset += count; + this.initLoadMore(); + } + }, + +initLoadMore: + function() { + $(window).bind('scroll', function(){ + if($(window).scrollTop() == $(document).height() - $(window).height()){ + $(window).unbind('scroll'); + CommitsList.getOld(); + } + }); + } +} diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index fa0d0b57..79703cf1 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -13,11 +13,12 @@ class CommitsController < ApplicationController load_refs # load @branch, @tag & @ref @repo = project.repo + limit, offset = (params[:limit] || 20), (params[:offset] || 0) if params[:path] - @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) + @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset) else - @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0) + @commits = @repo.commits(@ref, limit, offset) end respond_to do |format| diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml index 9761c65f..2d393993 100644 --- a/app/views/commits/_commits.html.haml +++ b/app/views/commits/_commits.html.haml @@ -22,4 +22,3 @@ %strong= commit.author_name = time_ago_in_words(commit.committed_date) ago -= more_commits_link if @commits.size > 99 diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index b9650145..0dfb2cff 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -15,4 +15,14 @@ .right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) } %div{:id => dom_id(@project)} - = render "commits" + #commits_list= render "commits" +.clear +.loading{ :style => "display:none;"} + %center= image_tag "ajax-loader.gif" + + + +:javascript + $(function(){ + CommitsList.init("#{@ref}", 20); + }); diff --git a/app/views/commits/index.js.erb b/app/views/commits/index.js.erb deleted file mode 100644 index 94daa396..00000000 --- a/app/views/commits/index.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$("#more-commits-link").remove(); -$('#<%= dom_id(@project)%>').append('<%= escape_javascript(render("commits")) %>'); diff --git a/app/views/commits/index.js.haml b/app/views/commits/index.js.haml new file mode 100644 index 00000000..39b7108c --- /dev/null +++ b/app/views/commits/index.js.haml @@ -0,0 +1,3 @@ +:plain + CommitsList.append(#{@commits.count}, "#{escape_javascript(render(:partial => 'commits/commits'))}"); + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 030f1999..9022ecb1 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,11 +2,7 @@ %html %head %title - GitLab #{" - #{@project.name}" if @project && !@project.new_record?} - -#= stylesheet_link_tag 'blueprint/screen', :media => "screen, projection" - -#= stylesheet_link_tag 'blueprint/print', :media => "print" - -#= stylesheet_link_tag 'blueprint/plugins/buttons/screen', :media => "screen, projection" - -#= stylesheet_link_tag 'blueprint/plugins/link-icons/screen', :media => "screen, projection" + GitLab = stylesheet_link_tag "application" = javascript_include_tag "application" = csrf_meta_tags @@ -17,6 +13,5 @@ #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" - %div{ :id => "main", :role => "main", :class => "container_4" } - = render :partial => "layouts/page_title" - = yield + = render :partial => "layouts/page_title" + = yield