Commit 5eecbfdb10f97a216b585e7bddcbbd68f71f6ccc
1 parent
586c53ea
Exists in
master
and in
4 other branches
commit paging fixes
Showing
7 changed files
with
68 additions
and
14 deletions
Show diff stats
app/assets/javascripts/commits.js
| @@ -7,3 +7,51 @@ $(document).ready(function(){ | @@ -7,3 +7,51 @@ $(document).ready(function(){ | ||
| 7 | } | 7 | } |
| 8 | }); | 8 | }); |
| 9 | }); | 9 | }); |
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +var CommitsList = { | ||
| 14 | + | ||
| 15 | +ref:null, | ||
| 16 | +limit:0, | ||
| 17 | +offset:0, | ||
| 18 | + | ||
| 19 | +init: | ||
| 20 | + function(ref, limit) { | ||
| 21 | + this.ref=ref; | ||
| 22 | + this.limit=limit; | ||
| 23 | + this.offset=limit; | ||
| 24 | + this.initLoadMore(); | ||
| 25 | + $('.loading').show(); | ||
| 26 | + }, | ||
| 27 | + | ||
| 28 | +getOld: | ||
| 29 | + function() { | ||
| 30 | + $('.loading').show(); | ||
| 31 | + $.ajax({ | ||
| 32 | + type: "GET", | ||
| 33 | + url: location.href, | ||
| 34 | + data: "limit=" + this.limit + "&offset=" + this.offset + "&ref=" + this.ref, | ||
| 35 | + complete: function(){ $('.loading').hide()}, | ||
| 36 | + dataType: "script"}); | ||
| 37 | + }, | ||
| 38 | + | ||
| 39 | +append: | ||
| 40 | + function(count, html) { | ||
| 41 | + $("#commits_list").append(html); | ||
| 42 | + if(count > 0) { | ||
| 43 | + this.offset += count; | ||
| 44 | + this.initLoadMore(); | ||
| 45 | + } | ||
| 46 | + }, | ||
| 47 | + | ||
| 48 | +initLoadMore: | ||
| 49 | + function() { | ||
| 50 | + $(window).bind('scroll', function(){ | ||
| 51 | + if($(window).scrollTop() == $(document).height() - $(window).height()){ | ||
| 52 | + $(window).unbind('scroll'); | ||
| 53 | + CommitsList.getOld(); | ||
| 54 | + } | ||
| 55 | + }); | ||
| 56 | + } | ||
| 57 | +} |
app/controllers/commits_controller.rb
| @@ -13,11 +13,12 @@ class CommitsController < ApplicationController | @@ -13,11 +13,12 @@ class CommitsController < ApplicationController | ||
| 13 | load_refs # load @branch, @tag & @ref | 13 | load_refs # load @branch, @tag & @ref |
| 14 | 14 | ||
| 15 | @repo = project.repo | 15 | @repo = project.repo |
| 16 | + limit, offset = (params[:limit] || 20), (params[:offset] || 0) | ||
| 16 | 17 | ||
| 17 | if params[:path] | 18 | if params[:path] |
| 18 | - @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) | 19 | + @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset) |
| 19 | else | 20 | else |
| 20 | - @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0) | 21 | + @commits = @repo.commits(@ref, limit, offset) |
| 21 | end | 22 | end |
| 22 | 23 | ||
| 23 | respond_to do |format| | 24 | respond_to do |format| |
app/views/commits/_commits.html.haml
app/views/commits/index.html.haml
| @@ -15,4 +15,14 @@ | @@ -15,4 +15,14 @@ | ||
| 15 | .right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) } | 15 | .right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) } |
| 16 | 16 | ||
| 17 | %div{:id => dom_id(@project)} | 17 | %div{:id => dom_id(@project)} |
| 18 | - = render "commits" | 18 | + #commits_list= render "commits" |
| 19 | +.clear | ||
| 20 | +.loading{ :style => "display:none;"} | ||
| 21 | + %center= image_tag "ajax-loader.gif" | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +:javascript | ||
| 26 | + $(function(){ | ||
| 27 | + CommitsList.init("#{@ref}", 20); | ||
| 28 | + }); |
app/views/commits/index.js.erb
app/views/layouts/application.html.haml
| @@ -2,11 +2,7 @@ | @@ -2,11 +2,7 @@ | ||
| 2 | %html | 2 | %html |
| 3 | %head | 3 | %head |
| 4 | %title | 4 | %title |
| 5 | - GitLab #{" - #{@project.name}" if @project && !@project.new_record?} | ||
| 6 | - -#= stylesheet_link_tag 'blueprint/screen', :media => "screen, projection" | ||
| 7 | - -#= stylesheet_link_tag 'blueprint/print', :media => "print" | ||
| 8 | - -#= stylesheet_link_tag 'blueprint/plugins/buttons/screen', :media => "screen, projection" | ||
| 9 | - -#= stylesheet_link_tag 'blueprint/plugins/link-icons/screen', :media => "screen, projection" | 5 | + GitLab |
| 10 | = stylesheet_link_tag "application" | 6 | = stylesheet_link_tag "application" |
| 11 | = javascript_include_tag "application" | 7 | = javascript_include_tag "application" |
| 12 | = csrf_meta_tags | 8 | = csrf_meta_tags |
| @@ -17,6 +13,5 @@ | @@ -17,6 +13,5 @@ | ||
| 17 | #container | 13 | #container |
| 18 | = render :partial => "layouts/flash" | 14 | = render :partial => "layouts/flash" |
| 19 | = render :partial => "layouts/head_panel" | 15 | = render :partial => "layouts/head_panel" |
| 20 | - %div{ :id => "main", :role => "main", :class => "container_4" } | ||
| 21 | - = render :partial => "layouts/page_title" | ||
| 22 | - = yield | 16 | + = render :partial => "layouts/page_title" |
| 17 | + = yield |