From d845b8afdce815960595c57fdb7a3f93e133e452 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Thu, 17 Oct 2024 17:59:47 +0200 Subject: [PATCH 01/16] Add delivery attributes --- app/models/site.rb | 2 ++ ...17155157_add_delivery_related_attributes_to_site.rb | 10 ++++++++++ db/schema.rb | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20241017155157_add_delivery_related_attributes_to_site.rb diff --git a/app/models/site.rb b/app/models/site.rb index 3d74373f0..ce4581dcc 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -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 + after_validation :geocode scope :sorted, -> { order(:position) } diff --git a/db/migrate/20241017155157_add_delivery_related_attributes_to_site.rb b/db/migrate/20241017155157_add_delivery_related_attributes_to_site.rb new file mode 100644 index 000000000..bf7dbcab2 --- /dev/null +++ b/db/migrate/20241017155157_add_delivery_related_attributes_to_site.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b8ac4555d..3d3819372 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.2].define(version: 2024_10_17_143515) do +ActiveRecord::Schema[7.2].define(version: 2024_10_17_155157) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -486,6 +486,8 @@ t.decimal "longitude" t.integer "rooms_count", default: 0, null: false t.text "description" + t.text "delivery_address" + t.text "delivery_times" end create_table "stacks", force: :cascade do |t| From fcc9672208ac5c529734eb46efcd9804f4d7776c Mon Sep 17 00:00:00 2001 From: B_Rass Date: Thu, 17 Oct 2024 18:31:36 +0200 Subject: [PATCH 02/16] Add new attributes to show and _form --- app/controllers/sites_controller.rb | 7 ++++++- app/views/sites/_form.html.erb | 18 ++++++++++++++++++ app/views/sites/show.html.erb | 20 +++++++++++++++++--- config/locales/activerecord.fr.yml | 3 +++ config/locales/fr.yml | 2 -- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 2c4529134..a23780020 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -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, :description, :position, :street, :country, :city, :latitude, :longitude) + params.require(:site).permit( + :name, :description, + :position, + :street, :country, :city, :latitude, :longitude, + :delivery_address, :delivery_times, :delivery_map + ) end end diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index e6e7037fa..67e146d93 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -56,6 +56,24 @@ <%= f.text_field :longitude, class: "form-control" %> + +
+ <%= f.label :delivery_address, class: "form-label" %> + <%= f.text_area :delivery_address, class: "form-control" %> +
+ +
+ <%= f.label :delivery_times, class: "form-label" %> + <%= f.text_area :delivery_times, class: "form-control" %> +
+ +
+ <%= 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" %> + <% end %> +
<% end %>
diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index a67899e3c..9d3ed6fc9 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -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:) %>
@@ -42,6 +40,22 @@
<%= @site.public_send(attribute_name) %>
<% end %> + +
+ <% %i[delivery_address delivery_times].each do |attribute_name| %> +
<%= Site.human_attribute_name(attribute_name) %>
+
<%= @site.public_send(attribute_name) %>
+ <% end %> + +
<%= Site.human_attribute_name(:delivery_map) %>
+
+ <% if @site.delivery_map.attached? %> + <%= link_to @site.delivery_map, rel: :noopener, target: :_blank do %> + <%= image_tag @site.delivery_map, class: "w-100" %> + <% end %> + <% end %> +
+
<% end %>
diff --git a/config/locales/activerecord.fr.yml b/config/locales/activerecord.fr.yml index 25d00bc0b..9c598d5bc 100644 --- a/config/locales/activerecord.fr.yml +++ b/config/locales/activerecord.fr.yml @@ -113,6 +113,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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 56f1c8f21..5cd10e7fd 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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: From 27bcdb75fff43c896d789c1b250cde205cb332a7 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Fri, 18 Oct 2024 11:04:42 +0200 Subject: [PATCH 03/16] After-review cleans --- app/views/sites/_form.html.erb | 2 +- app/views/sites/show.html.erb | 2 +- db/schema.rb | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 67e146d93..1181b913e 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -71,7 +71,7 @@ <%= 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" %> + <%= image_tag @site.delivery_map.representation(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %> <% end %> <% end %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 9d3ed6fc9..c7f5dae8b 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -51,7 +51,7 @@
<% if @site.delivery_map.attached? %> <%= link_to @site.delivery_map, rel: :noopener, target: :_blank do %> - <%= image_tag @site.delivery_map, class: "w-100" %> + <%= image_tag @site.delivery_map.representation(resize_to_limit: [1200, 1200]), class: "w-100" %> <% end %> <% end %>
diff --git a/db/schema.rb b/db/schema.rb index 3d3819372..6304c727c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -485,7 +485,6 @@ t.decimal "latitude" t.decimal "longitude" t.integer "rooms_count", default: 0, null: false - t.text "description" t.text "delivery_address" t.text "delivery_times" end From 95eaff449868be79993955e0362b1030e3b9c257 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Fri, 18 Oct 2024 11:05:14 +0200 Subject: [PATCH 04/16] Rename export_pdf_controller to frame_export_pdf_controller --- ...troller.js => frame_export_pdf_controller.js} | 1 - app/views/bays/_export_button.html.erb | 16 ++++++++-------- app/views/islets/_export_button.html.erb | 16 ++++++++-------- app/views/moves/index.html.erb | 12 ++++++------ app/views/rooms/_action_buttons.html.erb | 14 +++++++------- app/views/rooms/_export_button.html.erb | 16 ++++++++-------- 6 files changed, 37 insertions(+), 38 deletions(-) rename app/javascript/controllers/{export_pdf_controller.js => frame_export_pdf_controller.js} (99%) diff --git a/app/javascript/controllers/export_pdf_controller.js b/app/javascript/controllers/frame_export_pdf_controller.js similarity index 99% rename from app/javascript/controllers/export_pdf_controller.js rename to app/javascript/controllers/frame_export_pdf_controller.js index a990a2c08..0f021658e 100644 --- a/app/javascript/controllers/export_pdf_controller.js +++ b/app/javascript/controllers/frame_export_pdf_controller.js @@ -46,7 +46,6 @@ export default class extends Controller { for (let i = 0; i < this.modelIdsValue.length; i++) { const modelId = this.modelIdsValue[i] - const url = this.isMoveValue ? `moves/print/${modelId}`: `/visualization/frames/${modelId}/print?view=${viewTarget}${ bgWiring ? "&bg=wiring" : ""}` diff --git a/app/views/bays/_export_button.html.erb b/app/views/bays/_export_button.html.erb index 240b22e57..ef6c446c6 100644 --- a/app/views/bays/_export_button.html.erb +++ b/app/views/bays/_export_button.html.erb @@ -1,14 +1,14 @@
+ data-controller="frame-export-pdf" + data-frame-export-pdf-model-ids-value="<%= bay.frames.order(:name).pluck(:id) %>" + data-frame-export-pdf-filename-value="bay-<%= bay.id %>"> diff --git a/app/views/bays/index.html.erb b/app/views/bays/index.html.erb index 671b8b9b4..0dd82a265 100644 --- a/app/views/bays/index.html.erb +++ b/app/views/bays/index.html.erb @@ -88,7 +88,7 @@ <% end %> <% end %> - <% table.with_column(style: "min-width: 140px; width: 140px") do |bay| %> + <% table.with_column(style: "min-width: 132px; width: 132px") do |bay| %>
<%= render partial: "bays/export_button", locals: { bay: bay } %> <%= link_to visualization_bay_path(bay), class: "btn btn-primary", data: { turbo_frame: :_top } do %> diff --git a/app/views/islets/_export_button.html.erb b/app/views/islets/_export_button.html.erb index c354045a8..ea08f46cf 100644 --- a/app/views/islets/_export_button.html.erb +++ b/app/views/islets/_export_button.html.erb @@ -7,9 +7,9 @@ data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - - + <%= t("export_button.label") %> diff --git a/app/views/islets/index.html.erb b/app/views/islets/index.html.erb index 30f653c76..450c4d4bf 100644 --- a/app/views/islets/index.html.erb +++ b/app/views/islets/index.html.erb @@ -75,7 +75,7 @@ <%= Islet.human_attribute_name(:frames_count, count: islet.frames.count) %> <% end %> - <% table.with_column(style: "min-width: 140px; width: 140px") do |islet| %> + <% table.with_column(style: "min-width: 132px; width: 132px") do |islet| %>
<%= render partial: "islets/export_button", locals: { islet: islet } %> <%= link_to edit_islet_path(islet), class: "btn btn-info", data: { turbo_frame: :_top } do %> diff --git a/app/views/moves/index.html.erb b/app/views/moves/index.html.erb index 80873691b..b05a80732 100644 --- a/app/views/moves/index.html.erb +++ b/app/views/moves/index.html.erb @@ -90,7 +90,7 @@ <%= t("export_button.exports.pdf") %> - diff --git a/app/views/rooms/_action_buttons.html.erb b/app/views/rooms/_action_buttons.html.erb index 467bbafd1..46b86b191 100644 --- a/app/views/rooms/_action_buttons.html.erb +++ b/app/views/rooms/_action_buttons.html.erb @@ -53,8 +53,8 @@
diff --git a/app/views/rooms/_export_button.html.erb b/app/views/rooms/_export_button.html.erb index 5af029c82..42311f12d 100644 --- a/app/views/rooms/_export_button.html.erb +++ b/app/views/rooms/_export_button.html.erb @@ -7,9 +7,9 @@ data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - - + <%= t("export_button.label") %> diff --git a/app/views/rooms/index.html.erb b/app/views/rooms/index.html.erb index d7c717ab6..19e3dc24f 100644 --- a/app/views/rooms/index.html.erb +++ b/app/views/rooms/index.html.erb @@ -69,7 +69,7 @@ disabled> <% end %> - <% table.with_column(style: "min-width: 140px; width: 140px") do |room| %> + <% table.with_column(style: "min-width: 132px; width: 132px") do |room| %>
<%= render partial: "rooms/export_button", locals: { room: room } %> <%= link_to visualization_room_path(room), class: "btn btn-primary", data: { turbo_frame: :_top } do %> From f0493122cfb7395212c7a2030372fd00fd1e04ad Mon Sep 17 00:00:00 2001 From: B_Rass Date: Fri, 18 Oct 2024 12:48:43 +0200 Subject: [PATCH 06/16] Add export to PDF on delivery block on Site#show --- .../controllers/export_pdf_controller.js | 42 +++++++++++++++++++ .../frame_export_pdf_controller.js | 18 ++------ app/views/sites/show.html.erb | 29 ++++++++----- 3 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 app/javascript/controllers/export_pdf_controller.js diff --git a/app/javascript/controllers/export_pdf_controller.js b/app/javascript/controllers/export_pdf_controller.js new file mode 100644 index 000000000..af585b15b --- /dev/null +++ b/app/javascript/controllers/export_pdf_controller.js @@ -0,0 +1,42 @@ +import { Controller } from "@hotwired/stimulus" + +import { html2pdf } from "html2pdf.js" + +const exportOptions = { + margin: 10, + image: { + type: "jpeg", + quality: 1.0 + }, + enableLinks: false, + html2canvas: { scale: 1.5 }, + jsPDF: { format: "legal" } +} + +export default class extends Controller { + static targets = ["spinner"] + static values = { filename: String } + + async export() { + this.showSpinner() + + const opt = { ...exportOptions, ...{ + filename: `export_${this.filenameValue}` + }} + + var element = document.getElementById("export-to-pdf").cloneNode(true) + element.prepend(document.getElementsByTagName("h1")[0].cloneNode(true)) + await html2pdf().set(opt) + .from(element) + .save() + .finally(() => this.hideSpinner()) + } + + showSpinner() { + this.spinnerTarget.classList.remove("d-none") + } + + hideSpinner() { + this.spinnerTarget.classList.add("d-none") + } +} diff --git a/app/javascript/controllers/frame_export_pdf_controller.js b/app/javascript/controllers/frame_export_pdf_controller.js index 0f021658e..05406b307 100644 --- a/app/javascript/controllers/frame_export_pdf_controller.js +++ b/app/javascript/controllers/frame_export_pdf_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "@hotwired/stimulus" +import ExportPdfController from "./export_pdf_controller.js" import { get } from "@rails/request.js" import { html2pdf, saveAs, PDFDocument } from "html2pdf.js" @@ -15,11 +15,9 @@ const exportOptions = { jsPDF: { format: "legal" } } -export default class extends Controller { - static targets = ["spinner"] +export default class extends ExportPdfController { static values = { modelIds: Array, - filename: String, isMove: Boolean } @@ -49,9 +47,7 @@ export default class extends Controller { const url = this.isMoveValue ? `moves/print/${modelId}`: `/visualization/frames/${modelId}/print?view=${viewTarget}${ bgWiring ? "&bg=wiring" : ""}` - const response = await get(url, { - responseKind: "application/pdf" - }) + const response = await get(url) if (response.ok) { const html = await response.text @@ -70,12 +66,4 @@ export default class extends Controller { return pdfDoc } - - showSpinner() { - this.spinnerTarget.classList.remove("d-none") - } - - hideSpinner() { - this.spinnerTarget.classList.add("d-none") - } } diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index c7f5dae8b..0cdd39fc8 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -3,7 +3,23 @@ breadcrumb_steps = { Site.model_name.human.pluralize => sites_path, @site.name => "" } %> -<%= render Page::HeadingShowComponent.new(resource: @site, title: @site.name, breadcrumb_steps:) %> +<%= render Page::HeadingShowComponent.new(resource: @site, title: @site.name, breadcrumb_steps:) do |heading| %> + <% heading.with_extra_buttons do %> + + <% end %> +<% end %>
@@ -28,21 +44,14 @@ <% end %>
-
+
<%= render CardComponent.new(type: :primary) do |card| %> <% card.with_header do %> <%= t("layouts.sidebar.location.title") %> <% end %>
- <% %i[street city country latitude longitude].each do |attribute_name| %> -
<%= Site.human_attribute_name(attribute_name) %>
-
<%= @site.public_send(attribute_name) %>
- <% end %> -
- -
- <% %i[delivery_address delivery_times].each do |attribute_name| %> + <% %i[street city country latitude longitude delivery_address delivery_times].each do |attribute_name| %>
<%= Site.human_attribute_name(attribute_name) %>
<%= @site.public_send(attribute_name) %>
<% end %> From 425f150a40fb42f101b6a0e5bd995687f84dec3a Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 22 Oct 2024 17:39:56 +0200 Subject: [PATCH 07/16] Add content_type validation on delivery_map --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/models/site.rb | 4 +++- app/views/sites/_form.html.erb | 6 ++++-- spec/models/site_spec.rb | 11 ++++++++++- spec/rails_helper.rb | 3 +++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index c416b005f..4cfe47eff 100644 --- a/Gemfile +++ b/Gemfile @@ -77,6 +77,7 @@ group :production do gem "passenger" end +gem "active_storage_validations" gem "acts_as_list" gem "friendly_id", "~> 5.2" gem "record_tag_helper", "~> 1.0" # Add helpers removed from Rails core in Rails 5 diff --git a/Gemfile.lock b/Gemfile.lock index b48954f31..9e9568ea2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,6 +47,11 @@ GEM rails-html-sanitizer (~> 1.6) active_record_doctor (1.15.0) activerecord (>= 4.2.0) + active_storage_validations (1.3.0) + activejob (>= 6.1.4) + activemodel (>= 6.1.4) + activestorage (>= 6.1.4) + activesupport (>= 6.1.4) activejob (7.2.1.1) activesupport (= 7.2.1.1) globalid (>= 0.3.6) @@ -588,6 +593,7 @@ PLATFORMS DEPENDENCIES active_record_doctor + active_storage_validations acts_as_list bootsnap bootstrap (~> 5.3.2) diff --git a/app/models/site.rb b/app/models/site.rb index ce4581dcc..8936df9f2 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Site < ApplicationRecord - geocoded_by :address has_changelog has_many :rooms, dependent: :restrict_with_error @@ -9,6 +8,9 @@ class Site < ApplicationRecord has_one_attached :delivery_map + validates :delivery_map, content_type: [:png, :jpg, :jpeg, :pdf, :gif] + + geocoded_by :address after_validation :geocode scope :sorted, -> { order(:position) } diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 1181b913e..7fdf55176 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -69,8 +69,10 @@
<%= f.label :delivery_map, class: "form-label" %> - <%= f.file_field :delivery_map, class: "form-control" %> - <% if @site.delivery_map.attached? %> + <%= f.file_field :delivery_map, + class: "form-control", + accept: "image/png, image/jpeg, image/gif, application/pdf" %> + <% if @site.delivery_map.attached? && @site.persisted? %> <%= image_tag @site.delivery_map.representation(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %> <% end %>
diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 36e36f657..5d2a0fb86 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Site do subject(:site) do @@ -13,6 +13,15 @@ it { is_expected.to have_many(:rooms) } end + describe "validations" do + it do + is_expected.to validate_content_type_of(:delivery_map).allowing("image/png", + "image/jpeg", + "image/gif", + "application/pdf") + end + end + describe "#to_s" do it { expect(site.to_s).to eq site.name } end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d9c2ccaa9..caf119799 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,6 +8,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! +require "active_storage_validations/matchers" # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -68,4 +69,6 @@ config.include ActiveJob::TestHelper, type: :job config.include ActiveJob::TestHelper, type: :controller + + config.include ActiveStorageValidations::Matchers end From de3b8d11dbe0756af920708e5414686544a2afc0 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 22 Oct 2024 17:57:40 +0200 Subject: [PATCH 08/16] rubocop clean --- spec/models/site_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 5d2a0fb86..25dfcd3f1 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -15,7 +15,7 @@ describe "validations" do it do - is_expected.to validate_content_type_of(:delivery_map).allowing("image/png", + is_expected.to validate_content_type_of(:delivery_map).allowing("image/png", # rubocop:disable RSpec/ImplicitSubject "image/jpeg", "image/gif", "application/pdf") From 34a85b5c288d0f9f63dfcf27d5119d63265f8ec6 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Wed, 23 Oct 2024 12:01:56 +0200 Subject: [PATCH 09/16] Move export button to location block --- app/views/sites/show.html.erb | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 0cdd39fc8..927eb0586 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -3,23 +3,7 @@ breadcrumb_steps = { Site.model_name.human.pluralize => sites_path, @site.name => "" } %> -<%= render Page::HeadingShowComponent.new(resource: @site, title: @site.name, breadcrumb_steps:) do |heading| %> - <% heading.with_extra_buttons do %> - - <% end %> -<% end %> +<%= render Page::HeadingShowComponent.new(resource: @site, title: @site.name, breadcrumb_steps:) %>
@@ -47,7 +31,23 @@
<%= render CardComponent.new(type: :primary) do |card| %> <% card.with_header do %> - <%= t("layouts.sidebar.location.title") %> +
+ <%= t("layouts.sidebar.location.title") %> + +
<% end %>
From 8dc1e27b0c2c867b3df5888cfef37f2a4b1f9180 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Wed, 23 Oct 2024 12:04:17 +0200 Subject: [PATCH 10/16] Clean action_buttons --- app/views/rooms/_action_buttons.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/rooms/_action_buttons.html.erb b/app/views/rooms/_action_buttons.html.erb index 46b86b191..d1746af96 100644 --- a/app/views/rooms/_action_buttons.html.erb +++ b/app/views/rooms/_action_buttons.html.erb @@ -34,17 +34,17 @@ <% if view_side == Frame::VIEW_SIDES[:both] %> - <%= content_tag :div, class: 'btn btn-sm btn-primary disabled' do %> + <%= content_tag :div, class: 'btn btn-sm btn-outline-primary disabled' do %> <%= Frame.human_attribute_name("view_sides.both") %> <% end %> <% else %> - <%= link_to url_for(params.except(:controller, :action).permit(:view, :islet, :id, :bg, :format).merge({view: (view_side == Frame::VIEW_SIDES[:back] ? Frame::VIEW_SIDES[:front] : Frame::VIEW_SIDES[:back]), islet: params['islet'], id: params['id']})), class: "btn btn-sm btn-primary align-items-center", remote: true do %> + <%= link_to url_for(params.except(:controller, :action).permit(:view, :islet, :id, :bg, :format).merge({view: (view_side == Frame::VIEW_SIDES[:back] ? Frame::VIEW_SIDES[:front] : Frame::VIEW_SIDES[:back]), islet: params['islet'], id: params['id']})), class: "btn btn-sm btn-outline-primary align-items-center", remote: true do %> <%= Frame.human_attribute_name("view_sides.#{view_side}") %> <% end %> <% end %> - <%= link_to "#", class: 'btn btn-sm btn-primary align-items-center', id: 'drag-n-drop-switcher' do %> + <%= link_to "#", class: 'btn btn-sm btn-outline-primary align-items-center', id: 'drag-n-drop-switcher' do %> <%= t(".dragn_drop.enable") %> <% end %> From 6c4e5562a6003ca2bf6a988c37bdf9fa1d77a637 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Wed, 23 Oct 2024 13:33:15 +0200 Subject: [PATCH 11/16] Fixing test --- spec/features/rooms/browse_room_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/rooms/browse_room_spec.rb b/spec/features/rooms/browse_room_spec.rb index 42bbdcb85..012c1ecaa 100644 --- a/spec/features/rooms/browse_room_spec.rb +++ b/spec/features/rooms/browse_room_spec.rb @@ -25,7 +25,7 @@ end # 2. Change view to 'back' - switch_view_btn = find("a.btn-primary > span.bi-back") + switch_view_btn = find("a.btn-outline-primary > span.bi-back") switch_view_btn.click # Since the overview container is already loaded, we cannot use find() to wait for loading From b215eb504c2e061daa4627fe989256559c03f363 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Thu, 24 Oct 2024 18:04:15 +0200 Subject: [PATCH 12/16] Fix rebase --- db/schema.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/schema.rb b/db/schema.rb index 6304c727c..3d3819372 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -485,6 +485,7 @@ t.decimal "latitude" t.decimal "longitude" t.integer "rooms_count", default: 0, null: false + t.text "description" t.text "delivery_address" t.text "delivery_times" end From 60c52424fc9d9d18b5576ea59658e4f22ca7c32a Mon Sep 17 00:00:00 2001 From: B-Rass Date: Tue, 29 Oct 2024 11:07:40 +0100 Subject: [PATCH 13/16] Update app/models/site.rb Co-authored-by: Nicolas Brousse --- app/models/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/site.rb b/app/models/site.rb index 8936df9f2..66267efc3 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -8,7 +8,7 @@ class Site < ApplicationRecord has_one_attached :delivery_map - validates :delivery_map, content_type: [:png, :jpg, :jpeg, :pdf, :gif] + validates :delivery_map, content_type: %i[png jpg jpeg pdf gif] geocoded_by :address after_validation :geocode From a81af4995f3a60abacc88448faac099c478656a9 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 29 Oct 2024 11:27:04 +0100 Subject: [PATCH 14/16] Create SitesHelper with delivery_map_accepted_mime_types method --- app/helpers/sites_helper.rb | 10 ++++++++++ app/models/site.rb | 2 +- app/views/sites/_form.html.erb | 2 +- spec/helpers/sites_helper_spec.rb | 9 +++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/helpers/sites_helper.rb create mode 100644 spec/helpers/sites_helper_spec.rb diff --git a/app/helpers/sites_helper.rb b/app/helpers/sites_helper.rb new file mode 100644 index 000000000..a66a8c25e --- /dev/null +++ b/app/helpers/sites_helper.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module SitesHelper + def delivery_map_accepted_mime_types + Site.validators_on(:delivery_map).find { |v| v.is_a?(ActiveStorageValidations::ContentTypeValidator) } + .options[:in].map { |f| Mime[f].to_s } + .uniq + .join(", ") + end +end diff --git a/app/models/site.rb b/app/models/site.rb index 66267efc3..f91280829 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -8,7 +8,7 @@ class Site < ApplicationRecord has_one_attached :delivery_map - validates :delivery_map, content_type: %i[png jpg jpeg pdf gif] + validates :delivery_map, content_type: %i[png jpg jpeg gif pdf] geocoded_by :address after_validation :geocode diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 7fdf55176..35aac48f6 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -71,7 +71,7 @@ <%= f.label :delivery_map, class: "form-label" %> <%= f.file_field :delivery_map, class: "form-control", - accept: "image/png, image/jpeg, image/gif, application/pdf" %> + accept: delivery_map_accepted_mime_types %> <% if @site.delivery_map.attached? && @site.persisted? %> <%= image_tag @site.delivery_map.representation(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %> <% end %> diff --git a/spec/helpers/sites_helper_spec.rb b/spec/helpers/sites_helper_spec.rb new file mode 100644 index 000000000..c9983bf60 --- /dev/null +++ b/spec/helpers/sites_helper_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe SitesHelper do + describe "delivery_map_accepted_mime_types" do + it { expect(helper.delivery_map_accepted_mime_types).to eq("image/png, image/jpeg, image/gif, application/pdf") } + end +end From 58ecb1e67eb5989e3e407d9cb72fe3f53be1983f Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 29 Oct 2024 11:29:51 +0100 Subject: [PATCH 15/16] Fixing to short export_button max-width --- app/assets/stylesheets/application.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9edcec992..807b1fc73 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -755,7 +755,7 @@ body { } .export-button { - max-width: 69px; + max-width: 70px; } .export-pdf-button { From 9453d21351fad2763c01fea067f8a093fe1d87fb Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 29 Oct 2024 12:30:14 +0100 Subject: [PATCH 16/16] Move format validator check to application helper --- app/helpers/application_helper.rb | 9 +++++++++ app/helpers/sites_helper.rb | 10 ---------- app/views/sites/_form.html.erb | 2 +- spec/helpers/application_helper_spec.rb | 23 +++++++++++++++++++++++ spec/helpers/sites_helper_spec.rb | 9 --------- 5 files changed, 33 insertions(+), 20 deletions(-) delete mode 100644 app/helpers/sites_helper.rb create mode 100644 spec/helpers/application_helper_spec.rb delete mode 100644 spec/helpers/sites_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 15b06f0f6..97a38e4a8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,13 @@ # frozen_string_literal: true module ApplicationHelper + def accepted_format_for_attachment(model_klass, attribute_name) + validator = model_klass.validators_on(attribute_name.to_sym).find do |v| + v.is_a?(ActiveStorageValidations::ContentTypeValidator) + end + + return unless validator + + validator.options[:in].map { |f| Mime[f].to_s }.uniq.join(", ") + end end diff --git a/app/helpers/sites_helper.rb b/app/helpers/sites_helper.rb deleted file mode 100644 index a66a8c25e..000000000 --- a/app/helpers/sites_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -module SitesHelper - def delivery_map_accepted_mime_types - Site.validators_on(:delivery_map).find { |v| v.is_a?(ActiveStorageValidations::ContentTypeValidator) } - .options[:in].map { |f| Mime[f].to_s } - .uniq - .join(", ") - end -end diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 35aac48f6..7ed77ab33 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -71,7 +71,7 @@ <%= f.label :delivery_map, class: "form-label" %> <%= f.file_field :delivery_map, class: "form-control", - accept: delivery_map_accepted_mime_types %> + accept: accepted_format_for_attachment(@site.class, "delivery_map") %> <% if @site.delivery_map.attached? && @site.persisted? %> <%= image_tag @site.delivery_map.representation(resize_to_limit: [200, 200]), class: "ms-0 mt-2" %> <% end %> diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..7edaa3f54 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ApplicationHelper do + describe "accepted_format_for_attachment" do + context "with a model and attribute using ContentTypeValidator" do + it do + expect(helper.accepted_format_for_attachment(Site, "delivery_map")).to eq( + "image/png, image/jpeg, image/gif, application/pdf" + ) + end + end + + context "with a model using ContentTypeValidator (but not the attribute)" do + it { expect(helper.accepted_format_for_attachment(Site, "name")).to be_nil } + end + + context "with a model not using ContentTypeValidator" do + it { expect(helper.accepted_format_for_attachment(Room, "name")).to be_nil } + end + end +end diff --git a/spec/helpers/sites_helper_spec.rb b/spec/helpers/sites_helper_spec.rb deleted file mode 100644 index c9983bf60..000000000 --- a/spec/helpers/sites_helper_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe SitesHelper do - describe "delivery_map_accepted_mime_types" do - it { expect(helper.delivery_map_accepted_mime_types).to eq("image/png, image/jpeg, image/gif, application/pdf") } - end -end