diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index d64232e..5a79fa0 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -174,10 +174,11 @@ def authenticate_user! end def entry_params - params.require(:entry).permit(:name, :email, :transport, :phone, :entry_type, :direction, :date, :location, :latitude, :longitude, :seats, :notes) + params.require(:entry).permit(:name, :email, :transport, :phone, :entry_type, :driver, + :direction, :date, :location, :latitude, :longitude, :seats, :notes) end def entry_update_params - params.require(:entry).permit(:name, :transport, :phone, :date, :location, :latitude, :longitude, :seats, :notes) + params.require(:entry).permit(:name, :transport, :phone, :date, :driver, :location, :latitude, :longitude, :seats, :notes) end end diff --git a/app/models/entry.rb b/app/models/entry.rb index 6965c17..a06cc8a 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -71,7 +71,7 @@ def self.ransackable_associations(auth_object = nil) def self.ransackable_attributes(auth_object = nil) ["confirmed_at", "created_at", "date", "direction", "email", "entry_type", "event_id", "id", "id_value", "transport", "longitude", "latitude", "location", - "name", "notes", "phone", "seats", "token", "locale", "updated_at"] + "driver", "name", "notes", "phone", "seats", "token", "locale", "updated_at"] end def create_id diff --git a/app/views/entries/_entry.html.haml b/app/views/entries/_entry.html.haml index f0c94fc..2191657 100644 --- a/app/views/entries/_entry.html.haml +++ b/app/views/entries/_entry.html.haml @@ -24,6 +24,15 @@ %b=entry.event.name → =entry.location + -if entry.transport.to_sym == :car && entry.driver? + %p + -if entry.is_offer? + %b + %i.bi.bi-exclamation-triangle + =t('driver-needed') + -else + %i.bi.bi-heart + =t('driver-offer') .col-12.col-md-2 =link_to t('entry_contact.title'), event_entry_path(entry.event, entry), class: 'btn btn-outline-primary btn-sm w-100', role: 'button' diff --git a/app/views/entries/_form.html.haml b/app/views/entries/_form.html.haml index 4e06e80..f5bb77c 100644 --- a/app/views/entries/_form.html.haml +++ b/app/views/entries/_form.html.haml @@ -24,10 +24,14 @@ blank: t('simple_form.labels.entry.transport'), label: t('simple_form.labels.entry.transport'), hint: t('simple_form.hints.entry.transport') + .collapse#carInputs + =f.input :driver, as: :boolean, + label: @entry.is_offer? ? t('simple_form.labels.entry.driver-needed') : t('simple_form.labels.entry.driver-offer'), + hint: @entry.is_offer? ? t('simple_form.hints.entry.driver-needed') : t('simple_form.hints.entry.driver-offer') + =f.input :seats, + hint: @entry.is_offer? ? t('simple_form.hints.entry.seats-available') : t('simple_form.hints.entry.seats-needed') =f.input :phone =f.input :location - =f.input :seats, - hint: @entry.is_offer? ? t('simple_form.hints.entry.seats-available') : t('simple_form.hints.entry.seats-needed') =f.input :date, as: :string, input_html: { value: @entry.date&.strftime('%d/%m/%Y %H:%M') } @@ -81,3 +85,26 @@ document.addEventListener('turbo:load', init_entry_timepicker); document.addEventListener('turbo:frame-load', init_entry_timepicker); + + init_collapse = () => { + const carInputsElement = document.getElementById('carInputs'); + const transportSelect = document.getElementById('entry_transport'); + + if (carInputsElement !== null && transportSelect !== null) { + const carInputsCollapse = new bootstrap.Collapse(carInputsElement, { toggle: false }); + + const callback = () => { + if (transportSelect.value === 'car') { + carInputsCollapse.show(); + } else { + carInputsCollapse.hide(); + } + }; + + transportSelect.addEventListener('change', callback); + callback(); + } + }; + + document.addEventListener('turbo:load', init_collapse); + document.addEventListener('turbo:frame-load', init_collapse); diff --git a/app/views/entries/popup.html.haml b/app/views/entries/popup.html.haml index 140498f..f597696 100644 --- a/app/views/entries/popup.html.haml +++ b/app/views/entries/popup.html.haml @@ -26,6 +26,16 @@ %i.bi.bi-arrow-right =@entry.location + -if @entry.transport.to_sym == :car && @entry.driver? + .col-12 + -if @entry.is_offer? + %b + %i.bi.bi-exclamation-triangle + =t('driver-needed') + -else + %i.bi.bi-heart + =t('driver-offer') + .col-12 =link_to t('entry_contact.title'), event_entry_path(@entry.event, @entry), class: 'btn btn-primary btn-sm w-100 mt-1', role: 'button' diff --git a/app/views/entries/show.html.haml b/app/views/entries/show.html.haml index 658c77b..4778ee4 100644 --- a/app/views/entries/show.html.haml +++ b/app/views/entries/show.html.haml @@ -29,6 +29,17 @@ %i.mx-1{class: icon_class_for_transport(@entry.transport)} =t("transport.#{@entry.transport}") + -if @entry.transport.to_sym == :car + -if @entry.driver? + %br + -if @entry.is_offer? + %b + %i.bi.bi-exclamation-triangle.mx-1 + =t('driver-needed') + -else + %i.bi.bi-heart.mx-1 + =t('driver-offer') + %tr -if @entry.is_way_there? %th=t('simple_form.labels.entry.starting-point') @@ -37,10 +48,6 @@ %td= @entry.location - %tr - %th= t('activerecord.fields.entry.seats') - %td= @entry.seats - %tr %th= t('activerecord.fields.entry.notes') %td= @entry.notes diff --git a/config/locales/de.yml b/config/locales/de.yml index e82e7ae..fd84411 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -98,6 +98,10 @@ de: way_there: Hinweg way_back: Rückweg + driver-needed: Für diese Fahrt wird ein:e Fahrer:in gesucht! + driver-offer: | + %{name} bietet an, das Auto zu fahren. + add_offer: title: Neues Angebot aufgeben offer_yourself: | @@ -296,6 +300,8 @@ de: starting-point: Start destination: Ziel seats: Anzahl der Plätze + driver-needed: Fahrer:in gesucht? + driver-offer: Kannst du fahren? notes: Zusätzliche Notizen contact_email: @@ -325,12 +331,12 @@ de: location: | Wo möchtest du starten bzw abgesetzt werden? Setze einen Marker auf der Karte, um einen Ort auszuwählen. - seats-available: | - Die Anzahl der verfügbaren Plätze. - Falls Du mit dem Fahrrad fährst oder zu Fuß gehst, ist dieses Feld optional. - seats-needed: | - Die Anzahl der benötigten Plätze. - Falls Du mit dem Fahrrad fährst oder zu Fuß gehst, ist dieses Feld optional. + seats-available: Die Anzahl der verfügbaren Plätze. + seats-needed: Die Anzahl der benötigten Plätze. + driver-needed: | + Wenn du nach einem Fahrer für diese Fahrt suchst, setze bitte dieses Häkchen. + driver-offer: | + Könntest du dir vorstellen, das Auto zu fahren? notes: Alle zusätzlichen Notizen, die du mit anderen teilen möchtest. contact_email: diff --git a/config/locales/en.yml b/config/locales/en.yml index f5a7dc1..adc38d7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -95,6 +95,10 @@ en: way_there: Way there way_back: Way back + driver-needed: This ride needs a driver! + driver-offer: | + %{name} offers to drive a car + no_entries: No entries yet. add_offer: @@ -278,6 +282,8 @@ en: starting-point: Start destination: Destination seats: Number of seats + driver-needed: Driver needed? + driver-offer: Offering to drive? notes: Additional notes contact_email: @@ -306,12 +312,13 @@ en: location: | The location where you want to start or where you want to go. You can put a marker on the map to select a location. - seats-available: | - The number of seats you have available. - In case you are going by bike or foot, you can leave this field empty. - seats-needed: | - The number of seats you need. - In case you are going by bike or foot, you can leave this field empty. + seats-available: The number of seats you have available. + seats-needed: The number of seats you need. + driver-needed: | + If you are looking for a driver for this ride, please check this box. + driver-offer: | + Would you offer to drive the car? Please check this box. + notes: Any additional notes you want to share with others. contact_email: diff --git a/config/locales/es.yml b/config/locales/es.yml index 6e502e8..3c04a17 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -96,6 +96,10 @@ es: way_there: Ida way_back: Vuelta + driver-needed: Este viaje busca un conductor + driver-offer: | + %{name} ofrece conducir un coche + add_offer: title: Agregar nueva oferta offer_yourself: | @@ -292,6 +296,8 @@ es: direction: Dirección location: Punto de partida o destino seats: Número de asientos + driver-needed: ¿Buscas conductor? + driver-offer: ¿Ofreces conducir? notes: Notas adicionales contact_email: @@ -324,10 +330,13 @@ es: destination: | ¿Dónde quieres ir o ser dejado? Coloca un marcador en el mapa para seleccionar un lugar. - seats-available: | - El número de asientos disponibles. - Si viajas en bicicleta o a pie, este campo es opcional. + seats-available: El número de asientos disponibles. seats-needed: El número de asientos necesarios. + driver-needed: | + Si buscas un conductor para este viaje, marca esta casilla. + driver-offer: | + Si ofreces conducir a otras personas, marca esta casilla. + notes: Cualquier nota adicional que quieras compartir con otros. contact_email: diff --git a/db/migrate/20240310090156_add_driver_to_entries.rb b/db/migrate/20240310090156_add_driver_to_entries.rb new file mode 100644 index 0000000..91690bd --- /dev/null +++ b/db/migrate/20240310090156_add_driver_to_entries.rb @@ -0,0 +1,5 @@ +class AddDriverToEntries < ActiveRecord::Migration[7.1] + def change + add_column :entries, :driver, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 303a863..d7588be 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_26_235410) do +ActiveRecord::Schema[7.1].define(version: 2024_03_10_090156) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace" t.text "body" @@ -64,6 +64,7 @@ t.string "locale" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "driver", default: false, null: false t.index ["event_id"], name: "index_entries_on_event_id" end diff --git a/db/seeds.rb b/db/seeds.rb index b982154..52cd8c6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -41,6 +41,7 @@ def random_european_coord latitude: random_coord[0], longitude: random_coord[1], seats: Faker::Number.between(from: 1, to: 4), + driver: Faker::Boolean.boolean, notes: Faker::Lorem.paragraph(sentence_count: 2), confirmed_at: Faker::Date.between(from: DateTime.now-1.month, to: DateTime.now) )