diff options
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 6 | ||||
| -rw-r--r-- | app/models/workbench.rb | 2 | ||||
| -rw-r--r-- | app/views/referentials/_counts.html.slim | 2 | ||||
| -rw-r--r-- | app/views/shared/_header.html.slim | 2 | ||||
| -rw-r--r-- | lib/stif/my_workbench_scopes.rb | 11 |
6 files changed, 14 insertions, 11 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 diff --git a/lib/stif/my_workbench_scopes.rb b/lib/stif/my_workbench_scopes.rb index ed3432ad3..7e4500a7d 100644 --- a/lib/stif/my_workbench_scopes.rb +++ b/lib/stif/my_workbench_scopes.rb @@ -1,20 +1,19 @@ class Stif::MyWorkbenchScopes - attr_accessor :organisation + attr_accessor :workbench def initialize(workbench) @workbench = workbench end - def line_scope - scope = Chouette::Line - ids = self.parse_functional_scope - ids ? scope.where(objectid: ids) : scope.all + def line_scope(initial_scope) + ids = self.parse_functional_scope + ids ? initial_scope.where(objectid: ids) : initial_scope end def parse_functional_scope return false unless @workbench.organisation.sso_attributes begin - line_ids = JSON.parse @workbench.organisation.sso_attributes['functional_scope'] + JSON.parse @workbench.organisation.sso_attributes['functional_scope'] rescue Exception => e Rails.logger.error "MyWorkbenchScopes : #{e}" end |
