From 2eb01bdf422fa5a5d662a49c79aee007635b793f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 26 Nov 2015 12:29:34 +0100 Subject: [PATCH] Add paginate for user dossiers --- Gemfile | 3 +++ Gemfile.lock | 7 +++++++ app/assets/stylesheets/application.scss | 5 +++++ app/controllers/users/dossiers_controller.rb | 12 +++++++++--- app/decorators/dossier_decorator.rb | 1 + app/decorators/dossiers_decorator.rb | 4 ++++ app/views/users/dossiers/index.html.haml | 5 ++++- config/locales/fr.yml | 4 ++++ 8 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 app/decorators/dossiers_decorator.rb diff --git a/Gemfile b/Gemfile index 4b447edb4..cedaac8df 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,9 @@ gem 'haml-rails' #bootstrap saas gem 'bootstrap-sass', '~> 3.3.5' +# Pagination +gem 'will_paginate-bootstrap' + # Decorators gem 'draper' diff --git a/Gemfile.lock b/Gemfile.lock index f350af0f5..a7bfbf62e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -408,6 +408,9 @@ GEM websocket-driver (0.5.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + will_paginate (3.0.7) + will_paginate-bootstrap (1.0.1) + will_paginate (>= 3.0.3) xpath (2.0.0) nokogiri (~> 1.3) @@ -465,3 +468,7 @@ DEPENDENCIES unicorn web-console (~> 2.0) webmock + will_paginate-bootstrap + +BUNDLED WITH + 1.10.6 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 424790ccf..7e3678c01 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -89,6 +89,11 @@ input#nom_projet { max-width: 27px; } +div.pagination{ + padding-top:20px; + display:block; + text-align: center; +} .alert.alert-success.move_up { position: absolute; diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 87dbb8d08..a30a713d6 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -2,10 +2,16 @@ class Users::DossiersController < UsersController before_action :authenticate_user! def index - @dossiers = current_user.dossiers.where("state NOT IN ('draft')").order(updated_at: 'DESC').decorate - end - def show + @dossiers = current_user.dossiers.where("state NOT IN ('draft')").order(updated_at: 'DESC') + if params[:page].nil? + params[:page] = 1 + end + + @dossiers = @dossiers.paginate(:page => params[:page], :per_page => 12).decorate + end + + def show @dossier = current_user_dossier params[:id] @etablissement = @dossier.etablissement diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index 57378acc6..8d70fe9a1 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -1,4 +1,5 @@ class DossierDecorator < Draper::Decorator + delegate :current_page, :per_page, :offset, :total_entries, :total_pages delegate_all def date_fr diff --git a/app/decorators/dossiers_decorator.rb b/app/decorators/dossiers_decorator.rb new file mode 100644 index 000000000..6e8571b6f --- /dev/null +++ b/app/decorators/dossiers_decorator.rb @@ -0,0 +1,4 @@ +class DossiersDecorator < Draper::CollectionDecorator + delegate :current_page, :per_page, :offset, :total_entries, :total_pages + +end diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index 2749ae186..929c22e3f 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -11,4 +11,7 @@ %td = link_to(dossier.nom_projet, users_dossier_recapitulatif_path(dossier)) %td{id: "dossier_#{dossier.id}_state"}= dossier.state_fr - %td= dossier.last_update \ No newline at end of file + %td= dossier.last_update + +.pagination + = will_paginate @dossiers, renderer: BootstrapPagination::Rails \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index de6f61940..8d369a1ed 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -20,6 +20,10 @@ # available at http://guides.rubyonrails.org/i18n.html. fr: + will_paginate: + next_label: 'Suivant' + previous_label: 'Précédent' + number: currency: format: