aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjpl2017-01-03 14:43:21 +0100
committerjpl2017-01-03 14:43:29 +0100
commite5cbf0ccd1a38a7674721505e978d89d26083137 (patch)
tree08a500a326937cf450b3d9957dc90c460256d719
parent7e0eb1a892c4926da8300844613fd5400469f34a (diff)
downloadchouette-core-e5cbf0ccd1a38a7674721505e978d89d26083137.tar.bz2
Refs #2236: display lines on referential
-rw-r--r--app/controllers/referentials_controller.rb29
-rw-r--r--app/views/referentials/_reflines.html.slim15
-rw-r--r--app/views/referentials/show.html.slim3
3 files changed, 47 insertions, 0 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 937fd0b76..23eb6263d 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -31,6 +31,8 @@ class ReferentialsController < BreadcrumbController
}
format.html { build_breadcrumb :show}
end
+ @reflines = lines_collection.paginate(page: params[:page], per_page: 10)
+ # resource.lines.paginate(page: params[:page], per_page: 10)
end
def edit
@@ -74,6 +76,26 @@ class ReferentialsController < BreadcrumbController
@referentials ||= current_organisation.referentials.order(:name)
end
+ def lines_collection
+ @q = resource.lines.search(params[:q])
+
+ if sort_column && sort_direction
+ @reflines ||=
+ begin
+ reflines = @q.result(distinct: true).order(sort_column + ' ' + sort_direction)
+ reflines = reflines.paginate(page: params[:page], per_page: 10)
+ reflines
+ end
+ else
+ @reflines ||=
+ begin
+ reflines = @q.result(distinct: true).order(:name)
+ reflines = reflines.paginate(page: params[:page], per_page: 10)
+ reflines
+ end
+ end
+ end
+
def build_resource
super.tap do |referential|
referential.user_id = current_user.id
@@ -87,6 +109,13 @@ class ReferentialsController < BreadcrumbController
end
private
+ def sort_column
+ resource.lines.include?(params[:sort]) ? params[:sort] : 'name'
+ end
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
+
def check_policy
authorize resource
end
diff --git a/app/views/referentials/_reflines.html.slim b/app/views/referentials/_reflines.html.slim
new file mode 100644
index 000000000..730a45e0a
--- /dev/null
+++ b/app/views/referentials/_reflines.html.slim
@@ -0,0 +1,15 @@
+- if @reflines.any?
+ p
+ strong Lignes :
+
+ = table_builder @reflines,
+ { 'Oid' => Proc.new { |n| n.objectid.local_id }, @reflines.human_attribute_name(:id) => 'id',
+ @reflines.human_attribute_name(:number) => 'number', @reflines.human_attribute_name(:name) => 'name', @reflines.human_attribute_name(:network) => Proc.new { |n| n.try(:network).try(:name) }, @reflines.human_attribute_name(:company) => Proc.new { |n| n.try(:company).try(:name) } },
+ [],
+ 'table table-bordered'
+
+ .text-center
+ = will_paginate @reflines, container: false, renderer: BootstrapPagination::Rails
+
+- else
+ = replacement_msg t('referential_lines.search_no_results')
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index e969d3b93..4826f9040 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -34,6 +34,9 @@ h2
=> l period.begin
=> Referential.human_attribute_name("end_validity_period")
= l period.end
+
+ #reflines
+ = render partial: 'reflines'
/ - if @referential.api_keys.present?
/ h3.api_keys = t('.api_keys')