Replace will_paginate with kaminari. Fixed foodcoop/users page.

This commit is contained in:
benni 2012-10-08 15:24:32 +02:00
parent 1708df3f6c
commit ab81ef09d5
17 changed files with 162 additions and 64 deletions

View File

@ -21,11 +21,10 @@ gem 'mysql2'
gem "fastercsv"
gem 'prawn'
gem 'haml-rails'
gem "will_paginate", "~> 3.0.pre2"
gem 'kaminari'
gem 'client_side_validations'
gem 'simple_form'
gem 'rails3_acts_as_paranoid', "~>0.1.4"
gem 'meta_search'
gem 'inherited_resources'
gem 'localize_input', :git => "git://github.com/bennibu/localize_input.git"
gem 'wikicloth'

View File

@ -77,6 +77,9 @@ GEM
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
kaminari (0.14.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
less (2.2.2)
commonjs (~> 0.2.6)
less-rails (2.2.3)
@ -87,11 +90,6 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.3)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
polyamorous (~> 0.5.0)
mime-types (1.19)
multi_json (1.3.6)
mysql2 (0.3.11)
@ -99,8 +97,6 @@ GEM
Ascii85 (~> 1.0.0)
hashery (~> 2.0)
ruby-rc4
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
prawn (0.12.0)
pdf-reader (>= 0.9.0)
@ -171,7 +167,6 @@ GEM
wikicloth (0.8.0)
builder
expression_parser
will_paginate (3.0.3)
PLATFORMS
ruby
@ -186,8 +181,8 @@ DEPENDENCIES
haml-rails
inherited_resources
jquery-rails
kaminari
localize_input!
meta_search
mysql2
prawn
rails (= 3.2.8)
@ -200,4 +195,3 @@ DEPENDENCIES
twitter-bootstrap-rails
uglifier (>= 1.0.3)
wikicloth
will_paginate (~> 3.0.pre2)

View File

@ -4,11 +4,16 @@ class Foodcoop::UsersController < ApplicationController
@users = User.order('nick ASC')
# if somebody uses the search field:
unless params[:query].blank?
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
unless params[:user_name].blank?
@users = @users.where("first_name LIKE :user_name OR last_name LIKE :user_name OR nick LIKE :user_name",
user_name: "%#{params[:user_name]}%")
end
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
if params[:ordergroup_name]
@users = @users.joins(:groups).where("groups.type = 'Ordergroup' AND groups.name LIKE ?", "%#{params[:ordergroup_name]}%")
end
@users = @users.page(params[:page]).per(@per_page).order('users.nick ASC')
respond_to do |format|
format.html # index.html.haml

View File

@ -20,18 +20,11 @@ module ApplicationHelper
end
# Creates ajax-controlled-links for pagination
# see also the plugin "will_paginate"
def pagination_links_remote(collection, options = {})
per_page = options[:per_page] || @per_page
params = options[:params] || {}
# Translations
previous_label = '&laquo; ' + "Vorherige"
next_label = "Nächste" + ' &raquo;'
# Merge other url-options for will_paginate
params = params.merge({:per_page => per_page})
will_paginate collection, :params => params, 'data-remote' => true,
:previous_label => previous_label, :next_label => next_label
paginate collection, :params => params, :remote => true
end
# Link-collection for per_page-options when using the pagination-plugin
@ -42,9 +35,15 @@ module ApplicationHelper
links = per_page_options.map do |per_page|
params.merge!({:per_page => per_page})
per_page == current ? per_page : link_to(per_page, params, :remote => true)
link_class = 'btn'
link_class << ' disabled' if per_page == current
link_to(per_page, params, :remote => true, class: link_class)
end
"Pro Seite: #{links.join(" ")}".html_safe
content_tag :div, class: 'btn-group pull-right' do
links.join.html_safe
end
end
def sort_td_class_helper(param)

View File

@ -9,4 +9,12 @@ module MessagesHelper
end
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe
end
def link_to_new_message(options = {})
messages_params = options[:message_params] || nil
link_text = content_tag :id, nil, class: 'icon-envelope'
link_text << " #{options[:text]}" if options[:text].present?
link_to(link_text.html_safe, new_message_path(message: messages_params), class: 'btn',
title: 'Nachricht verschicken')
end
end

View File

