diff --git a/app/assets/stylesheets/bootstrap_overrides.css.sass b/app/assets/stylesheets/bootstrap_overrides.css.sass index 8d147588..ca3d14f7 100644 --- a/app/assets/stylesheets/bootstrap_overrides.css.sass +++ b/app/assets/stylesheets/bootstrap_overrides.css.sass @@ -20,3 +20,7 @@ body .container .brand padding-left: 7px + .pagination + li + a + background-color: rgba(0, 0, 0, 0.4) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 3029357d..45a014ec 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -198,7 +198,7 @@ class UserController < ApplicationController # Displays the closed lists of the user # GET /user/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' end diff --git a/app/models/list.rb b/app/models/list.rb index 7f895919..adfd80e4 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -1,5 +1,6 @@ class List include SimplyStored::Couch + per_page_method :limit_value #kaminari property :state, default: 'active' # active, #closed property :needs_help, type: :boolean, default: false @@ -24,6 +25,14 @@ class List } }|, 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 def self.from_table table, user return if user.has_active_list? @@ -35,9 +44,9 @@ class List list end - def self.of_user(user, options = {}) + def self.for_user(user, 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 diff --git a/app/views/user/list_history.html.slim b/app/views/user/list_history.html.slim index 6631f128..ef458df0 100644 --- a/app/views/user/list_history.html.slim +++ b/app/views/user/list_history.html.slim @@ -1,4 +1,5 @@ .page-header= title 'User list history' += paginate @lists ul - for list in @lists li= link_to l(list.created_at, format: :short), user_history_list_path(list_id: list.id)