Skip to content

Commit

Permalink
Add clean driver function
Browse files Browse the repository at this point in the history
  • Loading branch information
zonque committed Mar 10, 2024
1 parent e1f42ca commit 8eeae31
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 25 deletions.
5 changes: 3 additions & 2 deletions app/controllers/entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/views/entries/_entry.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
31 changes: 29 additions & 2 deletions app/views/entries/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down Expand Up @@ -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);
10 changes: 10 additions & 0 deletions app/views/entries/popup.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

15 changes: 11 additions & 4 deletions app/views/entries/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
18 changes: 12 additions & 6 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240310090156_add_driver_to_entries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDriverToEntries < ActiveRecord::Migration[7.1]
def change
add_column :entries, :driver, :boolean, null: false, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit 8eeae31

Please sign in to comment.