From ba676c12b9a5d6811a1f5c75bfcdb6483d1c8af5 Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Mon, 13 Nov 2023 16:16:45 +0100 Subject: [PATCH 1/7] CHOUETTE-3200 - add new option to select static date on export form --- app/lib/time_of_day.rb | 14 ++++++++++++++ app/models/export/gtfs.rb | 9 ++++++++- app/models/export/netex_generic.rb | 4 +++- app/packs/entrypoints/exports/form.js | 6 +++++- app/views/exports/options/_period.html.slim | 6 +++++- config/locales/enumerize.en.yml | 1 + config/locales/enumerize.fr.yml | 1 + config/locales/exports.en.yml | 2 ++ config/locales/exports.fr.yml | 2 ++ 9 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/lib/time_of_day.rb b/app/lib/time_of_day.rb index cd05d24497..35ec8c392e 100644 --- a/app/lib/time_of_day.rb +++ b/app/lib/time_of_day.rb @@ -266,5 +266,19 @@ def changed_in_place?(raw_old_value, new_value) raw_old_value != serialize(new_value) end end + + class DatePicker < ActiveRecord::Type::Value + def cast(value) + return unless value.present? + + value.to_date + end + + def serialize(value) + return unless value.present? + + value.to_date + end + end end end diff --git a/app/models/export/gtfs.rb b/app/models/export/gtfs.rb index c733cf8154..21f45940aa 100644 --- a/app/models/export/gtfs.rb +++ b/app/models/export/gtfs.rb @@ -3,8 +3,10 @@ class Export::Gtfs < Export::Base include LocalExportSupport - option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days] + option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days static_day_period] option :duration + option :from, serialize: TimeOfDay::Type::DatePicker + option :to, serialize: TimeOfDay::Type::DatePicker option :exported_lines, default_value: 'all_line_ids', enumerize: %w[line_ids company_ids line_provider_ids all_line_ids] option :line_ids, serialize: :map_ids option :company_ids, serialize: :map_ids @@ -15,6 +17,11 @@ class Export::Gtfs < Export::Base option :prefer_referent_company, required: true, default_value: false, enumerize: [true, false], serialize: ActiveModel::Type::Boolean option :ignore_parent_stop_places, required: true, default_value: false, enumerize: [true, false], serialize: ActiveModel::Type::Boolean + %w[from to].each do |option| + define_method "#{option}=" do |value| + value.to_date if value + end + end DEFAULT_AGENCY_ID = "chouette_default" DEFAULT_TIMEZONE = "Etc/UTC" diff --git a/app/models/export/netex_generic.rb b/app/models/export/netex_generic.rb index 4c0f4ace97..0672e872a2 100644 --- a/app/models/export/netex_generic.rb +++ b/app/models/export/netex_generic.rb @@ -3,10 +3,12 @@ class Export::NetexGeneric < Export::Base option :profile, enumerize: %w[none french european idfm/line idfm/full], default: :none option :duration + option :from + option :to option :line_ids, serialize: :map_ids option :company_ids, serialize: :map_ids option :line_provider_ids, serialize: :map_ids - option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days] + option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days static_day_period] option :exported_lines, default_value: 'all_line_ids', enumerize: %w[line_ids company_ids line_provider_ids all_line_ids] def target diff --git a/app/packs/entrypoints/exports/form.js b/app/packs/entrypoints/exports/form.js index f4ae7137b6..75f4d5b44b 100644 --- a/app/packs/entrypoints/exports/form.js +++ b/app/packs/entrypoints/exports/form.js @@ -8,7 +8,9 @@ class Store { period = 'all_periods', referentialId = '', isExport = null, - duration = null + duration = null, + from = null, + to = null } = {}) { this.type = type this.exportedLines = exportedLines @@ -16,6 +18,8 @@ class Store { this.referentialId = referentialId this.isExport = isExport this.duration = duration + this.from = from + this.to = to this.workbenchOrWorkgroupId = location.pathname.match(/(\d+)/)[0] this.exportedLinesSelectURL = '' this.exportType = isExport ? null : 'full' diff --git a/app/views/exports/options/_period.html.slim b/app/views/exports/options/_period.html.slim index 4ef5cde4b9..365ae2b560 100644 --- a/app/views/exports/options/_period.html.slim +++ b/app/views/exports/options/_period.html.slim @@ -2,4 +2,8 @@ = form.input :period, as: :radio_buttons, required: true, wrapper: :horizontal_form, input_html: { 'x-model': 'period' } .form-group .col-sm-4.col-xs-5 - = form.input :duration, wrapper: false, legend_tag: false, label: false, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods'", 'x-model': 'duration' } + = form.input :duration, wrapper: false, legend_tag: false, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'static_day_period'", 'x-model': 'duration' } +.form-group + .col-sm-4.col-xs-5 + = form.input :from, as: :date_picker, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'from' } + = form.input :to, as: :date_picker, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'to' } diff --git a/config/locales/enumerize.en.yml b/config/locales/enumerize.en.yml index 0df64df386..ef3b4f208f 100644 --- a/config/locales/enumerize.en.yml +++ b/config/locales/enumerize.en.yml @@ -370,6 +370,7 @@ en: period: all_periods: All available period only_next_days: Only next days + static_day_period: Static day period profile: none: None french: French (beta) diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index 8f4682503d..8e44e72024 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -370,6 +370,7 @@ fr: period: all_periods: Toute la période disponible only_next_days: Seulement les jours suivants + static_day_period: Période statique profile: none: Aucun french: France (beta) diff --git a/config/locales/exports.en.yml b/config/locales/exports.en.yml index 2470f51912..692dad4f08 100644 --- a/config/locales/exports.en.yml +++ b/config/locales/exports.en.yml @@ -105,6 +105,8 @@ en: referential_id: Referential referential: Referential duration: Duration + from: Valid after + to: Valid until exported_lines: Exported lines profile: Profile prefer_referent_stop_area: Prefer Referent Stop Areas diff --git a/config/locales/exports.fr.yml b/config/locales/exports.fr.yml index 48442ca7ae..148d63d6b3 100644 --- a/config/locales/exports.fr.yml +++ b/config/locales/exports.fr.yml @@ -107,6 +107,8 @@ fr: referential: Jeu de données options: Options duration: Durée + from: Valide à partir de + to: Valide jusqu'au exported_lines: Lignes exportées profile: Profil prefer_referent_stop_area: Préférer les arrêts Référents From bfdebdb3ebac35dc971b8d7a232960577c8059d8 Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Thu, 16 Nov 2023 14:52:43 +0100 Subject: [PATCH 2/7] CHOUETTE-3200 - update export form/show (use new wrapper), rewrite date/time_picker input style (tailwind), add validation and serialize type for from/to options, update simple form wrappers styles --- app/decorators/export_decorator.rb | 2 ++ app/inputs/date_picker_input.rb | 9 ++++----- app/inputs/time_picker_input.rb | 7 +++---- app/lib/time_of_day.rb | 14 -------------- app/models/export/gtfs.rb | 13 ++++++++----- app/models/export/netex_generic.rb | 13 +++++++++++-- app/packs/entrypoints/exports/form.js | 4 ++++ .../stylesheets/components/_on_off_switch.scss | 1 + app/views/exports/_form.html.slim | 6 +++--- app/views/exports/_show.html.slim | 2 ++ app/views/exports/options/_period.html.slim | 14 ++++++-------- app/views/sources/_form.html.slim | 4 +--- config/initializers/simple_form_bootstrap.rb | 15 +++++++++------ config/locales/exports.en.yml | 4 ++-- config/locales/exports.fr.yml | 8 ++++++-- 15 files changed, 62 insertions(+), 54 deletions(-) diff --git a/app/decorators/export_decorator.rb b/app/decorators/export_decorator.rb index 7844873ea6..827ad180b8 100644 --- a/app/decorators/export_decorator.rb +++ b/app/decorators/export_decorator.rb @@ -31,6 +31,8 @@ class ExportDecorator < AF83::Decorator end define_instance_method :display_period do + return I18n.t('enumerize.period.static_day_period') if from.present? && to.present? + duration.present? ? "#{I18n.t('enumerize.period.only_next_days')} : #{duration}" : I18n.t('enumerize.period.all_periods') end diff --git a/app/inputs/date_picker_input.rb b/app/inputs/date_picker_input.rb index d14658ded2..beded5541a 100644 --- a/app/inputs/date_picker_input.rb +++ b/app/inputs/date_picker_input.rb @@ -7,12 +7,11 @@ def input(wrapper_options) # Never update the code before read https://flatpickr.js.org/examples/#flatpickr--external-elements input_html_options[:type] = 'text' input_html_options[:data] = { 'input': ''} - input_html_options[:style] = 'background-color: white;' input_html_options[:value] ||= I18n.localize(value, format: display_pattern) if value - content_tag(:div, class: 'date_picker_block input-group') do + content_tag(:div, class: 'date_picker_block flex') do concat @builder.text_field(attribute_name, input_html_options) - concat( content_tag(:div, class: 'input-group-btn') do + concat( content_tag(:div, class: 'flex items-center bg-enroute-blue rounded-tr-full rounded-br-full') do concat calendar_button concat clear_button end) @@ -21,13 +20,13 @@ def input(wrapper_options) end def input_html_classes - super.push 'form-control' + super.push 'border border-gray-300 rounded-tl rounded-bl w-full py-4 px-3 focus:outline-none focus:ring-0 focus:border-blue-500 leading-6 transition-colors duration-200 ease-in-out string optional' end private def clear_button - content_tag(:a, title: "clear", class: 'btn btn-default', 'data-clear': "") do + content_tag(:a, title: "clear", class: 'btn btn-default ml-0', 'data-clear': "") do concat content_tag(:i, "", class: 'fas fa-times') end end diff --git a/app/inputs/time_picker_input.rb b/app/inputs/time_picker_input.rb index 108be0721b..7789210e78 100644 --- a/app/inputs/time_picker_input.rb +++ b/app/inputs/time_picker_input.rb @@ -7,18 +7,17 @@ def input # Never update the code before read https://flatpickr.js.org/examples/#flatpickr--external-elements input_html_options[:type] = 'text' input_html_options[:data] ||= { 'input': ''} - input_html_options[:style] = 'background-color: white;' - content_tag(:div, class: 'time_picker_block input-group') do + content_tag(:div, class: 'time_picker_block flex') do concat @builder.text_field(attribute_name, input_html_options) - concat( content_tag(:div, class: 'input-group-btn') do + concat( content_tag(:div, class: 'flex items-center bg-enroute-blue rounded-tr-full rounded-br-full') do concat clock_button end) end end def input_html_classes - super.push 'form-control' + super.push 'border border-gray-300 rounded-tl rounded-bl w-full py-4 px-3 focus:outline-none focus:ring-0 focus:border-blue-500 leading-6 transition-colors duration-200 ease-in-out string optional' end private diff --git a/app/lib/time_of_day.rb b/app/lib/time_of_day.rb index 35ec8c392e..cd05d24497 100644 --- a/app/lib/time_of_day.rb +++ b/app/lib/time_of_day.rb @@ -266,19 +266,5 @@ def changed_in_place?(raw_old_value, new_value) raw_old_value != serialize(new_value) end end - - class DatePicker < ActiveRecord::Type::Value - def cast(value) - return unless value.present? - - value.to_date - end - - def serialize(value) - return unless value.present? - - value.to_date - end - end end end diff --git a/app/models/export/gtfs.rb b/app/models/export/gtfs.rb index 21f45940aa..67384bb655 100644 --- a/app/models/export/gtfs.rb +++ b/app/models/export/gtfs.rb @@ -5,8 +5,8 @@ class Export::Gtfs < Export::Base option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days static_day_period] option :duration - option :from, serialize: TimeOfDay::Type::DatePicker - option :to, serialize: TimeOfDay::Type::DatePicker + option :from, serialize: ActiveModel::Type::Date + option :to, serialize: ActiveModel::Type::Date option :exported_lines, default_value: 'all_line_ids', enumerize: %w[line_ids company_ids line_provider_ids all_line_ids] option :line_ids, serialize: :map_ids option :company_ids, serialize: :map_ids @@ -17,9 +17,12 @@ class Export::Gtfs < Export::Base option :prefer_referent_company, required: true, default_value: false, enumerize: [true, false], serialize: ActiveModel::Type::Boolean option :ignore_parent_stop_places, required: true, default_value: false, enumerize: [true, false], serialize: ActiveModel::Type::Boolean - %w[from to].each do |option| - define_method "#{option}=" do |value| - value.to_date if value + validate :ensure_is_valid_period + + def ensure_is_valid_period + if from > to + errors.add(:from, :invalid) + errors.add(:to, :invalid) end end diff --git a/app/models/export/netex_generic.rb b/app/models/export/netex_generic.rb index 0672e872a2..90c4615d54 100644 --- a/app/models/export/netex_generic.rb +++ b/app/models/export/netex_generic.rb @@ -3,14 +3,23 @@ class Export::NetexGeneric < Export::Base option :profile, enumerize: %w[none french european idfm/line idfm/full], default: :none option :duration - option :from - option :to + option :from, serialize: ActiveModel::Type::Date + option :to, serialize: ActiveModel::Type::Date option :line_ids, serialize: :map_ids option :company_ids, serialize: :map_ids option :line_provider_ids, serialize: :map_ids option :period, default_value: 'all_periods', enumerize: %w[all_periods only_next_days static_day_period] option :exported_lines, default_value: 'all_line_ids', enumerize: %w[line_ids company_ids line_provider_ids all_line_ids] + validate :ensure_is_valid_period + + def ensure_is_valid_period + if from > to + errors.add(:from, :invalid) + errors.add(:to, :invalid) + end + end + def target @target ||= Netex::Target.build export_file, profile: netex_profile, validity_periods: [export_scope.validity_period] end diff --git a/app/packs/entrypoints/exports/form.js b/app/packs/entrypoints/exports/form.js index 75f4d5b44b..8e5d14e0ef 100644 --- a/app/packs/entrypoints/exports/form.js +++ b/app/packs/entrypoints/exports/form.js @@ -30,6 +30,10 @@ class Store { init() { this.$watch('referentialId', () => this.handleReferentialIdUpdate()) + this.$watch('type', () => flatpickr('.date_picker_block', { + dateFormat: "d/m/Y", + wrap: true + })) } /* Used in app/views/exports/options/_exported_lines.html.slim as x-bind:data-url diff --git a/app/packs/stylesheets/components/_on_off_switch.scss b/app/packs/stylesheets/components/_on_off_switch.scss index 8bd6846fe6..ade9cda287 100644 --- a/app/packs/stylesheets/components/_on_off_switch.scss +++ b/app/packs/stylesheets/components/_on_off_switch.scss @@ -49,6 +49,7 @@ .onoffswitch-switch { display: block; width: 14px; + height: 14px; margin: 4px; background: $lightergrey; position: absolute; diff --git a/app/views/exports/_form.html.slim b/app/views/exports/_form.html.slim index ea53613782..2366e37a46 100644 --- a/app/views/exports/_form.html.slim +++ b/app/views/exports/_form.html.slim @@ -1,5 +1,5 @@ - javascript_additional_packs 'exports/form' -= simple_form_for @export, as: :export, url: workbench_exports_path(workbench), html: {class: 'form-horizontal', id: 'wb_export_form', 'x-data': "exportForm(#{@export.alpine_state(true)})" }, wrapper: :horizontal_form do |form| += simple_form_for @export, as: :export, url: workbench_exports_path(workbench), html: {class: 'tailwind-form', id: 'wb_export_form', 'x-data': "exportForm(#{@export.alpine_state(true)})" }, wrapper: :horizontal_form_tailwind do |form| .row .col-lg-12 @@ -11,8 +11,8 @@ as: :tom_select, collection: @referential_options, label_method: :name, - input_html: { 'x-model': 'referentialId' } - + input_html: { 'x-model': 'referentialId', class: "w-full" } + = render 'exports/options', form: form, resource_type: :options, workgroup: @workbench.workgroup .col-lg-12 diff --git a/app/views/exports/_show.html.slim b/app/views/exports/_show.html.slim index 706de8c648..e5fcbae86c 100644 --- a/app/views/exports/_show.html.slim +++ b/app/views/exports/_show.html.slim @@ -7,6 +7,8 @@ - if @export.type != "Export::Netex" = d.attribute :exported_lines, value_method: :display_selected_lines_to_export = d.attribute :period, value_method: :display_period + = d.attribute :from, as: :date + = d.attribute :to, as: :date - if @export.type == "Export::NetexGeneric" = d.attribute :profile, value_method: :display_profile - if @export.type == "Export::Gtfs" diff --git a/app/views/exports/options/_period.html.slim b/app/views/exports/options/_period.html.slim index 365ae2b560..896548999e 100644 --- a/app/views/exports/options/_period.html.slim +++ b/app/views/exports/options/_period.html.slim @@ -1,9 +1,7 @@ -= form.input :period, as: :radio_buttons, required: true, wrapper: :horizontal_form, input_html: { 'x-model': 'period' } -.form-group - .col-sm-4.col-xs-5 - = form.input :duration, wrapper: false, legend_tag: false, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'static_day_period'", 'x-model': 'duration' } -.form-group - .col-sm-4.col-xs-5 - = form.input :from, as: :date_picker, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'from' } - = form.input :to, as: :date_picker, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'to' } += form.input :period, as: :radio_buttons, required: true, wrapper: :vertical_radio_and_checkboxes_tailwind, input_html: { 'x-model': 'period' } +div[x-bind:class="{ 'opacity-50': period == 'all_periods' || period == 'static_day_period' }" ] + = form.input :duration, legend_tag: false, input_html: { 'x-bind:disabled': "period == 'all_periods' || period == 'static_day_period'", 'x-model': 'duration' } +div[x-bind:class="{ 'opacity-50': period == 'all_periods' || period == 'only_next_days' }" ] + = form.input :from, as: :date_picker, input_html: { 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'from' } + = form.input :to, as: :date_picker, input_html: { 'x-bind:disabled': "period == 'all_periods' || period == 'only_next_days'", 'x-model': 'to' } diff --git a/app/views/sources/_form.html.slim b/app/views/sources/_form.html.slim index ff0181962c..fa42995620 100644 --- a/app/views/sources/_form.html.slim +++ b/app/views/sources/_form.html.slim @@ -16,9 +16,7 @@ = t("sources.form.sections.retrieval") .simple-separator.mb-5 .col-lg-12 x-data="{ retrieval_frequency: '#{@source.retrieval_frequency}' }" - .flex.items-center.mb-10 - = f.label :retrieval_frequency, class: 'flex justify-end w-2/6 mr-8 mb-0 control-label pt-0' - = f.input :retrieval_frequency, as: :radio_buttons, label: false, wrapper: :vertical_radio_and_checkboxes_tailwind, input_html: { "x-model" => "retrieval_frequency" } + = f.input :retrieval_frequency, as: :radio_buttons, wrapper: :vertical_radio_and_checkboxes_tailwind, input_html: { "x-model" => "retrieval_frequency" } = f.input :retrieval_time_of_day, as: :time_of_day, input_html: { "x-bind:disabled" => "retrieval_frequency != 'daily'" } .flex.items-center.mb-10 = f.label :retrieval_days_of_week, class: "flex justify-end w-2/6 mr-8 mb-0 control-label pt-0 required" diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index fa0a4e0f02..fef5fcff29 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -211,7 +211,7 @@ b.optional :pattern b.optional :min_max b.optional :readonly - b.use :label, class: 'flex justify-end w-2/6 mr-8 mb-0 control-label pt-0' + b.use :label, class: 'flex justify-end text-right w-2/6 mr-8 mb-0 control-label pt-0' b.wrapper tag: 'div', class: 'w-4/6 flex items-center relative' do |ba| ba.use :input, class: 'form-control' @@ -220,13 +220,16 @@ end end - config.wrappers :vertical_radio_and_checkboxes_tailwind, tag: 'div', class: 'flex flex-col', error_class: 'has-error' do |b| + config.wrappers :vertical_radio_and_checkboxes_tailwind, tag: 'div', class: 'flex items-center mb-10', error_class: 'has-error' do |b| b.use :html5 b.optional :readonly - b.use :label, class: 'control-label' - b.use :input, class: 'cursor-pointer' - b.use :error, wrap_with: { tag: 'span', class: 'help-block small' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block small' } + b.use :label, class: 'flex justify-end w-2/6 mr-8 mb-0 control-label pt-0' + + b.wrapper tag: 'div', class: 'w-4/6 flex flex-col relative' do |ba| + ba.use :input, class: 'cursor-pointer' + ba.use :error, wrap_with: { tag: 'span', class: 'help-block small absolute top-14 ml-2' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block small absolute top-14 ml-2' } + end end config.wrappers :horizontal_boolean_tailwind, tag: 'div', class: '', error_class: 'has-error' do |b| diff --git a/config/locales/exports.en.yml b/config/locales/exports.en.yml index 692dad4f08..015e28a704 100644 --- a/config/locales/exports.en.yml +++ b/config/locales/exports.en.yml @@ -105,8 +105,8 @@ en: referential_id: Referential referential: Referential duration: Duration - from: Valid after - to: Valid until + from: From + to: To exported_lines: Exported lines profile: Profile prefer_referent_stop_area: Prefer Referent Stop Areas diff --git a/config/locales/exports.fr.yml b/config/locales/exports.fr.yml index 148d63d6b3..8871f2c004 100644 --- a/config/locales/exports.fr.yml +++ b/config/locales/exports.fr.yml @@ -83,6 +83,10 @@ fr: wrong_file_extension: "Le fichier exporté doit être au format zip" options: not_supported: L'option %{name} n'est pas valide pour ce type d'export + from: + invalid: 'invalid from period' + to: + invalid: 'invalid to period' attributes: attrs: &attrs created_at: Créé le @@ -107,8 +111,8 @@ fr: referential: Jeu de données options: Options duration: Durée - from: Valide à partir de - to: Valide jusqu'au + from: De + to: Vers exported_lines: Lignes exportées profile: Profil prefer_referent_stop_area: Préférer les arrêts Référents From 824823b9602a012b58617e6ee868365ee4626eaa Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Tue, 21 Nov 2023 15:59:48 +0100 Subject: [PATCH 3/7] CHOUETTE-3200 - test condition if exist (fix specs) --- app/models/export/gtfs.rb | 1 + app/models/export/netex_generic.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/export/gtfs.rb b/app/models/export/gtfs.rb index 67384bb655..de5e927b59 100644 --- a/app/models/export/gtfs.rb +++ b/app/models/export/gtfs.rb @@ -20,6 +20,7 @@ class Export::Gtfs < Export::Base validate :ensure_is_valid_period def ensure_is_valid_period + return unless from || to if from > to errors.add(:from, :invalid) errors.add(:to, :invalid) diff --git a/app/models/export/netex_generic.rb b/app/models/export/netex_generic.rb index 90c4615d54..685463eba9 100644 --- a/app/models/export/netex_generic.rb +++ b/app/models/export/netex_generic.rb @@ -14,6 +14,7 @@ class Export::NetexGeneric < Export::Base validate :ensure_is_valid_period def ensure_is_valid_period + return unless from || to if from > to errors.add(:from, :invalid) errors.add(:to, :invalid) From 0233f7f670691cc80fdcb81c9a984c7a1514373c Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Tue, 28 Nov 2023 16:53:54 +0100 Subject: [PATCH 4/7] CHOUETTE-3200 - add new attribute from to feed_info start_date (gtfs export), update validate period conditions --- app/models/export/gtfs.rb | 14 +++++++++----- app/models/export/netex_generic.rb | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/models/export/gtfs.rb b/app/models/export/gtfs.rb index de5e927b59..5c19b753b0 100644 --- a/app/models/export/gtfs.rb +++ b/app/models/export/gtfs.rb @@ -20,8 +20,9 @@ class Export::Gtfs < Export::Base validate :ensure_is_valid_period def ensure_is_valid_period - return unless from || to - if from > to + return unless period == 'static_day_period' + + if from.blank? || to.blank? || from > to errors.add(:from, :invalid) errors.add(:to, :invalid) end @@ -1353,9 +1354,10 @@ def is_operator class FeedInfo < Part delegate :companies, :validity_period, to: :export_scope + delegate :from, to: :export def export! - target.feed_infos << Decorator.new(company: company, validity_period: validity_period).feed_info_attributes + target.feed_infos << Decorator.new(company: company, validity_period: validity_period, from: from).feed_info_attributes end def company @@ -1363,11 +1365,12 @@ def company end class Decorator - attr_reader :company, :validity_period + attr_reader :company, :validity_period, :from - def initialize(company:, validity_period:) + def initialize(company:, validity_period:, from:) @company = company @validity_period = validity_period + @from = from end def feed_info_attributes @@ -1381,6 +1384,7 @@ def feed_info_attributes end def start_date + return from if from.present? validity_period&.min end diff --git a/app/models/export/netex_generic.rb b/app/models/export/netex_generic.rb index 685463eba9..0180f9dd8e 100644 --- a/app/models/export/netex_generic.rb +++ b/app/models/export/netex_generic.rb @@ -14,8 +14,9 @@ class Export::NetexGeneric < Export::Base validate :ensure_is_valid_period def ensure_is_valid_period - return unless from || to - if from > to + return unless period == 'static_day_period' + + if from.blank? || to.blank? || from > to errors.add(:from, :invalid) errors.add(:to, :invalid) end From 5ff2e7c3e6be0a20bc4ae677efcc5f854451c818 Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Wed, 29 Nov 2023 10:59:02 +0100 Subject: [PATCH 5/7] CHOUETTE-3200 - rollback modifications (gtfs feedInfos), update date_range method to take new static_day_period option (local_export_support) --- app/models/concerns/local_export_support.rb | 7 +++++-- app/models/export/gtfs.rb | 9 +++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/local_export_support.rb b/app/models/concerns/local_export_support.rb index 54afd8dc0e..d01d61c463 100644 --- a/app/models/concerns/local_export_support.rb +++ b/app/models/concerns/local_export_support.rb @@ -16,8 +16,11 @@ def skip_empty_exports? end def date_range - return nil if duration.nil? - @date_range ||= Time.now.to_date..self.duration.to_i.days.from_now.to_date + @date_range ||= if duration.present? + Time.now.to_date..self.duration.to_i.days.from_now.to_date + elsif period == 'static_day_period' && from.present? && to.present? + from..to + end end def export_type diff --git a/app/models/export/gtfs.rb b/app/models/export/gtfs.rb index 5c19b753b0..021a109d7a 100644 --- a/app/models/export/gtfs.rb +++ b/app/models/export/gtfs.rb @@ -1354,10 +1354,9 @@ def is_operator class FeedInfo < Part delegate :companies, :validity_period, to: :export_scope - delegate :from, to: :export def export! - target.feed_infos << Decorator.new(company: company, validity_period: validity_period, from: from).feed_info_attributes + target.feed_infos << Decorator.new(company: company, validity_period: validity_period).feed_info_attributes end def company @@ -1365,12 +1364,11 @@ def company end class Decorator - attr_reader :company, :validity_period, :from + attr_reader :company, :validity_period - def initialize(company:, validity_period:, from:) + def initialize(company:, validity_period:) @company = company @validity_period = validity_period - @from = from end def feed_info_attributes @@ -1384,7 +1382,6 @@ def feed_info_attributes end def start_date - return from if from.present? validity_period&.min end From 27a440aed9756d47a5e7b5e3404cae013a9b601c Mon Sep 17 00:00:00 2001 From: Guillaume Perot Date: Wed, 29 Nov 2023 11:05:55 +0100 Subject: [PATCH 6/7] CHOUETTE-3200 - update i18n errors --- config/locales/exports.en.yml | 4 ++++ config/locales/exports.fr.yml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/locales/exports.en.yml b/config/locales/exports.en.yml index 015e28a704..fc95cc2c15 100644 --- a/config/locales/exports.en.yml +++ b/config/locales/exports.en.yml @@ -82,6 +82,10 @@ en: wrong_file_extension: "The exported file must be a zip file" options: not_supported: "%{name} option is valid afor this export type" + from: + invalid: 'invalid period' + to: + invalid: 'invalid period' attributes: attrs: &attrs created_at: Created at diff --git a/config/locales/exports.fr.yml b/config/locales/exports.fr.yml index 8871f2c004..cdf32148f9 100644 --- a/config/locales/exports.fr.yml +++ b/config/locales/exports.fr.yml @@ -84,9 +84,9 @@ fr: options: not_supported: L'option %{name} n'est pas valide pour ce type d'export from: - invalid: 'invalid from period' + invalid: 'période non valide' to: - invalid: 'invalid to period' + invalid: 'période non valide' attributes: attrs: &attrs created_at: Créé le From de7cf3a910c0114e89fe0aeac2a1520fc1ad0e7e Mon Sep 17 00:00:00 2001 From: Luc Date: Mon, 4 Dec 2023 20:51:07 +0100 Subject: [PATCH 7/7] CHOUETTE-3200 Use display period to display from and to in export show page --- app/decorators/export_decorator.rb | 6 +++--- app/views/exports/_show.html.slim | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/decorators/export_decorator.rb b/app/decorators/export_decorator.rb index 827ad180b8..aed487f380 100644 --- a/app/decorators/export_decorator.rb +++ b/app/decorators/export_decorator.rb @@ -31,9 +31,9 @@ class ExportDecorator < AF83::Decorator end define_instance_method :display_period do - return I18n.t('enumerize.period.static_day_period') if from.present? && to.present? - - duration.present? ? "#{I18n.t('enumerize.period.only_next_days')} : #{duration}" : I18n.t('enumerize.period.all_periods') + return "#{I18n.l(from, format: :default)} - #{I18n.l(to, format: :default)}" if from.present? && to.present? + return "#{I18n.t('enumerize.period.only_next_days')} : #{duration}" if duration.present? + I18n.t('enumerize.period.all_periods') end define_instance_method :display_profile do diff --git a/app/views/exports/_show.html.slim b/app/views/exports/_show.html.slim index e5fcbae86c..706de8c648 100644 --- a/app/views/exports/_show.html.slim +++ b/app/views/exports/_show.html.slim @@ -7,8 +7,6 @@ - if @export.type != "Export::Netex" = d.attribute :exported_lines, value_method: :display_selected_lines_to_export = d.attribute :period, value_method: :display_period - = d.attribute :from, as: :date - = d.attribute :to, as: :date - if @export.type == "Export::NetexGeneric" = d.attribute :profile, value_method: :display_profile - if @export.type == "Export::Gtfs"