pagination update

This commit is contained in:
Andreas Stephanides
2014-09-24 14:39:59 +02:00
parent fc48959e48
commit a8dd419f9e
17 changed files with 109 additions and 57 deletions

View File

@@ -103,6 +103,7 @@ gem 'themes_for_rails'
gem 'rubyzip'
gem 'acts_as_votable'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'kaminari'
gem 'bootstrap-kaminari-views', :git=>'git://github.com/matenia/bootstrap-kaminari-views.git'
#gem 'will_paginate', :git=>'git://github.com/mislav/will_paginate.git'
#gem 'bootstrap-will_paginate'

View File

@@ -1,4 +1,5 @@
$ ->
if $('#infinite-scrolling').size() > 0
more_posts_url = $('.pagination .next_page a').attr('href')

View File

@@ -18,7 +18,7 @@ class BeispieleController < ApplicationController
# @lva = params([:lva]) unless params([:lva]).nil?
@beispiel = Beispiel.find(params[:id])
respond_to do |format|
format.html { redirect_to @beispiel.lva }
format.html { redirect_to lva_path(@beispiel.lva , show_comments: params[:show_comments])}
format.js
end
end

View File

@@ -1,10 +1,25 @@
class CommentsController < ApplicationController
def index
@comments=Comment.all
@commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
@comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(2).reverse_order
respond_to do |format|
format.html # new.html.erb
format.json { render json: @comment }
format.js
end
end
def hide
@commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
respond_to do |format|
format.js
end
end
def show
@comment = Comment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @comment }
@@ -33,15 +48,9 @@ class CommentsController < ApplicationController
c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil?
@comment = Comment.build_for(c, current_user,"", params_new)
#raise @comment.to_yaml.to_s
# @comment.commentable= c
respond_to do |format|
if @comment
format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.' }
format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.', show_comments: true }
format.json { render json: @comment, status: :created, location: @comment }
else
format.html { render action: "new" }
@@ -73,11 +82,13 @@ class CommentsController < ApplicationController
# DELETE /comments/1.json
def destroy
@comment = Comment.find(params[:id])
@commentable=@comment.commentable
@comment.destroy
respond_to do |format|
format.html { redirect_to comments_url }
format.html { redirect_to @commentable, :action=>"show"}
format.json { head :no_content }
end
end
end

View File

@@ -4,10 +4,10 @@ class RubrikenController < ApplicationController
def index
if can?(:showintern, Rubrik)
@rubriken = Rubrik.all
@neuigkeiten = Neuigkeit.paginate(page: params[:page], per_page:3)
@neuigkeiten = Neuigkeit.page(params[:page]).per(3)
else
@rubriken = Rubrik.where(:public=>true)
@neuigkeiten = Neuigkeit.public.published.paginate(page: params[:page], per_page:3)
@neuigkeiten = Neuigkeit.public.published.page(params[:page]).per(3)
end
@calentries= @rubriken.collect(&:calentries).flatten
@@ -31,9 +31,9 @@ class RubrikenController < ApplicationController
@moderatoren=User.with_role(:newsmoderator,@rubrik)
@calentries= @rubrik.calentries
if can?(:showunpublished, Neuigkeit)
@neuigkeiten = @rubrik.neuigkeiten.paginate(page: params[:page], per_page:3)
@neuigkeiten = @rubrik.neuigkeiten.page(params[:page]).per(3)
else
@neuigkeiten = @rubrik.neuigkeiten.published.paginate(page: params[:page], per_page:3)
@neuigkeiten = @rubrik.neuigkeiten.published..page(params[:page]).per(3)
end
@toolbar_elements << {:text=>I18n.t('neuigkeit.new.title'), :path=> new_rubrik_neuigkeit_path(@rubrik),:hicon=>'icon-plus-sign'} if can? :verwalten, @rubrik
@toolbar_elements << {:text=>I18n.t('common.verwalten'), :path=>verwalten_rubrik_path(@rubrik),:icon=>:pencil} if can? :verwalten, @rubrik

View File

@@ -18,6 +18,11 @@ class ThemenController < ApplicationController
format.js
end
end
def sanitize
@thema = Thema.find(params[:id])
@fragen=@thema.fragen
end
def verwalten
@thema = Thema.find(params[:id])
@attachment=Attachment.new

View File

@@ -32,6 +32,13 @@ class Comment < ActiveRecord::Base
t_url= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil?
t_url
end
def self.wrapid_for(c)
"comments_" + c.class.to_s + "_" + c.id.to_s
end
def self.switchshowid_for(c)
"show_comments_" + c.class.to_s + "_" + c.id.to_s
end
def divid
"comment_" + id.to_s
end

View File

