diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/application_controller.rb | 10 | ||||
| -rw-r--r-- | app/controllers/referentials_controller.rb | 12 | ||||
| -rw-r--r-- | app/decorators/referential_decorator.rb | 4 | ||||
| -rw-r--r-- | app/helpers/referentials_helper.rb | 10 | ||||
| -rw-r--r-- | app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js | 10 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 2 | ||||
| -rw-r--r-- | app/models/organisation.rb | 4 | ||||
| -rw-r--r-- | app/models/user.rb | 1 | ||||
| -rw-r--r-- | app/models/workbench.rb | 7 | ||||
| -rw-r--r-- | app/views/dashboards/_dashboard.html.slim | 30 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left_content_stif.html.slim | 10 | ||||
| -rw-r--r-- | app/views/referentials/_form.html.slim | 4 | ||||
| -rw-r--r-- | app/views/referentials/select_compliance_control_set.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stif/dashboards/_dashboard.html.slim | 6 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 4 |
15 files changed, 69 insertions, 47 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8bd3da2f9..45b7f55f6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,16 +36,6 @@ class ApplicationController < ActionController::Base end helper_method :current_organisation - def current_offer_workbench - current_organisation.workbenches.find_by_name("Gestion de l'offre") - end - helper_method :current_offer_workbench - - def current_workgroup - current_offer_workbench.workgroup - end - helper_method :current_workgroup - def current_functional_scope functional_scope = current_organisation.sso_attributes.try(:[], "functional_scope") if current_organisation JSON.parse(functional_scope) if functional_scope diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 0ed3f75dd..5267c15d8 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,5 +1,6 @@ class ReferentialsController < ChouetteController defaults :resource_class => Referential + before_action :load_workbench include PolicyChecker respond_to :html @@ -30,7 +31,7 @@ class ReferentialsController < ChouetteController def show resource.switch show! do |format| - @referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } ) + @referential = @referential.decorate() @reflines = lines_collection.paginate(page: params[:page], per_page: 10) @reflines = ReferentialLineDecorator.decorate( @reflines, @@ -141,7 +142,6 @@ class ReferentialsController < ChouetteController 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 @@ -175,4 +175,12 @@ class ReferentialsController < ChouetteController ) end + def load_workbench + @workbench ||= Workbench.find(params[:workbench_id]) if params[:workbench_id] + @workbench ||= resource&.workbench if params[:id] + @workbench + end + + alias_method :current_workbench, :load_workbench + helper_method :current_workbench end diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index 3132cbf92..41cad237d 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -22,12 +22,12 @@ class ReferentialDecorator < AF83::Decorator instance_decorator.action_link policy: :clone, secondary: :show do |l| l.content t('actions.clone') - l.href { h.new_referential_path(from: object.id, current_workbench_id: context[:current_workbench_id]) } + l.href { h.duplicate_workbench_referential_path(object) } end instance_decorator.action_link policy: :validate, secondary: :show do |l| l.content t('actions.validate') - l.href { h.referential_select_compliance_control_set_path(object.id) } + l.href { h.select_compliance_control_set_referential_path(object.id) } end instance_decorator.action_link policy: :archive, secondary: :show do |l| diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb index 8251377aa..e464ec8a5 100644 --- a/app/helpers/referentials_helper.rb +++ b/app/helpers/referentials_helper.rb @@ -15,4 +15,14 @@ module ReferentialsHelper service = ReferentialOverview.new referential, self render partial: "referentials/overview", locals: {referential: referential, overview: service} end + + def mutual_workbench workbench + current_user.organisation.workbenches.where(workgroup_id: workbench.workgroup_id).last + end + + def duplicate_workbench_referential_path referential + workbench = mutual_workbench referential.workbench + raise "Missing workbench for referential #{referential.name}" unless workbench.present? + new_workbench_referential_path(workbench, from: referential.id) + end end diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js index 7ab85a1ea..72dbd0152 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js @@ -29,11 +29,11 @@ export default class BSelect4 extends Component { val = this.props.selection.selectedJPModal } } - if(this.useAjax()){ - val = val.published_name - } - else{ - if(val){ + if(val){ + if(this.useAjax()){ + val = val.published_name + } + else{ val = val.id } } diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index bb8747faa..830fe8b78 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -384,8 +384,8 @@ module Chouette def country_name return unless country_code - country = ISO3166::Country[country_code] + return unless country country.translations[I18n.locale.to_s] || country.name end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index da7d1fcf3..e8fb4e060 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -80,4 +80,8 @@ class Organisation < ActiveRecord::Base features && features.include?(feature.to_s) end + def default_workbench + workbenches.default + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 1342f60ed..31e634415 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,6 +15,7 @@ class User < ActiveRecord::Base # Setup accessible (or protected) attributes for your model # attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes belongs_to :organisation + has_many :workbenches, through: :organisation accepts_nested_attributes_for :organisation validates :organisation, :presence => true diff --git a/app/models/workbench.rb b/app/models/workbench.rb index b80fa64ac..eb53af7aa 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,4 +1,6 @@ class Workbench < ActiveRecord::Base + DEFAULT_WORKBENCH_NAME = "Gestion de l'offre" + include ObjectidFormatterSupport belongs_to :organisation belongs_to :line_referential @@ -40,6 +42,11 @@ class Workbench < ActiveRecord::Base end end + def self.default + self.last if self.count == 1 + where(name: DEFAULT_WORKBENCH_NAME).last + end + private def initialize_output diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim index 05257a766..7f78934a6 100644 --- a/app/views/dashboards/_dashboard.html.slim +++ b/app/views/dashboards/_dashboard.html.slim @@ -14,25 +14,25 @@ - if workbench.referentials.present? .list-group - workbench.referentials.limit(5).each do |referential| - = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: workbench.id), class: 'list-group-item' + = link_to referential.name, referential_path(referential), class: 'list-group-item' - else .panel-body em.small.text-muted = t('workbenches.index.offers.no_content') - .panel.panel-default - .panel-heading - h3.panel-title.with_actions - = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(current_workgroup) - div - = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right' - - if @dashboard.current_organisation.calendars.present? - .list-group - - @dashboard.current_organisation.calendars.order("updated_at desc").limit(5).each do |calendar| - = link_to calendar.name, workgroup_calendars_path(current_workgroup, calendar), class: 'list-group-item' - - else - .panel-body - em.small.text-muted - = t('dasboard.calendars.none') + .panel.panel-default + .panel-heading + h3.panel-title.with_actions + = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(workbench.workgroup) + div + = link_to '', workgroup_calendars_path(workbench.workgroup), class: ' fa fa-chevron-right pull-right' + - if @dashboard.current_organisation.calendars.present? + .list-group + - @dashboard.current_organisation.calendars.order("updated_at desc").limit(5).each do |calendar| + = link_to calendar.name, workgroup_calendars_path(workbench.workgroup, calendar), class: 'list-group-item' + - else + .panel-body + em.small.text-muted + = t('dasboard.calendars.none') .col-lg-6.col-md-6.col-sm-6.col-xs-12 .panel.panel-default diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim index 1b7293d21..cb0698cf8 100644 --- a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim +++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim @@ -24,14 +24,14 @@ #miTwo.panel-collapse.collapse .list-group - - if current_user - = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do + - current_user.workbenches.each do |current_workbench| + = link_to workbench_path(current_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do span Jeux de données - = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do + = link_to workbench_imports_path(current_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do span Import - = link_to workgroup_calendars_path(current_workgroup), class: 'list-group-item' do + = link_to workgroup_calendars_path(current_workbench.workgroup), class: 'list-group-item' do span Modèles de calendrier - = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do + = link_to workbench_compliance_check_sets_path(current_workbench), class: 'list-group-item' do span Rapport de contrôle = link_to compliance_control_sets_path, class: 'list-group-item' do span Jeux de contrôle diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim index 9927f05bd..1e59ab566 100644 --- a/app/views/referentials/_form.html.slim +++ b/app/views/referentials/_form.html.slim @@ -1,4 +1,6 @@ -= simple_form_for @referential, html: {class: 'form-horizontal', id: 'referential_form'}, wrapper: :horizontal_form do |form| +- url = @referential.new_record? ? [@workbench, @referential] : [@referential] + += simple_form_for @referential, url: url, html: {class: 'form-horizontal', id: 'referential_form'}, wrapper: :horizontal_form do |form| .row .col-lg-12 diff --git a/app/views/referentials/select_compliance_control_set.html.slim b/app/views/referentials/select_compliance_control_set.html.slim index 87a888c0a..69c87aab2 100644 --- a/app/views/referentials/select_compliance_control_set.html.slim +++ b/app/views/referentials/select_compliance_control_set.html.slim @@ -2,7 +2,7 @@ .container-fluid .row .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 - = form_tag validate_referential_path(params[:referential_id]), {class: 'form-horizontal', id: 'select_compliance_control_set', wrapper: :horizontal_form} do + = form_tag validate_referential_path(@referential), {class: 'form-horizontal', id: 'select_compliance_control_set', wrapper: :horizontal_form} do .row .col-lg-12 .form-group diff --git a/app/views/stif/dashboards/_dashboard.html.slim b/app/views/stif/dashboards/_dashboard.html.slim index c28696a94..83a2106bb 100644 --- a/app/views/stif/dashboards/_dashboard.html.slim +++ b/app/views/stif/dashboards/_dashboard.html.slim @@ -47,7 +47,7 @@ - if @dashboard.referentials.present? .list-group - @dashboard.referentials.first(5).each_with_index do |referential, i| - = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: @dashboard.workbench.id), class: 'list-group-item' if i < 6 + = link_to referential.name, referential_path(referential), class: 'list-group-item' if i < 6 - else .panel-body @@ -60,12 +60,12 @@ span.badge.ml-xs = @dashboard.calendars.count if @dashboard.calendars.present? div - = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right', title: t('.see') + = link_to '', workgroup_calendars_path(@dashboard.workbench.workgroup), class: ' fa fa-chevron-right pull-right', title: t('.see') - if @dashboard.calendars.present? .list-group - @dashboard.calendars.first(5).each_with_index do |calendar, i| - = link_to calendar.name, workgroup_calendar_path(current_workgroup, calendar), class: 'list-group-item' if i < 6 + = link_to calendar.name, workgroup_calendar_path(@dashboard.workbench.workgroup, calendar), class: 'list-group-item' if i < 6 - else .panel-body diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index aae34c51b..159aa8ea2 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -5,7 +5,7 @@ .col-lg-12.text-right - if policy(Referential).create? = link_to t('actions.import'), workbench_imports_path(@workbench), class: 'btn btn-primary' - = link_to t('actions.add'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary' + = link_to t('actions.add'), new_workbench_referential_path(@workbench), class: 'btn btn-primary' = link_to t('workbenches.actions.show_output'), workbench_output_path(@workbench), class: 'btn btn-primary' .page_content @@ -25,7 +25,7 @@ key: :name, \ attribute: 'name', \ link_to: lambda do |referential| \ - referential_path(referential, current_workbench_id: params[:id]) \ + referential_path(referential) \ end \ ), \ TableBuilderHelper::Column.new( \ |
