aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/referentials_controller.rb4
-rw-r--r--app/models/referential.rb5
-rw-r--r--app/models/referential_metadata.rb3
-rw-r--r--app/views/referentials/_form.html.slim2
-rw-r--r--app/views/workbenches/index.html.slim6
6 files changed, 16 insertions, 9 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d15aa336d..47b54039c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -33,6 +33,11 @@ class ApplicationController < ActionController::Base
end
helper_method :current_organisation
+ def current_functional_scope
+ JSON.parse(current_organisation.sso_attributes["functional_scope"]) if current_organisation
+ end
+ helper_method :current_functional_scope
+
def begin_of_association_chain
current_organisation
end
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index afd376092..2094047b1 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -9,7 +9,8 @@ class ReferentialsController < BreadcrumbController
def new
if params[:from]
source_referential = Referential.find(params[:from])
- @referential = Referential.new_from(source_referential)
+ @referential = Referential.new_from(source_referential, current_functional_scope)
+ @referential.workbench_id = current_organisation.workbenches.first.id
end
new! do
@@ -56,6 +57,7 @@ class ReferentialsController < BreadcrumbController
end
def destroy
+ binding.pry
workbench = referential.workbench_id
referential.destroy!
diff --git a/app/models/referential.rb b/app/models/referential.rb
index cb2c7b23b..ecfc69c4a 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -130,7 +130,7 @@ class Referential < ActiveRecord::Base
self
end
- def self.new_from(from)
+ def self.new_from(from, functional_scope)
Referential.new(
name: I18n.t("activerecord.copy", :name => from.name),
slug: "#{from.slug}_clone",
@@ -139,9 +139,8 @@ class Referential < ActiveRecord::Base
bounds: from.bounds,
line_referential: from.line_referential,
stop_area_referential: from.stop_area_referential,
- workbench: from.workbench,
created_from: from,
- metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m) }
+ metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) }
)
end
diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb
index b774072c7..839a937f4 100644
--- a/app/models/referential_metadata.rb
+++ b/app/models/referential_metadata.rb
@@ -155,8 +155,9 @@ class ReferentialMetadata < ActiveRecord::Base
end
private :clear_periods
- def self.new_from from
+ def self.new_from(from, functional_scope)
from.dup.tap do |metadata|
+ metadata.line_ids = from.referential.lines.where(id: metadata.line_ids, objectid: functional_scope).collect(&:id)
metadata.referential_id = nil
end
end
diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim
index a9e308699..6f7da84c7 100644
--- a/app/views/referentials/_form.html.slim
+++ b/app/views/referentials/_form.html.slim
@@ -46,7 +46,7 @@
.separator
- = subform.input :lines, as: :select, collection: @referential.workbench.lines.includes(:company).order(:name), selected: subform.object.line_ids, label_method: :display_name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('simple_form.labels.referential.placeholders.select_lines'), 'multiple': 'multiple', style: 'width: 100%' }
+ = subform.input :lines, as: :select, collection: Chouette::Line.includes(:company).order(:name).where(objectid: current_functional_scope), selected: subform.object.line_ids, label_method: :display_name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('simple_form.labels.referential.placeholders.select_lines'), 'multiple': 'multiple', style: 'width: 100%' }
.hidden = form.input :workbench_id, as: :hidden
diff --git a/app/views/workbenches/index.html.slim b/app/views/workbenches/index.html.slim
index 54d50d114..d57f579ff 100644
--- a/app/views/workbenches/index.html.slim
+++ b/app/views/workbenches/index.html.slim
@@ -34,7 +34,7 @@
div
= t('.offers.referentials')
span.badge.ml-xs = @referentials.count if @referentials.any?
-
+
div
= link_to '', workbench_path(@workbench), class: ' fa fa-chevron-right pull-right', title: t('.offers.see')
@@ -42,7 +42,7 @@
.list-group
- @referentials.each_with_index do |referential, i|
= link_to referential.name, referential_path(referential), class: 'list-group-item' if i < 6
-
+
- else
.panel-body
em.small.text-muted = t('.offers.no_content')
@@ -61,7 +61,7 @@
.list-group
- @calendars.each_with_index do |calendar, i|
= link_to calendar.name, calendar_path(calendar), class: 'list-group-item' if i < 6
-
+
- else
.panel-body
em.small.text-muted = t('.offers.no_content')