diff options
| author | cedricnjanga | 2017-09-11 16:06:42 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-09-11 16:21:41 +0200 |
| commit | 8fe9a39516f6fb71545d6329c448680d6f8c75d1 (patch) | |
| tree | 0b0e231aea62d32fe91544cd79c8224a755ceaf6 /app/controllers | |
| parent | ecef9d98cbe08e42434753477da4886dcfcb02bb (diff) | |
| download | chouette-core-8fe9a39516f6fb71545d6329c448680d6f8c75d1.tar.bz2 | |
Update of ReferentialsController#new :
- Add some context to referential and workbench decorator to access current_referential and assign it to the cloned referential
- Add a build_referential method to avoir duplicates of code (in the controller and in the model), need to clean a bit more
- Need to add some Spec features to take into account the functional scope of the current_user
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/referentials_controller.rb | 35 | ||||
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 2 |
2 files changed, 27 insertions, 10 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index bd0544a74..c8984076a 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -7,17 +7,19 @@ class ReferentialsController < BreadcrumbController respond_to :js, :only => :show def new - if params[:from] - source_referential = Referential.find(params[:from]) - @referential = Referential.new_from(source_referential, current_functional_scope) + new! do + build_referenial end + end - new! do - @referential.data_format = current_organisation.data_format - @referential.workbench_id ||= params[:workbench_id] + def create + create! do |format| + build_referenial - if @referential.in_workbench? - @referential.init_metadatas default_date_range: Range.new(Date.today, Date.today.advance(months: 1)) + if !!@referential.created_from_id + format.html { redirect_to workbench_path(@referential.workbench) } + else + build_breadcrumb :new end end end @@ -25,7 +27,7 @@ class ReferentialsController < BreadcrumbController def show resource.switch show! do |format| - @referential = @referential.decorate(context: { workbench_id: params[:workbench_id] } ) + @referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } ) @reflines = lines_collection.paginate(page: params[:page], per_page: 10) @reflines = ModelDecorator.decorate( @reflines, @@ -123,6 +125,21 @@ class ReferentialsController < BreadcrumbController super end + def build_referenial + if params[:from] + source_referential = Referential.find(params[:from]) + @referential = Referential.new_from(source_referential, current_functional_scope) + @referential.workbench_id = params[:current_workbench_id] + end + + @referential.data_format = current_organisation.data_format + @referential.workbench_id ||= params[:workbench_id] + + if @referential.in_workbench? + @referential.init_metadatas default_date_range: Range.new(Date.today, Date.today.advance(months: 1)) + end + end + private def sort_column sortable_columns = Chouette::Line.column_names + ['networks.name', 'companies.name'] diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index bae3fcff2..54ddb8be1 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -24,7 +24,7 @@ class WorkbenchesController < BreadcrumbController @wbench_refs, with: ReferentialDecorator, context: { - workbench_id: params[:id] + current_workbench_id: params[:id] } ) show! do |
