aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorXinhui2016-11-09 11:47:02 +0100
committerXinhui2016-11-09 11:47:17 +0100
commit2ca92317d4dc06992e93b39202fbc3231c8cac4d (patch)
treed8ec68c092d48889234127e18d8cec6f36b32259 /app
parente5bdfe49e120f6e703e63d05fad9e53ea499b58e (diff)
downloadchouette-core-2ca92317d4dc06992e93b39202fbc3231c8cac4d.tar.bz2
Refactoring MyWorkbenchScopes with initial_scope
Refs #1787
Diffstat (limited to 'app')
-rw-r--r--app/controllers/referential_lines_controller.rb2
-rw-r--r--app/models/referential.rb6
-rw-r--r--app/models/workbench.rb2
-rw-r--r--app/views/referentials/_counts.html.slim2
-rw-r--r--app/views/shared/_header.html.slim2
5 files changed, 9 insertions, 5 deletions
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb
index 29d8fa664..a566f440e 100644
--- a/app/controllers/referential_lines_controller.rb
+++ b/app/controllers/referential_lines_controller.rb
@@ -82,7 +82,7 @@ class ReferentialLinesController < ChouetteController
params[:q]["group_of_lines_id_blank"] = "1"
end
- @q = referential.workbench.lines.search(params[:q])
+ @q = referential.lines.search(params[:q])
@lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 1e2c2acc3..8b8df3294 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -30,7 +30,7 @@ class Referential < ActiveRecord::Base
validates_presence_of :line_referential
belongs_to :created_from, class_name: 'Referential'
- has_many :lines, through: :line_referential
+ has_many :associated_lines, through: :line_referential, source: :lines
has_many :companies, through: :line_referential
has_many :group_of_lines, through: :line_referential
has_many :networks, through: :line_referential
@@ -43,6 +43,10 @@ class Referential < ActiveRecord::Base
has_many :stop_areas, through: :stop_area_referential
belongs_to :workbench
+ def lines
+ workbench ? workbench.lines : associated_lines
+ end
+
def slug_excluded_values
if ! slug.nil?
if slug.start_with? "pg_"
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index f02c6a5a1..a83fea70d 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -3,7 +3,7 @@ class Workbench < ActiveRecord::Base
belongs_to :line_referential
belongs_to :stop_area_referential
- has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope }, through: :line_referential
+ has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential
has_many :networks, through: :line_referential
has_many :companies, through: :line_referential
has_many :group_of_lines, through: :line_referential
diff --git a/app/views/referentials/_counts.html.slim b/app/views/referentials/_counts.html.slim
index 5d7019225..9754ebc99 100644
--- a/app/views/referentials/_counts.html.slim
+++ b/app/views/referentials/_counts.html.slim
@@ -16,7 +16,7 @@
= Referential.human_attribute_name('group_of_lines')
li.list-group-item
- span.badge = @referential.workbench.lines.size
+ span.badge = @referential.lines.size
= Referential.human_attribute_name('lines')
li.list-group-item
diff --git a/app/views/shared/_header.html.slim b/app/views/shared/_header.html.slim
index 58785f34c..73e705e35 100644
--- a/app/views/shared/_header.html.slim
+++ b/app/views/shared/_header.html.slim
@@ -63,7 +63,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
li
= link_to referential_lines_path(@referential) do
- span.badge.pull-right = @referential.workbench.lines.size
+ span.badge.pull-right = @referential.lines.size
= Referential.human_attribute_name("lines")
li