Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

341609 Add delivery block to Site #14

Open
wants to merge 8 commits into
base: 341607-update-show-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def set_site

# Never trust parameters from the scary internet, only allow the white list through.
def site_params
params.require(:site).permit(:name, :position, :street, :country, :city, :latitude, :longitude)
params.require(:site).permit(
:name,
:position,
:street, :country, :city, :latitude, :longitude,
:delivery_address, :delivery_times, :delivery_map
)
end
end
2 changes: 2 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Site < ApplicationRecord
has_many :rooms, dependent: :restrict_with_error
has_many :frames, through: :rooms, dependent: :restrict_with_error

has_one_attached :delivery_map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add some format and size validation?


after_validation :geocode

scope :sorted, -> { order(:position) }
Expand Down
18 changes: 18 additions & 0 deletions app/views/sites/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@
<%= f.text_field :longitude, class: "form-control" %>
</fieldset>
</div>

<fieldset class="col-12 mt-4">
<%= f.label :delivery_address, class: "form-label" %>
<%= f.text_area :delivery_address, class: "form-control" %>
</fieldset>

<fieldset class="col-12 mt-4">
<%= f.label :delivery_times, class: "form-label" %>
<%= f.text_area :delivery_times, class: "form-control" %>
</fieldset>

<fieldset class="col-12 mt-4">
<%= f.label :delivery_map, class: "form-label" %>
<%= f.file_field :delivery_map, class: "form-control" %>
<% if @site.delivery_map.attached? %>
<%= image_tag @site.delivery_map.variant(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<%= image_tag @site.delivery_map.variant(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %>
<%= image_tag @site.delivery_map.representation(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %>

Prefer representation to manage other files than images (ex: pdf)

<% end %>
</fieldset>
<% end %>

<div class="col-12 py-4 mt-4 text-end sticky-bottom bg-body-tertiary border-top">
Expand Down
20 changes: 17 additions & 3 deletions app/views/sites/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
breadcrumb_steps = { Site.model_name.human.pluralize => sites_path, @site.name => "" }
%>

<%= render Page::HeadingShowComponent.new(
resource: @site, title: t(".title", site_id: @site.id, site_name: @site.name), breadcrumb_steps:
) %>
<%= render Page::HeadingShowComponent.new(resource: @site, title: @site.name, breadcrumb_steps:) %>
<div class="col-12 p-4 border-top">
<div class="d-flex flex-row flex-wrap">
<div class="col-12 col-lg-6 pe-lg-4">
Expand Down Expand Up @@ -42,6 +40,22 @@
<dd class="mb-0 pb-2 ps-3"><%= @site.public_send(attribute_name) %></dd>
<% end %>
</dl>

<dl class="show-page_dl d-grid row-gap-2 pt-3 border-top mb-0">
<% %i[delivery_address delivery_times].each do |attribute_name| %>
<dt class="pb-2"><%= Site.human_attribute_name(attribute_name) %></dt>
<dd class="mb-0 pb-2 ps-3"><%= @site.public_send(attribute_name) %></dd>
<% end %>

<dt class="pb-2"><%= Site.human_attribute_name(:delivery_map) %></dt>
<dd class="mb-0 pb-2 ps-3">
<% if @site.delivery_map.attached? %>
<%= link_to @site.delivery_map, rel: :noopener, target: :_blank do %>
<%= image_tag @site.delivery_map, class: "w-100" %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a representation with resize. Here if use upload a pdf, it will do an image of first page at least.

<% end %>
<% end %>
</dd>
</dl>
<% end %>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/activerecord.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ fr:
country: Pays
latitude: Latitude
longitude: Longitude
delivery_address: Adresse livraison
delivery_times: Horaires de livraison
delivery_map: Plan de livraison
rooms_count:
zero: 0 salle
one: 1 salle
Expand Down
2 changes: 0 additions & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ fr:
title: Sites
new_site: Ajouter un site
delete_confirmation: Ce site ne pourra pas être supprimé tant qu'il sera associé à au moins une salle. Voulez-vous continuer ?
show:
title: 'Site #%{site_id} - %{site_name}'
new:
title: Nouveau site
create:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddDeliveryRelatedAttributesToSite < ActiveRecord::Migration[7.2]
def change
change_table :sites, bulk: true do |t|
t.text :delivery_address
t.text :delivery_times
end
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

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