Skip to content

Commit

Permalink
Merged in CHOUETTE-3200-export-publish-a-given-sta (pull request #1513)
Browse files Browse the repository at this point in the history
CHOUETTE-3200 export with a given static range

Approved-by: Luc Donnet
  • Loading branch information
Guillaume Perot authored and Luc Donnet committed Dec 4, 2023
2 parents 0c9f8f1 + de7cf3a commit fb89b86
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 31 deletions.
4 changes: 3 additions & 1 deletion app/decorators/export_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class ExportDecorator < AF83::Decorator
end

define_instance_method :display_period do
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
Expand Down
9 changes: 4 additions & 5 deletions app/inputs/date_picker_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions app/inputs/time_picker_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/models/concerns/local_export_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion app/models/export/gtfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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
Expand All @@ -15,6 +17,16 @@ 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

validate :ensure_is_valid_period

def ensure_is_valid_period
return unless period == 'static_day_period'

if from.blank? || to.blank? || from > to
errors.add(:from, :invalid)
errors.add(:to, :invalid)
end
end

DEFAULT_AGENCY_ID = "chouette_default"
DEFAULT_TIMEZONE = "Etc/UTC"
Expand Down
15 changes: 14 additions & 1 deletion app/models/export/netex_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@ class Export::NetexGeneric < Export::Base

option :profile, enumerize: %w[none french european idfm/line idfm/full], default: :none
option :duration
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]
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
return unless period == 'static_day_period'

if from.blank? || to.blank? || 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
Expand Down
10 changes: 9 additions & 1 deletion app/packs/entrypoints/exports/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ class Store {
period = 'all_periods',
referentialId = '',
isExport = null,
duration = null
duration = null,
from = null,
to = null
} = {}) {
this.type = type
this.exportedLines = exportedLines
this.period = period
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'
Expand All @@ -26,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
Expand Down
1 change: 1 addition & 0 deletions app/packs/stylesheets/components/_on_off_switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
.onoffswitch-switch {
display: block;
width: 14px;
height: 14px;
margin: 4px;
background: $lightergrey;
position: absolute;
Expand Down
6 changes: 3 additions & 3 deletions app/views/exports/_form.html.slim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions app/views/exports/options/_period.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +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, label: false, input_html: { class: "simple_form_input_offset", 'x-bind:disabled': "period == 'all_periods'", 'x-model': 'duration' }
= 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' }
4 changes: 1 addition & 3 deletions app/views/sources/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions config/initializers/simple_form_bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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|
Expand Down
1 change: 1 addition & 0 deletions config/locales/enumerize.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config/locales/enumerize.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions config/locales/exports.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -105,6 +109,8 @@ en:
referential_id: Referential
referential: Referential
duration: Duration
from: From
to: To
exported_lines: Exported lines
profile: Profile
prefer_referent_stop_area: Prefer Referent Stop Areas
Expand Down
6 changes: 6 additions & 0 deletions config/locales/exports.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'période non valide'
to:
invalid: 'période non valide'
attributes:
attrs: &attrs
created_at: Créé le
Expand All @@ -107,6 +111,8 @@ fr:
referential: Jeu de données
options: Options
duration: Durée
from: De
to: Vers
exported_lines: Lignes exportées
profile: Profil
prefer_referent_stop_area: Préférer les arrêts Référents
Expand Down

0 comments on commit fb89b86

Please sign in to comment.