Commit 5eecbfdb10f97a216b585e7bddcbbd68f71f6ccc

Authored by Dmitriy Zaporozhets
1 parent 586c53ea

commit paging fixes

app/assets/javascripts/commits.js
... ... @@ -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 13 load_refs # load @branch, @tag & @ref
14 14  
15 15 @repo = project.repo
  16 + limit, offset = (params[:limit] || 20), (params[:offset] || 0)
16 17  
17 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 20 else
20   - @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0)
  21 + @commits = @repo.commits(@ref, limit, offset)
21 22 end
22 23  
23 24 respond_to do |format|
... ...
app/views/commits/_commits.html.haml
... ... @@ -22,4 +22,3 @@
22 22 %strong= commit.author_name
23 23 = time_ago_in_words(commit.committed_date)
24 24 ago
25   -= more_commits_link if @commits.size > 99
... ...
app/views/commits/index.html.haml
... ... @@ -15,4 +15,14 @@
15 15 .right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) }
16 16  
17 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
... ... @@ -1,2 +0,0 @@
1   -$("#more-commits-link").remove();
2   -$('#<%= dom_id(@project)%>').append('<%= escape_javascript(render("commits")) %>');
app/views/commits/index.js.haml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +:plain
  2 + CommitsList.append(#{@commits.count}, "#{escape_javascript(render(:partial => 'commits/commits'))}");
  3 +
... ...
app/views/layouts/application.html.haml
... ... @@ -2,11 +2,7 @@
2 2 %html
3 3 %head
4 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 6 = stylesheet_link_tag "application"
11 7 = javascript_include_tag "application"
12 8 = csrf_meta_tags
... ... @@ -17,6 +13,5 @@
17 13 #container
18 14 = render :partial => "layouts/flash"
19 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
... ...