mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-04-01 23:49:11 +02:00
added pagination! (at least on the timeline)
This commit is contained in:
parent
6c4bff5346
commit
c279026ce0
5 changed files with 42 additions and 2 deletions
app
assets/javascripts
controllers
views/static
15
app/assets/javascripts/pagination.coffee
Normal file
15
app/assets/javascripts/pagination.coffee
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
jQuery ->
|
||||||
|
if $('#pagination').size() > 0
|
||||||
|
$('#pagination').hide()
|
||||||
|
loading_posts = false
|
||||||
|
|
||||||
|
$('#load-more-btn').show().click ->
|
||||||
|
unless loading_posts
|
||||||
|
loading_posts = true
|
||||||
|
more_posts_url = $('#pagination .pagination .next a').attr('href')
|
||||||
|
$this = $(this)
|
||||||
|
$this.html('<i class="fa fa-spinner fa-spin"></i>').addClass('disabled')
|
||||||
|
$.getScript more_posts_url, ->
|
||||||
|
$this.text('Load more').removeClass('disabled') if $this
|
||||||
|
loading_posts = false
|
||||||
|
return
|
|
@ -12,6 +12,7 @@ class Ajax::AnswerController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
answer.user.decrement! :answered_count
|
answer.user.decrement! :answered_count
|
||||||
|
answer.question.decrement! :answer_count
|
||||||
if answer.user == current_user
|
if answer.user == current_user
|
||||||
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
||||||
end # TODO: decide what happens with the question
|
end # TODO: decide what happens with the question
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
class StaticController < ApplicationController
|
class StaticController < ApplicationController
|
||||||
def index
|
def index
|
||||||
|
if user_signed_in?
|
||||||
|
@timeline = current_user.timeline.paginate(page: params[:page])
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def about
|
def about
|
||||||
|
|
|
@ -36,8 +36,15 @@
|
||||||
.col-md-9.col-xs-12.col-sm-9
|
.col-md-9.col-xs-12.col-sm-9
|
||||||
= render 'layouts/messages'
|
= render 'layouts/messages'
|
||||||
|
|
||||||
- current_user.timeline.each do |answer|
|
#timeline
|
||||||
|
- @timeline.each do |answer|
|
||||||
= render 'shared/answerbox', a: answer
|
= render 'shared/answerbox', a: answer
|
||||||
|
|
||||||
|
#pagination= will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false
|
||||||
|
|
||||||
|
- if @timeline.next_page
|
||||||
|
%button#load-more-btn.btn.btn-default{type: :button, 'data-current-page' => @timeline.current_page, 'data-type' => 'timeline'}
|
||||||
|
Load more
|
||||||
= render "shared/links"
|
= render "shared/links"
|
||||||
- else
|
- else
|
||||||
.jumbotron
|
.jumbotron
|
||||||
|
|
10
app/views/static/index.js.erb
Normal file
10
app/views/static/index.js.erb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
$('#timeline').append('<% @timeline.each do |answer|
|
||||||
|
%><%= j render 'shared/answerbox', a: answer
|
||||||
|
%><% end %>');
|
||||||
|
<% if @timeline.next_page %>
|
||||||
|
var _p = $('#pagination');
|
||||||
|
_p.replaceWith('<%= j will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false %>');
|
||||||
|
_p.hide();
|
||||||
|
<% else %>
|
||||||
|
$('#pagination, #load-more-btn').remove();
|
||||||
|
<% end %>
|
Loading…
Reference in a new issue