@@ -5,7 +5,8 @@
<b><%=link_to ffi1_icon("note20")+" " + beispiel.name, beispiel.beispieldatei.url, title: beispiel.desc %></b>
<%= I18n.t("file.size") + ": " + (beispiel.beispieldatei.size/1024.0).round(2).to_s %>KiB <br>
<span class="linklist"><%=
<span class="linklist">
<%=
if can?(:like, beispiel)
link_to ffi1_icon("like3")+" like" + "("+beispiel.get_likes.size.to_s+")", like_beispiel_path(beispiel),title: "liked by " + ((current_user.liked?(beispiel)) ? ("you and " + ((beispiel.get_likes.size - 1).to_s + " others")) : beispiel.get_likes.size.to_s), remote: true
else
@@ -24,18 +25,26 @@ end
<%= link_to ff_icon("icon-pencil")+" edit", edit_beispiel_path(beispiel) if can? :edit, beispiel%>
<%= link_to ff_icon("icon-remove")+" delete", beispiel_path(beispiel), :method=>:delete, :data=>{:confirm=>I18n.t('beispiel.sure')} if can? :delete, beispiel %>
<%= link_to "Refresh", beispiel, remote: true %></br>
<%= link_to "Refres1h", beispiel_path(beispiel,show_comments: true), remote: true %></br>
</span>
</div>
<div class="span4">
<%= beispiel.desc %>
</div>
</div>
<%= link_to "comment" , new_comment_path( commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true if can? :comment, beispiel %>
<%= link_to "comments:.."+beispiel.comments.count().to_s, comments_path(commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true, id: Comment.switchshowid_for(beispiel) %>
<div id="<%= Comment.formid_for(beispiel) %>">
</div>
<% unless beispiel.comments.roots.empty? %>
<div class="row-fluid"><div class="span12"><%= render partial:"comments/comments", object: beispiel.comments.order(:created_at).roots.reverse_order %></div></div>
<div class="row-fluid">
<div class="span12">
<div id="<%= Comment.wrapid_for(beispiel)%>">
<%= render partial:"comments/comments", object: beispiel.comments.order(:created_at).roots.reverse_order if params[:show_comments] %>
</div>
</div>
</div>
<% end %>
</div>

View File

@@ -1,17 +1,19 @@
<div id="<%= comment.divid %>">
<a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a>
<div class="media-body">
<b><%= comment.user.try(:email) %></b> (<%= I18n.l(comment.created_at) %>):
<b><%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %></b> (<%= I18n.l(comment.created_at) %>) <%= link_to ffi1_icon("remove9"), comment, method: :delete, data: { confirm: 'Are you sure?' } %>:
<p><%= comment.text %>
<% if can?(:comment, comment.commentable) %>
<br><%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %>
<% end %>
</p>
<div id="<%= Comment.formid_for(comment) %>">
</div>
<%= render partial:"comments/comments", object: comment.children.order(:created_at).reverse_order if comment.children.size >0 %>
</div>
<div id="<%= Comment.formid_for(comment) %>">
</div>
</div>

View File

@@ -6,4 +6,7 @@
<% end %>
</ul>
</div>
<% if comments.first.root? %>
<%= paginate comments, :remote=>true , :theme=>'twitter-bootstrap'%>
<% end %>
<% end %>

View File

@@ -0,0 +1,3 @@
$("#<%= Comment.wrapid_for(@commentable) %>").html("<%= escape_javascript "" %>")
$("#<%= Comment.switchshowid_for(@commentable) %>").attr("href","<%= escape_javascript comments_path(commentable_type: @commentable.class.to_s, commentable_id: @commentable.id) %>")

View File

@@ -1,4 +1,5 @@
<h1>Listing comments</h1>
<%= render partial:"comments/comments", object: @comments %>
<table>
<tr>

View File

@@ -0,0 +1,2 @@
$("#<%= Comment.wrapid_for(@commentable) %>").html("<%= escape_javascript render partial:"comments/comments", object: @comments %>")
$("#<%= Comment.switchshowid_for(@commentable) %>").attr("href","<%= escape_javascript hide_comments_path(commentable_type: @commentable.class.to_s, commentable_id: @commentable.id) %>")

View File

@@ -21,7 +21,7 @@
<% end %>
</ul>
<div id="infinite-scrolling">
<%= will_paginate @neuigkeiten %>
<%= paginate @neuigkeiten, theme:'twitter-bootstrap' %>
</div>
</div>

View File

@@ -32,7 +32,9 @@
</ul>
<div id="infinite-scrolling">
<%= will_paginate @neuigkeiten %>
<%= paginate @neuigkeiten, theme:'twitter-bootstrap' %>
</div>
</div>
<div class="span3">

View File

@@ -1,6 +1,6 @@
$('#neuigkeiten').append('<%= j render @neuigkeiten, :wrap_in => :li %>');
<% if @neuigkeiten.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @neuigkeiten %>');
$('.pagination').replaceWith('<%= j paginate @neuigkeiten, theme: 'twitter-bootstrap' %>');
<% else %>
$(window).off('scroll');
$('.pagination').remove();

View File

@@ -132,7 +132,11 @@ Fetsite::Application.routes.draw do
end
end
end
resources :comments
resources :comments do
collection do
get 'hide'
end
end
resources :home, :only=>[:index] do
get :search, :on => :collection
collection do
@@ -160,6 +164,7 @@ Fetsite::Application.routes.draw do
get :attachments
get :fragen
get :verwalten
get :sanitize
end
resources :attachments
end