Commit 33aea41708b94f480b6eaad760e26abe17a37dfa
1 parent
70c2e1d7
Exists in
master
and in
4 other branches
Drop rjs from Infinite scrolling
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
12 changed files
with
30 additions
and
21 deletions
Show diff stats
app/assets/javascripts/commits.js.coffee
| ... | ... | @@ -4,13 +4,13 @@ class CommitsList |
| 4 | 4 | limit: 0 |
| 5 | 5 | offset: 0 |
| 6 | 6 | @disable = false |
| 7 | - | |
| 7 | + | |
| 8 | 8 | @showProgress: -> |
| 9 | 9 | $('.loading').show() |
| 10 | - | |
| 10 | + | |
| 11 | 11 | @hideProgress: -> |
| 12 | 12 | $('.loading').hide() |
| 13 | - | |
| 13 | + | |
| 14 | 14 | @init: (ref, limit) -> |
| 15 | 15 | $(".day-commits-table li.commit").live 'click', (event) -> |
| 16 | 16 | if event.target.nodeName != "A" |
| ... | ... | @@ -21,7 +21,7 @@ class CommitsList |
| 21 | 21 | @data.ref = ref |
| 22 | 22 | @data.limit = limit |
| 23 | 23 | @data.offset = limit |
| 24 | - | |
| 24 | + | |
| 25 | 25 | this.initLoadMore() |
| 26 | 26 | this.showProgress() |
| 27 | 27 | |
| ... | ... | @@ -32,7 +32,9 @@ class CommitsList |
| 32 | 32 | url: location.href |
| 33 | 33 | data: @data |
| 34 | 34 | complete: this.hideProgress |
| 35 | - dataType: "script" | |
| 35 | + success: (data) -> | |
| 36 | + CommitsList.append(data.count, data.html) | |
| 37 | + dataType: "json" | |
| 36 | 38 | |
| 37 | 39 | @append: (count, html) -> |
| 38 | 40 | $("#commits-list").append(html) |
| ... | ... | @@ -40,7 +42,7 @@ class CommitsList |
| 40 | 42 | @data.offset += count |
| 41 | 43 | else |
| 42 | 44 | @disable = true |
| 43 | - | |
| 45 | + | |
| 44 | 46 | @initLoadMore: -> |
| 45 | 47 | $(document).unbind('scroll') |
| 46 | 48 | $(document).endlessScroll | ... | ... |
app/assets/javascripts/pager.js.coffee
| ... | ... | @@ -19,8 +19,9 @@ |
| 19 | 19 | data: "limit=" + @limit + "&offset=" + @offset |
| 20 | 20 | complete: -> |
| 21 | 21 | $(".loading").hide() |
| 22 | - | |
| 23 | - dataType: "script" | |
| 22 | + success: (data) -> | |
| 23 | + Pager.append(data.count, data.html) | |
| 24 | + dataType: "json" | |
| 24 | 25 | |
| 25 | 26 | append: (count, html) -> |
| 26 | 27 | $(".content_list").append html | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -174,4 +174,18 @@ class ApplicationController < ActionController::Base |
| 174 | 174 | filters = cookies['event_filter'].split(',') if cookies['event_filter'].present? |
| 175 | 175 | @event_filter ||= EventFilter.new(filters) |
| 176 | 176 | end |
| 177 | + | |
| 178 | + # JSON for infinite scroll via Pager object | |
| 179 | + def pager_json(partial, count) | |
| 180 | + html = render_to_string( | |
| 181 | + partial, | |
| 182 | + layout: false, | |
| 183 | + formats: [:html] | |
| 184 | + ) | |
| 185 | + | |
| 186 | + render json: { | |
| 187 | + html: html, | |
| 188 | + count: count | |
| 189 | + } | |
| 190 | + end | |
| 177 | 191 | end | ... | ... |
app/controllers/dashboard_controller.rb
app/controllers/groups_controller.rb
app/controllers/projects/commits_controller.rb
| ... | ... | @@ -16,7 +16,7 @@ class Projects::CommitsController < Projects::ApplicationController |
| 16 | 16 | |
| 17 | 17 | respond_to do |format| |
| 18 | 18 | format.html # index.html.erb |
| 19 | - format.js | |
| 19 | + format.json { pager_json("projects/commits/_commits", @commits.size) } | |
| 20 | 20 | format.atom { render layout: false } |
| 21 | 21 | end |
| 22 | 22 | end | ... | ... |
app/controllers/projects_controller.rb
app/views/dashboard/show.js.haml
| ... | ... | @@ -0,0 +1 @@ |
| 1 | += render @events | ... | ... |
app/views/groups/show.js.haml
app/views/projects/commits/show.js.haml
app/views/projects/show.js.haml