@ -1,13 +1,8 @@
- unless params[:sort_by_ordergroups]
%p
%table{:style => "width:100%"}
%tr
%td
= pagination_links_remote @users, :update => :users
%td{:style => "text-align:right"}
- if @users.size > 20
= items_per_page :update => :users
%table.list
- if User.count > 20
= items_per_page
= pagination_links_remote @users
%table.table.table-striped
%thead
%tr
%th Benutzername
@ -17,13 +12,13 @@
%th Bestellgruppe
%th Arbeitsgruppe(n)
%tbody
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users
- for user in users
%tr{:class => cycle('even','odd', :name => 'users')}
%td= link_to user.nick, new_message_path(:message => {:mail_to => user.id}), :title => 'Send user an email'
%td=h user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
%td=h user.email if @current_user.role_admin? || user.settings["profile.emailIsPublic"] == '1'
%td=h user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1'
%td=h user.ordergroup_name
%td=h user.workgroups.collect(&:name).join(', ')
- for user in @users
%tr
%td= user.nick
%td= user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
%td= user.email if @current_user.role_admin? || user.settings["profile.emailIsPublic"] == '1'
%td= user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1'
%td= user.ordergroup_name
%td= user.workgroups.collect(&:name).join(', ')
%td= link_to_new_message(message_params: {mail_to: user.id})

View File

@ -1,24 +1,23 @@
%h1 Mitglieder der Foodcoop
%p
%i
- title "Mitglieder"
%section
%p
Hier kannst Du den Mitgliedern Deiner Foodcoop eine Nachricht schreiben.
%br/
Damit Deine Kontaktdaten einzusehen sind, musst Du sie unter
= link_to "Einstellungen", my_profile_path
freigeben.
.left_column{:style => "width:100%"}
.box_title
%h2 Übersicht
.column_content
- unless params[:sort_by_ordergroups]
#user_filter{:style => "float:left; margin-right:2em;"}
= form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search',
:remote => true, 'data-submit-onchange' => true do
%label{:for => 'article_name'} Suche nach Name:
= text_field_tag :query, params[:query], :size => 10
.well
= form_tag foodcoop_users_path, :method => :get, :remote => true,
'data-submit-onchange' => true, class: 'form-search' do
Nach Bestellgruppen sortieren:
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]
#users
= render :partial => "users"
= text_field_tag :user_name, params[:user_name], class: 'input-medium search-query',
placeholder: 'Name ...'
= text_field_tag :ordergroup_name, params[:ordergroup_name], class: 'input-medium search-query',
placeholder: 'Bestelllgruppe ...'
%button.btn
%i.icon-search
#users
= render :partial => "users"

View File

@ -1 +1 @@
$('#users').html('<%= escape_javascript(render("users")) %>');
$('#users').html('<%= escape_javascript(render("users")) %>');

View File

@ -0,0 +1,12 @@
-#
Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
- unless current_page.first?
%li{:class => "first"}
= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote

View File

@ -0,0 +1,11 @@
-#
Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
%li{:class => "page gap disabled"}
%a{:href => "#", :onclick => "return false;"}
= raw(t 'views.pagination.truncate')

View File

@ -0,0 +1,13 @@
-#
Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
- unless current_page.last?
%li{:class=>"last next"}
-# "next" class present for border styling in twitter bootstrap %>
= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}

View File

@ -0,0 +1,12 @@
-#
Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
- unless current_page.last?
%li{:class=>"next_page"}
= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote

View File

@ -0,0 +1,11 @@
-#
Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
%li{:class=>"page #{' active' if page.current? }"}
= link_to page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}

View File

@ -0,0 +1,21 @@
-#
The container tag
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
= paginator.render do
%nav.pagination
%ul
= first_page_tag unless current_page.first?
= prev_page_tag unless current_page.first?
- each_page do |page|
- if page.left_outer? || page.right_outer? || page.inside_window?
= page_tag page
- elsif !page.was_truncated?
= gap_tag
= next_page_tag unless current_page.last?
= last_page_tag unless current_page.last?

View File

@ -0,0 +1,12 @@
-#
Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
- unless current_page.first?
%li{:class=>"prev"}
= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote

View File

@ -10,6 +10,13 @@ de:
not_enough_apples:
Um zu Bestellen brauchst Du mindestends %{stop_ordering_under} Äpfel.
Momentan hat Deine Bestellgruppe aber nur %{apples} Äpfel.
views:
pagination:
first: "&laquo;"
last: "&raquo;"
previous: "&lsaquo;"
next: "&rsaquo;"
truncate: "..."
date:
abbr_day_names:
- So

View File

@ -38,9 +38,9 @@ SimpleNavigation::Configuration.run do |navigation|
end
primary.item :admin, 'Administration', '#', if: Proc.new { current_user.role_admin? } do |subnav|
subnav.item :users, 'Benutzerinnen', admin_users_path
subnav.item :ordergroups, 'Bestellgruppen', admin_ordergroups_path
subnav.item :workgroups, 'Arbeitsgruppen', admin_workgroups_path
subnav.item :users, 'Benutzerinnen', admin_users_path, id: nil
subnav.item :ordergroups, 'Bestellgruppen', admin_ordergroups_path, id: nil
subnav.item :workgroups, 'Arbeitsgruppen', admin_workgroups_path, id: nil
end
primary.item :divider, '', '#', class: 'divider'