pagination update

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

View File

@@ -103,6 +103,7 @@ gem 'themes_for_rails'
gem 'rubyzip' gem 'rubyzip'
gem 'acts_as_votable' gem 'acts_as_votable'
gem 'kaminari'
gem 'will_paginate' gem 'bootstrap-kaminari-views', :git=>'git://github.com/matenia/bootstrap-kaminari-views.git'
gem 'bootstrap-will_paginate' #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 if $('#infinite-scrolling').size() > 0
more_posts_url = $('.pagination .next_page a').attr('href') 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? # @lva = params([:lva]) unless params([:lva]).nil?
@beispiel = Beispiel.find(params[:id]) @beispiel = Beispiel.find(params[:id])
respond_to do |format| 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 format.js
end end
end end

View File

@@ -1,10 +1,25 @@
class CommentsController < ApplicationController class CommentsController < ApplicationController
def index 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 end
def show def show
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render json: @comment } 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? 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) @comment = Comment.build_for(c, current_user,"", params_new)
#raise @comment.to_yaml.to_s
# @comment.commentable= c
respond_to do |format| respond_to do |format|
if @comment 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 } format.json { render json: @comment, status: :created, location: @comment }
else else
format.html { render action: "new" } format.html { render action: "new" }
@@ -73,11 +82,13 @@ class CommentsController < ApplicationController
# DELETE /comments/1.json # DELETE /comments/1.json
def destroy def destroy
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
@commentable=@comment.commentable
@comment.destroy @comment.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to comments_url } format.html { redirect_to @commentable, :action=>"show"}
format.json { head :no_content } format.json { head :no_content }
end end
end end
end end

View File

@@ -4,10 +4,10 @@ class RubrikenController < ApplicationController
def index def index
if can?(:showintern, Rubrik) if can?(:showintern, Rubrik)
@rubriken = Rubrik.all @rubriken = Rubrik.all
@neuigkeiten = Neuigkeit.paginate(page: params[:page], per_page:3) @neuigkeiten = Neuigkeit.page(params[:page]).per(3)
else else
@rubriken = Rubrik.where(:public=>true) @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 end
@calentries= @rubriken.collect(&:calentries).flatten @calentries= @rubriken.collect(&:calentries).flatten
@@ -31,9 +31,9 @@ class RubrikenController < ApplicationController
@moderatoren=User.with_role(:newsmoderator,@rubrik) @moderatoren=User.with_role(:newsmoderator,@rubrik)
@calentries= @rubrik.calentries @calentries= @rubrik.calentries
if can?(:showunpublished, Neuigkeit) if can?(:showunpublished, Neuigkeit)
@neuigkeiten = @rubrik.neuigkeiten.paginate(page: params[:page], per_page:3) @neuigkeiten = @rubrik.neuigkeiten.page(params[:page]).per(3)
else else
@neuigkeiten = @rubrik.neuigkeiten.published.paginate(page: params[:page], per_page:3) @neuigkeiten = @rubrik.neuigkeiten.published..page(params[:page]).per(3)
end 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('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 @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 format.js
end end
end end
def sanitize
@thema = Thema.find(params[:id])
@fragen=@thema.fragen
end
def verwalten def verwalten
@thema = Thema.find(params[:id]) @thema = Thema.find(params[:id])
@attachment=Attachment.new @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= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil?
t_url t_url
end 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 def divid
"comment_" + id.to_s "comment_" + id.to_s
end end

View File

@@ -1,41 +1,50 @@
<div id="<%= beispiel.divid %>" class="contentbox"> <div id="<%= beispiel.divid %>" class="contentbox">
<div class="row-fluid"> <div class="row-fluid">
<div class="span8"> <div class="span8">
<b><%=link_to ffi1_icon("note20")+" " + beispiel.name, beispiel.beispieldatei.url, title: beispiel.desc %></b> <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> <%= 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 if can?(:like, beispiel)
else 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
"liked by " + beispiel.get_likes.size.to_s else
end "liked by " + beispiel.get_likes.size.to_s
%> end
%>
<%= <%=
if can?(:dislike, beispiel) if can?(:dislike, beispiel)
link_to ffi1_icon("dislike")+" dislike" + "("+beispiel.get_dislikes.size.to_s+")", dislike_beispiel_path(beispiel),title:"disliked by " + ((current_user.disliked?(beispiel)) ? ("you and " + ((beispiel.get_dislikes.size - 1).to_s + " others")) : beispiel.get_dislikes.size.to_s) , remote: true link_to ffi1_icon("dislike")+" dislike" + "("+beispiel.get_dislikes.size.to_s+")", dislike_beispiel_path(beispiel),title:"disliked by " + ((current_user.disliked?(beispiel)) ? ("you and " + ((beispiel.get_dislikes.size - 1).to_s + " others")) : beispiel.get_dislikes.size.to_s) , remote: true
else else
"disliked by " + beispiel.get_dislikes.size.to_s "disliked by " + beispiel.get_dislikes.size.to_s
end end
%> %>
<%= link_to ff_icon("icon-pencil")+" edit", edit_beispiel_path(beispiel) if can? :edit, beispiel%> <%= 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 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> </span>
</div> </div>
<div class="span4"> <div class="span4">
<%= beispiel.desc %> <%= beispiel.desc %>
</div> </div>
</div> </div>
<%= link_to "comment" , new_comment_path( commentable_type: "Beispiel", commentable_id: beispiel.id), remote:true if can? :comment, beispiel %>
<%= 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 id="<%= Comment.formid_for(beispiel) %>">
</div> </div>
<% unless beispiel.comments.roots.empty? %> <% 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">
<% end %> <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> </div>

View File

@@ -1,17 +1,19 @@
<div id="<%= comment.divid %>"> <div id="<%= comment.divid %>">
<a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a> <a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a>
<div class="media-body"> <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 %> <p><%= comment.text %>
<% if can?(:comment, comment.commentable) %> <% if can?(:comment, comment.commentable) %>
<br><%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %> <br><%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %>
<% end %> <% end %>
</p> </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 %> <%= render partial:"comments/comments", object: comment.children.order(:created_at).reverse_order if comment.children.size >0 %>
</div> </div>
<div id="<%= Comment.formid_for(comment) %>">
</div>
</div> </div>

View File

@@ -6,4 +6,7 @@
<% end %> <% end %>
</ul> </ul>
</div> </div>
<% if comments.first.root? %>
<%= paginate comments, :remote=>true , :theme=>'twitter-bootstrap'%>
<% end %>
<% 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> <h1>Listing comments</h1>
<%= render partial:"comments/comments", object: @comments %>
<table> <table>
<tr> <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 %> <% end %>
</ul> </ul>
<div id="infinite-scrolling"> <div id="infinite-scrolling">
<%= will_paginate @neuigkeiten %> <%= paginate @neuigkeiten, theme:'twitter-bootstrap' %>
</div> </div>
</div> </div>

View File

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

View File

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

View File

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