diff --git a/Gemfile b/Gemfile
index 8b79086c..f450622a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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'
diff --git a/Gemfile.lock b/Gemfile.lock
index 8995a509..73ad6428 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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)
diff --git a/app/controllers/foodcoop/users_controller.rb b/app/controllers/foodcoop/users_controller.rb
index ee57c59d..f73147bc 100644
--- a/app/controllers/foodcoop/users_controller.rb
+++ b/app/controllers/foodcoop/users_controller.rb
@@ -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
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ad2eebc1..55a07948 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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 = '« ' + "Vorherige"
- next_label = "Nächste" + ' »'
- # 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)
diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb
index e672107c..13bbbc95 100644
--- a/app/helpers/messages_helper.rb
+++ b/app/helpers/messages_helper.rb
@@ -9,4 +9,12 @@ module MessagesHelper
end
"#{link_to(h(subject), message)} #{h(body)}".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
diff --git a/app/views/foodcoop/users/_users.html.haml b/app/views/foodcoop/users/_users.html.haml
index 8fb1a8e2..bddc385b 100644
--- a/app/views/foodcoop/users/_users.html.haml
+++ b/app/views/foodcoop/users/_users.html.haml
@@ -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})
diff --git a/app/views/foodcoop/users/index.html.haml b/app/views/foodcoop/users/index.html.haml
index 00951486..464b08a4 100644
--- a/app/views/foodcoop/users/index.html.haml
+++ b/app/views/foodcoop/users/index.html.haml
@@ -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"
\ No newline at end of file
+ = 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"
\ No newline at end of file
diff --git a/app/views/foodcoop/users/index.js.erb b/app/views/foodcoop/users/index.js.erb
index 14521518..3b47479f 100644
--- a/app/views/foodcoop/users/index.js.erb
+++ b/app/views/foodcoop/users/index.js.erb
@@ -1 +1 @@
-$('#users').html('<%= escape_javascript(render("users")) %>');
\ No newline at end of file
+$('#users').html('<%= escape_javascript(render("users")) %>');
diff --git a/app/views/kaminari/_first_page.html.haml b/app/views/kaminari/_first_page.html.haml
new file mode 100644
index 00000000..90b48d12
--- /dev/null
+++ b/app/views/kaminari/_first_page.html.haml
@@ -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
\ No newline at end of file
diff --git a/app/views/kaminari/_gap.html.haml b/app/views/kaminari/_gap.html.haml
new file mode 100644
index 00000000..824ae292
--- /dev/null
+++ b/app/views/kaminari/_gap.html.haml
@@ -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')
\ No newline at end of file
diff --git a/app/views/kaminari/_last_page.html.haml b/app/views/kaminari/_last_page.html.haml
new file mode 100644
index 00000000..b185e96a
--- /dev/null
+++ b/app/views/kaminari/_last_page.html.haml
@@ -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}
\ No newline at end of file
diff --git a/app/views/kaminari/_next_page.html.haml b/app/views/kaminari/_next_page.html.haml
new file mode 100644
index 00000000..d3d749cd
--- /dev/null
+++ b/app/views/kaminari/_next_page.html.haml
@@ -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
\ No newline at end of file
diff --git a/app/views/kaminari/_page.html.haml b/app/views/kaminari/_page.html.haml
new file mode 100644
index 00000000..6df34eb0
--- /dev/null
+++ b/app/views/kaminari/_page.html.haml
@@ -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}
\ No newline at end of file
diff --git a/app/views/kaminari/_paginator.html.haml b/app/views/kaminari/_paginator.html.haml
new file mode 100644
index 00000000..748b2f1a
--- /dev/null
+++ b/app/views/kaminari/_paginator.html.haml
@@ -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?
\ No newline at end of file
diff --git a/app/views/kaminari/_prev_page.html.haml b/app/views/kaminari/_prev_page.html.haml
new file mode 100644
index 00000000..662a209f
--- /dev/null
+++ b/app/views/kaminari/_prev_page.html.haml
@@ -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
\ No newline at end of file
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 3ec8e587..9a79cd67 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -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: "«"
+ last: "»"
+ previous: "‹"
+ next: "›"
+ truncate: "..."
date:
abbr_day_names:
- So
diff --git a/config/navigation.rb b/config/navigation.rb
index 7d593fdf..852bca1c 100644
--- a/config/navigation.rb
+++ b/config/navigation.rb
@@ -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'