diff options
author | jpl | 2016-10-06 11:55:22 +0200 |
---|---|---|
committer | jpl | 2016-10-06 11:55:22 +0200 |
commit | 4b713d8b7b1097838a78d36dae3ec1cfac711349 (patch) | |
tree | 5f59b737ce7944173e5c1b96014fff51c41bd6bc | |
parent | ab0cb3af230e3b6e8c480c34581f9779036a0673 (diff) | |
download | chouette-core-4b713d8b7b1097838a78d36dae3ec1cfac711349.tar.bz2 |
adding draper for decorators(companies first)
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 7 | ||||
-rw-r--r-- | app/controllers/companies_controller.rb | 1 | ||||
-rw-r--r-- | app/decorators/company_decorator.rb | 12 | ||||
-rw-r--r-- | app/decorators/paginating_decorator.rb | 11 | ||||
-rw-r--r-- | app/views/companies/_companies.html.slim | 8 | ||||
-rw-r--r-- | spec/decorators/company_decorator_spec.rb | 4 |
7 files changed, 41 insertions, 4 deletions
@@ -93,6 +93,8 @@ gem 'will_paginate', '~> 3.0.7' gem 'ransack' gem 'squeel' +gem 'draper' + gem 'enumerize', '~> 0.10.0' gem 'foreigner', '~> 1.7.4' gem 'deep_cloneable', '~> 2.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index a9a74eabe..4e548fc12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -167,6 +167,11 @@ GEM docile (1.1.5) dr-ffi-proj4 (0.0.3) ffi (>= 1.0.0) + draper (2.1.0) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + request_store (~> 1.0) easy_translate (0.5.0) json thread @@ -398,6 +403,7 @@ GEM json (~> 1.4) redis (3.3.1) ref (2.0.0) + request_store (1.3.1) responders (1.1.2) railties (>= 3.2, < 4.2) rgeo (0.5.2) @@ -575,6 +581,7 @@ DEPENDENCIES devise-i18n devise_cas_authenticatable devise_invitable + draper enumerize (~> 0.10.0) fabrication (~> 2.14.1) factory_girl_rails (~> 4.0) diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index cd0467a21..72b751c9d 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -25,6 +25,7 @@ class CompaniesController < BreadcrumbController protected def collection @q = line_referential.companies.search(params[:q]) + # @companies ||= CompanyDecorator.decorate_collection(@q.result(:distinct => true).order(:name).paginate(:page => params[:page])) @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb new file mode 100644 index 000000000..3a0cc16ce --- /dev/null +++ b/app/decorators/company_decorator.rb @@ -0,0 +1,12 @@ +class CompanyDecorator < Draper::Decorator + delegate_all + + def self.collection_decorator_class + PaginatingDecorator + end + + def linecount + object.lines.count + end + +end diff --git a/app/decorators/paginating_decorator.rb b/app/decorators/paginating_decorator.rb new file mode 100644 index 000000000..00afb846c --- /dev/null +++ b/app/decorators/paginating_decorator.rb @@ -0,0 +1,11 @@ +class PaginatingDecorator < Draper::CollectionDecorator + delegate :current_page, + :per_page, + :offset, + :total_entries, + :total_pages, + :out_of_bounds?, + :limit_value, + :model_name, + :total_count +end diff --git a/app/views/companies/_companies.html.slim b/app/views/companies/_companies.html.slim index 8891912f0..b9053c8cb 100644 --- a/app/views/companies/_companies.html.slim +++ b/app/views/companies/_companies.html.slim @@ -1,9 +1,9 @@ .page_info span.search = t('will_paginate.page_entries_info.search') - = page_entries_info(@companies) + = page_entries_info @companies -.companies.paginated_content style="margin-top:20px;" - = table_builder @companies, [:name, :edited_at, :published_at, :validity_period, :lines, :transporter, :status], 'table table-bordered' +.companies.paginated_content + = table_builder CompanyDecorator.decorate_collection(@companies), [:name, :edited_at, :published_at, :validity_period, :linecount, :transporter, :status], 'table table-bordered' .pagination - = will_paginate @companies, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer + = will_paginate @companies, container: false, renderer: RemoteBootstrapPaginationLinkRenderer diff --git a/spec/decorators/company_decorator_spec.rb b/spec/decorators/company_decorator_spec.rb new file mode 100644 index 000000000..42ed6a408 --- /dev/null +++ b/spec/decorators/company_decorator_spec.rb @@ -0,0 +1,4 @@ +require 'spec_helper' + +describe CompanyDecorator do +end |