diff options
| author | cedricnjanga | 2017-12-13 21:08:19 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-12-13 21:08:19 +0100 |
| commit | f5681428184d2cdc1dc49b4426da60101c107f35 (patch) | |
| tree | a42bf08d67f666138fffad366f21c13931eec672 | |
| parent | 7a78e65f6b765cced904c6214c3f48a16ca36261 (diff) | |
| parent | 3b291a73e977737cb8f6da7fce7f914504426b93 (diff) | |
| download | chouette-core-f5681428184d2cdc1dc49b4426da60101c107f35.tar.bz2 | |
Merge branch 'master' into staging
27 files changed, 62 insertions, 29 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 2f0ef1542..571c73f4a 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -135,6 +135,8 @@ class LinesController < ChouetteController :color, :text_color, :stable_id, + :transport_submode, + :secondary_company_ids => [], footnotes_attributes: [:code, :label, :_destroy, :id] ) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d2cdaaa20..124604cd9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,12 +3,20 @@ module ApplicationHelper include NewapplicationHelper + def array_to_html_list items + content_tag :ul do + items.each do |item| + concat content_tag :li, item + end + end + end + def page_header_title(object) # Unwrap from decorator, we want to know the object model name object = object.object if object.try(:object) local = "#{object.model_name.name.underscore.pluralize}.#{params[:action]}.title" if object.try(:name) - t(local, name: object.name) + t(local, name: object.name || object.id) else t(local) end diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index ddb54d615..ce4b9209d 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -162,7 +162,7 @@ const actions = { resetValidation: (target) => { $(target).parent().removeClass('has-error').children('.help-block').remove() }, - validateFields : (fields) => { + validateFields : (...fields) => { const test = [] Object.keys(fields).map(function(key) { @@ -457,10 +457,6 @@ const actions = { minute: actions.simplePad(newArrivalDT.getUTCMinutes()) } } - }, - escapeWildcardCharacters(search) { - let newSearch = search.replace(/^_/, "\\_") - return newSearch.replace(/^%/, "\\%") } } diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index 8fb4b8a7e..929cbc5c4 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -49,8 +49,8 @@ export default class VehicleJourney extends Component { return ( <div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.errors ? ' has-error': '')}> <div className='th'> - <div className='strong mb-xs'>{this.props.value.objectid ? this.props.value.short_id : '-'}</div> - <div>{this.props.value.journey_pattern.short_id}</div> + <div className='strong mb-xs'>{this.props.value.short_id || '-'}</div> + <div>{this.props.value.journey_pattern.short_id || '-'}</div> <div> {time_tables.slice(0,3).map((tt, i)=> <span key={i} className='vj_tt'>{this.timeTableURL(tt)}</span> diff --git a/app/javascript/vehicle_journeys/components/tools/CreateModal.js b/app/javascript/vehicle_journeys/components/tools/CreateModal.js index 2bffebdf6..33873219c 100644 --- a/app/javascript/vehicle_journeys/components/tools/CreateModal.js +++ b/app/javascript/vehicle_journeys/components/tools/CreateModal.js @@ -9,7 +9,7 @@ export default class CreateModal extends Component { } handleSubmit() { - if(actions.validateFields(this.refs) == true && this.props.modal.modalProps.selectedJPModal) { + if (actions.validateFields(...this.refs, $('.vjCreateSelectJP')[0]) && this.props.modal.modalProps.selectedJPModal) { this.props.onAddVehicleJourney(this.refs, this.props.modal.modalProps.selectedJPModal, this.props.stopPointsList, this.props.modal.modalProps.selectedCompany) this.props.onModalClose() $('#NewVehicleJourneyModal').modal('hide') diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index 7d91896eb..f8d6add03 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -97,6 +97,7 @@ export default class EditVehicleJourney extends Component { <div className='form-group'> <label className='control-label'>Transporteur</label> <CompanySelect2 + editModal={this.props.modal.type == "edit"} editMode={this.props.editMode} company = {this.props.modal.modalProps.vehicleJourney.company} onSelect2Company = {(e) => this.props.onSelect2Company(e)} diff --git a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js index fef3cdcc9..6629135dd 100644 --- a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js @@ -29,7 +29,7 @@ export default class TimetablesEditVehicleJourney extends Component { <li className='st_action'> <button type='button' - disabled={(actions.getSelected(this.props.vehicleJourneys).length != 1 || this.props.disabled)} + disabled={(actions.getSelected(this.props.vehicleJourneys).length < 1 || this.props.disabled)} data-toggle='modal' data-target='#CalendarsEditVehicleJourneyModal' onClick={() => this.props.onOpenCalendarsEditModal(actions.getSelected(this.props.vehicleJourneys))} @@ -56,7 +56,7 @@ export default class TimetablesEditVehicleJourney extends Component { <div className='wrapper'> <div> <div className='form-group'> - <label className='control-label'>Calendriers associés</label> + <label className='control-label'>{this.props.modal.modalProps.timetables.length == 0 ? "Aucun calendrier associé" : "Calendriers associés"}</label> </div> </div> <div></div> diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js index 0697e9141..79ba8f094 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js @@ -21,7 +21,7 @@ export default class BSelect4 extends Component { value={(this.props.company) ? this.props.company.name : undefined} onSelect={(e) => this.props.onSelect2Company(e) } onUnselect={() => this.props.onUnselect2Company()} - disabled={!this.props.editMode} + disabled={!this.props.editMode && this.props.editModal} multiple={false} ref='company_id' options={{ @@ -36,7 +36,7 @@ export default class BSelect4 extends Component { delay: '500', data: function(params) { return { - q: { name_cont: actions.escapeWildcardCharacters(params.term)}, + q: { name_cont: params.term}, }; }, processResults: function(data, params) { diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js index 5b4ae564c..fa847886c 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js @@ -21,6 +21,8 @@ export default class BSelect4 extends Component { onSelect={(e) => this.props.onSelect2JourneyPattern(e)} multiple={false} ref='journey_pattern_id' + className={!this.props.isFilter ? "vjCreateSelectJP" : null} + required={!this.props.isFilter} options={{ allowClear: false, theme: 'bootstrap', @@ -33,7 +35,7 @@ export default class BSelect4 extends Component { delay: '500', data: function(params) { return { - q: { published_name_or_objectid_or_registration_number_cont: actions.escapeWildcardCharacters(params.term)}, + q: { published_name_or_objectid_or_registration_number_cont: params.term}, }; }, processResults: function(data, params) { diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js index a90a9f7b8..19c183839 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js @@ -34,7 +34,7 @@ export default class BSelect4 extends Component { data: function(params) { return { q: { - comment_or_objectid_cont_any: actions.escapeWildcardCharacters(params.term) + comment_or_objectid_cont_any: params.term } }; }, diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js index 37628fce0..b063abeca 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js @@ -33,7 +33,7 @@ export default class BSelect4b extends Component { delay: '500', data: function(params) { return { - q: { objectid_cont: actions.escapeWildcardCharacters(params.term)}, + q: { objectid_cont: params.term}, }; }, processResults: function(data, params) { diff --git a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js index 775fefdca..136e1b41a 100644 --- a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js +++ b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js @@ -38,6 +38,7 @@ const vehicleJourney= (state = {}, action, keep) => { published_journey_name: action.data.published_journey_name.value, published_journey_identifier: action.data.published_journey_identifier.value, objectid: '', + short_id: '', footnotes: [], time_tables: [], vehicle_journey_at_stops: pristineVjasList, diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index 784e3f5b9..93d4f5e8b 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -72,7 +72,7 @@ module Chouette end def display_name - [self.get_objectid.local_id, number, name, company.try(:name)].compact.join(' - ') + [self.get_objectid.short_id, number, name, company.try(:name)].compact.join(' - ') end def companies diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb index cfcdfd1a6..e27f85ae0 100644 --- a/app/models/compliance_control_block.rb +++ b/app/models/compliance_control_block.rb @@ -12,4 +12,8 @@ class ComplianceControlBlock < ActiveRecord::Base validates :transport_mode, presence: true validates :compliance_control_set, presence: true + def name + ApplicationController.helpers.transport_mode_text(self) + end + end diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index bc8a3e24b..253917509 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -22,7 +22,7 @@ class ReferentialPolicy < ApplicationPolicy end def validate? - !archived? && create? + !archived? && create? && organisation_match? end def archive? diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index 851a4a41a..d915bbdaf 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -27,9 +27,8 @@ = render '/compliance_controls/filters' / compliance controls without block - - if @direct_compliance_controls.try(:any?) - = render_compliance_control_block - = render_compliance_controls(@direct_compliance_controls) + = render_compliance_control_block + = render_compliance_controls(@direct_compliance_controls) / compliance controls with block - if params[:q] && params[:q][:compliance_control_block_id_eq_any].try(:present?) diff --git a/app/views/lines/_form.html.slim b/app/views/lines/_form.html.slim index 4952b72ff..de0308289 100644 --- a/app/views/lines/_form.html.slim +++ b/app/views/lines/_form.html.slim @@ -4,6 +4,7 @@ = f.input :name = f.input :network_id, as: :select, :collection => @line_referential.networks, include_blank: false = f.input :company_id, as: :select, :collection => @line_referential.companies, include_blank: false + = f.input :secondary_company_ids, :collection => @line_referential.companies, include_blank: false, input_html: { multiple: true, 'data-select2ed': true }, label: t('activerecord.attributes.line.secondary_company') = f.input :published_name = f.input :registration_number = f.input :number diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim index 4969ca3cd..d62fe30d6 100644 --- a/app/views/lines/show.html.slim +++ b/app/views/lines/show.html.slim @@ -20,7 +20,7 @@ 'Activé' => (@line.deactivated? ? t('false') : t('true')), @line.human_attribute_name(:network_id) => (@line.network.nil? ? t('lines.index.unset') : @line.network.name), @line.human_attribute_name(:company_id) => (@line.company.nil? ? t('lines.index.unset') : @line.company.name), - 'Transporteur(s) secondaire(s)' => (@line.secondary_companies.nil? ? t('lines.index.unset') : @line.secondary_companies.collect(&:name).join(', ')), + 'Transporteur(s) secondaire(s)' => (@line.secondary_companies.nil? ? t('lines.index.unset') : array_to_html_list(@line.secondary_companies.collect(&:name))), 'Nom court' => @line.number, 'Code public' => (@line.registration_number ? @line.registration_number : '-'), @line.human_attribute_name(:transport_mode) => (@line.transport_mode.present? ? t("enumerize.transport_mode.#{@line.transport_mode}") : '-'), diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb index 970f933f0..eb285b731 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -82,8 +82,8 @@ crumb :import do |workbench, import| end crumb :import_resources do |import, import_resources| - link I18n.t('import_resources.index.title'), workbench_import_import_resources_path(import.workbench, import) - parent :import, import.workbench, import + link I18n.t('import_resources.index.title'), workbench_import_import_resources_path(import.workbench, import.parent) + parent :import, import.workbench, import.parent end crumb :organisation do |organisation| diff --git a/config/initializers/ransack.rb b/config/initializers/ransack.rb index 659ee4a79..09d895e47 100644 --- a/config/initializers/ransack.rb +++ b/config/initializers/ransack.rb @@ -4,6 +4,7 @@ Ransack.configure do |config| formatter: proc { |v| v.split(' to ') }, type: :string end + module Arel module Predications def between other @@ -11,3 +12,19 @@ module Arel end end end + +module Ransack + module Constants + module_function + # replace % \ to \% \\ + def escape_wildcards(unescaped) + case ActiveRecord::Base.connection.adapter_name + when "Mysql2".freeze, "PostgreSQL".freeze, "PostGIS".freeze + # Necessary for PostgreSQL and MySQL + unescaped.to_s.gsub(/([\\|\%|_|.])/, '\\\\\\1') + else + unescaped + end + end + end +end diff --git a/config/locales/compliance_control_blocks.en.yml b/config/locales/compliance_control_blocks.en.yml index 150157ff3..b9c01278c 100644 --- a/config/locales/compliance_control_blocks.en.yml +++ b/config/locales/compliance_control_blocks.en.yml @@ -17,7 +17,7 @@ fr: new: title: Create a control block edit: - title: "Edit the control block : %{compliance_control_block}" + title: "Edit the control block : %{name}" metas: control: zero: "No controls" diff --git a/config/locales/compliance_control_blocks.fr.yml b/config/locales/compliance_control_blocks.fr.yml index 1222b5c1a..a6720881f 100644 --- a/config/locales/compliance_control_blocks.fr.yml +++ b/config/locales/compliance_control_blocks.fr.yml @@ -17,7 +17,7 @@ fr: new: title: Créer un groupe de contrôle(s) edit: - title: "Editer le groupe de contrôle : %{compliance_control_block}" + title: "Editer le groupe de contrôle : %{name}" metas: control: zero: "Aucun contrôle" diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index a69c3b0ba..78d5c36be 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -66,6 +66,7 @@ en: networks: name: "Network" company_id: "Company" + secondary_company: "Secondary company" companies: name: "Company" registration_number: "Registration number" diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index 160cc4ab4..35f8792f4 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -67,6 +67,7 @@ fr: networks: name: "Réseau" company_id: "Transporteur principal" + secondary_company: "Transporteurs secondaires" companies: name: "Transporteur principal" registration_number: "Nom court" diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index 3959a5924..cbeaf2407 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -33,8 +33,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do expect_action_link_elements.to be_empty expect_action_link_hrefs.to eq([ referential_time_tables_path(object), - new_referential_path(from: object), - referential_select_compliance_control_set_path(object) + new_referential_path(from: object) ]) end end diff --git a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js index c02ab3398..1c2cc1577 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -106,6 +106,7 @@ describe('vehicleJourneys reducer', () => { company: fakeSelectedCompany, published_journey_name: 'test', published_journey_identifier: '', + short_id: '', objectid: '', footnotes: [], time_tables: [], diff --git a/spec/lib/compliance_control_set_cloner_spec.rb b/spec/lib/compliance_control_set_cloner_spec.rb index c17f0bb52..7efe27659 100644 --- a/spec/lib/compliance_control_set_cloner_spec.rb +++ b/spec/lib/compliance_control_set_cloner_spec.rb @@ -102,7 +102,7 @@ RSpec.describe ComplianceControlSetCloner do # Check correctly copied blocks target_blox.zip(source_blox).each do | target_block, source_block | expect( target_block.compliance_control_set ).to eq(target_set) - expect( target_block.name ).to eq( [block_prefix, source_block.name].join(' ') ) + expect( target_block.name ).to eq(source_block.name) expect( target_block.condition_attributes ).to eq( source_block.condition_attributes ) end |
