paginate list history

This commit is contained in:
2012-09-07 12:12:40 +02:00
parent 3adf392e54
commit 2be6c0ee03
4 changed files with 17 additions and 3 deletions
@@ -20,3 +20,7 @@ body
.container .container
.brand .brand
padding-left: 7px padding-left: 7px
.pagination
li
a
background-color: rgba(0, 0, 0, 0.4)
+1 -1
View File
@@ -198,7 +198,7 @@ class UserController < ApplicationController
# Displays the closed lists of the user # Displays the closed lists of the user
# GET /user/list_history # GET /user/list_history
def list_history def list_history
@lists = current_user.lists @lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
render layout: 'phone' render layout: 'phone'
end end
+11 -2
View File
@@ -1,5 +1,6 @@
class List class List
include SimplyStored::Couch include SimplyStored::Couch
per_page_method :limit_value #kaminari
property :state, default: 'active' # active, #closed property :state, default: 'active' # active, #closed
property :needs_help, type: :boolean, default: false property :needs_help, type: :boolean, default: false
@@ -24,6 +25,14 @@ class List
} }
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
view :for_user_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){
doc.user_ids.forEach(function(uid){
emit([uid, doc.created_at], 1);
})
}
}|, reduce_function: '_sum'
# Create, a list given a table and a user # Create, a list given a table and a user
def self.from_table table, user def self.from_table table, user
return if user.has_active_list? return if user.has_active_list?
@@ -35,9 +44,9 @@ class List
list list
end end
def self.of_user(user, options = {}) def self.for_user(user, options = {})
with_pagination_options(options) do |options| with_pagination_options(options) do |options|
database.view(association_list_has_and_belongs_to_many_users({startkey: [user.id], endkey: ["#{user.id}\u9999"], include_docs: true, reduce: false}.merge(options))) database.view(for_user_view({startkey: ["#{user.id}\u9999"], endkey: [user.id], include_docs: true, reduce: false, descending: true}.merge(options)))
end end
end end
+1
View File
@@ -1,4 +1,5 @@
.page-header= title 'User list history' .page-header= title 'User list history'
= paginate @lists
ul ul
- for list in @lists - for list in @lists
li= link_to l(list.created_at, format: :short), user_history_list_path(list_id: list.id) li= link_to l(list.created_at, format: :short), user_history_list_path(list_id: list.id)