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 "fastercsv"
gem 'prawn' gem 'prawn'
gem 'haml-rails' gem 'haml-rails'
gem "will_paginate", "~> 3.0.pre2" gem 'kaminari'
gem 'client_side_validations' gem 'client_side_validations'
gem 'simple_form' gem 'simple_form'
gem 'rails3_acts_as_paranoid', "~>0.1.4" gem 'rails3_acts_as_paranoid', "~>0.1.4"
gem 'meta_search'
gem 'inherited_resources' gem 'inherited_resources'
gem 'localize_input', :git => "git://github.com/bennibu/localize_input.git" gem 'localize_input', :git => "git://github.com/bennibu/localize_input.git"
gem 'wikicloth' gem 'wikicloth'

View file

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

View file

@ -4,11 +4,16 @@ class Foodcoop::UsersController < ApplicationController
@users = User.order('nick ASC') @users = User.order('nick ASC')
# if somebody uses the search field: # if somebody uses the search field:
unless params[:query].blank? unless params[:user_name].blank?
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"})) @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 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| respond_to do |format|
format.html # index.html.haml format.html # index.html.haml

View file

@ -20,18 +20,11 @@ module ApplicationHelper
end end
# Creates ajax-controlled-links for pagination # Creates ajax-controlled-links for pagination
# see also the plugin "will_paginate"
def pagination_links_remote(collection, options = {}) def pagination_links_remote(collection, options = {})
per_page = options[:per_page] || @per_page per_page = options[:per_page] || @per_page
params = options[:params] || {} 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}) params = params.merge({:per_page => per_page})
will_paginate collection, :params => params, 'data-remote' => true, paginate collection, :params => params, :remote => true
:previous_label => previous_label, :next_label => next_label
end end
# Link-collection for per_page-options when using the pagination-plugin # 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| links = per_page_options.map do |per_page|
params.merge!({:per_page => 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 end
"Pro Seite: #{links.join(" ")}".html_safe
content_tag :div, class: 'btn-group pull-right' do
links.join.html_safe
end
end end
def sort_td_class_helper(param) def sort_td_class_helper(param)

View file

@ -9,4 +9,12 @@ module MessagesHelper
end end
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe "<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe
end 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 end

View file

@ -1,13 +1,8 @@
- unless params[:sort_by_ordergroups] - unless params[:sort_by_ordergroups]
%p - if User.count > 20
%table{:style => "width:100%"} = items_per_page
%tr = pagination_links_remote @users
%td %table.table.table-striped
= pagination_links_remote @users, :update => :users
%td{:style => "text-align:right"}
- if @users.size > 20
= items_per_page :update => :users
%table.list
%thead %thead
%tr %tr
%th Benutzername %th Benutzername
@ -17,13 +12,13 @@
%th Bestellgruppe %th Bestellgruppe
%th Arbeitsgruppe(n) %th Arbeitsgruppe(n)
%tbody %tbody
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users - for user in @users
- for user in users %tr
%tr{:class => cycle('even','odd', :name => 'users')} %td= user.nick
%td= link_to user.nick, new_message_path(:message => {:mail_to => user.id}), :title => 'Send user an email' %td= user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
%td=h 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=h 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=h user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1' %td= user.ordergroup_name
%td=h user.ordergroup_name %td= user.workgroups.collect(&:name).join(', ')
%td=h 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 - title "Mitglieder"
%section
%p %p
%i
Hier kannst Du den Mitgliedern Deiner Foodcoop eine Nachricht schreiben. Hier kannst Du den Mitgliedern Deiner Foodcoop eine Nachricht schreiben.
%br/ %br/
Damit Deine Kontaktdaten einzusehen sind, musst Du sie unter Damit Deine Kontaktdaten einzusehen sind, musst Du sie unter
= link_to "Einstellungen", my_profile_path = link_to "Einstellungen", my_profile_path
freigeben. freigeben.
.left_column{:style => "width:100%"} .well
.box_title = form_tag foodcoop_users_path, :method => :get, :remote => true,
%h2 Übersicht 'data-submit-onchange' => true, class: 'form-search' do
.column_content
- unless params[:sort_by_ordergroups] = text_field_tag :user_name, params[:user_name], class: 'input-medium search-query',
#user_filter{:style => "float:left; margin-right:2em;"} placeholder: 'Name ...'
= form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search', = text_field_tag :ordergroup_name, params[:ordergroup_name], class: 'input-medium search-query',
:remote => true, 'data-submit-onchange' => true do placeholder: 'Bestelllgruppe ...'
%label{:for => 'article_name'} Suche nach Name: %button.btn
= text_field_tag :query, params[:query], :size => 10 %i.icon-search
Nach Bestellgruppen sortieren:
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]
#users #users
= render :partial => "users" = render :partial => "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: not_enough_apples:
Um zu Bestellen brauchst Du mindestends %{stop_ordering_under} Äpfel. Um zu Bestellen brauchst Du mindestends %{stop_ordering_under} Äpfel.
Momentan hat Deine Bestellgruppe aber nur %{apples} Äpfel. Momentan hat Deine Bestellgruppe aber nur %{apples} Äpfel.
views:
pagination:
first: "&laquo;"
last: "&raquo;"
previous: "&lsaquo;"
next: "&rsaquo;"
truncate: "..."
date: date:
abbr_day_names: abbr_day_names:
- So - So

View file

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