feat: customized page 404

This commit is contained in:
Colin Darie 2024-03-28 09:45:05 +01:00
parent fe508c0a73
commit 7dcd4ba538
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
11 changed files with 149 additions and 77 deletions

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -0,0 +1,57 @@
<svg width="80px" height="80px" viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg">
<style>
.fr-artwork-decorative {
fill: #ECECFF;
}
.fr-artwork-minor {
fill: #E1000F;
}
.fr-artwork-major {
fill: #000091;
}
</style>
<g class="fr-artwork-decorative" id="artwork-decorative">
<path d="M69,12c0,0.55139-0.44861,1-1,1s-1-0.44861-1-1s0.44861-1,1-1S69,11.44861,69,12z M41,74
c-0.55139,0-1,0.44861-1,1s0.44861,1,1,1s1-0.44861,1-1S41.55139,74,41,74z M15,8c-0.55139,0-1,0.44855-1,1c0,0.55139,0.44861,1,1,1
s1-0.44861,1-1C16,8.44855,15.55139,8,15,8z"/>
</g>
<g class="fr-artwork-minor" id="artwork-minor">
<path d="M17,21c0,0.55139-0.44861,1-1,1s-1-0.44861-1-1s0.44861-1,1-1S17,20.44861,17,21z M20,20
c-0.55139,0-1,0.44861-1,1s0.44861,1,1,1s1-0.44861,1-1S20.55139,20,20,20z M24,20c-0.55139,0-1,0.44861-1,1s0.44861,1,1,1
s1-0.44861,1-1S24.55139,20,24,20z M62,20H32l-0.11658,0.00671C31.38599,20.06451,31,20.48718,31,21c0,0.55231,0.44769,1,1,1h30
l0.11658-0.00671C62.61401,21.93549,63,21.51282,63,21C63,20.44769,62.55231,20,62,20z M60.59998,42.20001
c0.40784,0.30591,0.5155,0.86346,0.26904,1.29498l-0.06903,0.10498l-4.30267,5.737C56.81488,49.81299,57,50.38489,57,51
c0,1.65692-1.34308,3-3,3s-3-1.34308-3-3c0-0.46307,0.10492-0.90179,0.29242-1.2934l-1.99951-1.99951
c-0.3905-0.3905-0.3905-1.02368,0-1.41418c0.36047-0.36053,0.92767-0.38818,1.32001-0.08319l0.09418,0.08319l1.99951,1.99951
C53.09821,48.10498,53.53693,48,54,48c0.31268,0,0.6142,0.04779,0.89758,0.1366l4.30243-5.73657
C59.53137,41.95819,60.1582,41.86859,60.59998,42.20001z M55,51c0-0.55231-0.44769-1-1-1s-1,0.44769-1,1s0.44769,1,1,1
S55,51.55231,55,51z"/>
</g>
<g class="fr-artwork-major" id="artwork-major">
<path d="M36.99329,62.88342L37,63c0,0.51282-0.38599,0.93549-0.88342,0.99329L36,64H12
c-0.51282,0-0.93549-0.38599-0.99329-0.88342L11,63V17c0-0.51282,0.38599-0.93549,0.88342-0.99329L12,16h54
c0.51282,0,0.93549,0.38599,0.99329,0.88342L67,17v16c0,0.55231-0.44769,1-1,1c-0.51282,0-0.93549-0.38599-0.99329-0.88342L65,33V18
H13v6h37c0.55231,0,1,0.44769,1,1c0,0.51282-0.38599,0.93549-0.88342,0.99329L50,26H13v36h23
C36.51282,62,36.93549,62.38599,36.99329,62.88342z M54,34c-9.38879,0-17,7.61121-17,17
c0,8.62091,6.41699,15.74298,14.73511,16.8504l-0.4422,0.4425l-0.08319,0.09418c-0.30499,0.39233-0.27734,0.95953,0.08319,1.32001
c0.3905,0.3905,1.02368,0.3905,1.41418,0l2-2c0.02942-0.02942,0.05701-0.06061,0.08258-0.09351
c0.05573-0.07172,0.10101-0.14996,0.13452-0.23102c0.0426-0.10284,0.0686-0.21436,0.07452-0.33105
C54.99957,67.03442,55,67.01727,55,67c0-0.13483-0.02667-0.26331-0.07501-0.38062c-0.04877-0.11877-0.1214-0.22998-0.2179-0.32648
l-2-2l-0.09418-0.08319c-0.39233-0.30499-0.95953-0.27734-1.32001,0.08319l-0.08319,0.09418
c-0.30499,0.39233-0.27734,0.95953,0.08319,1.32001l0.06,0.06012C44.33112,64.51691,39,58.38098,39,51c0-8.2843,6.7157-15,15-15
s15,6.7157,15,15c0,3.49902-1.2005,6.81122-3.3645,9.46729c-0.34882,0.42822-0.28448,1.05811,0.14368,1.40692
c0.42822,0.34882,1.05804,0.28448,1.40692-0.14374C69.63812,58.72083,71,54.9635,71,51C71,41.61121,63.38879,34,54,34z
M63.37518,62.71002c-0.5899,0.4729-1.21448,0.90076-1.86847,1.2796c-0.47791,0.27679-0.64093,0.88855-0.36414,1.36646
s0.88861,0.64093,1.36652,0.36414c0.74121-0.42932,1.44891-0.91412,2.11713-1.44983c0.43091-0.34546,0.50018-0.97479,0.15466-1.4057
C64.43542,62.43378,63.80609,62.3645,63.37518,62.71002z M62.7901,46.12402c-0.50708,0.21875-0.74078,0.80719-0.52209,1.31427
C62.74878,48.55267,63,49.75781,63,51c0,4.97058-4.02942,9-9,9s-9-4.02942-9-9s4.02942-9,9-9
c0.61743,0,1.2262,0.06201,1.82031,0.18402c0.54102,0.11096,1.06958-0.23755,1.18066-0.7785
c0.11115-0.54102-0.23749-1.06964-0.7785-1.18073C55.49622,40.07568,54.75269,40,54,40c-6.07507,0-11,4.92493-11,11
s4.92493,11,11,11s11-4.92493,11-11c0-1.51593-0.30737-2.99048-0.89557-4.354C63.88562,46.13892,63.29718,45.90521,62.7901,46.12402
z M38.11658,33.99329C38.61401,33.93549,39,33.51282,39,33c0-0.55231-0.44769-1-1-1H20l-0.11658,0.00671
C19.38599,32.06451,19,32.48718,19,33c0,0.55231,0.44769,1,1,1h18L38.11658,33.99329z M34.11658,39.99329
C34.61401,39.93549,35,39.51282,35,39c0-0.55231-0.44769-1-1-1H20l-0.11658,0.00671C19.38599,38.06451,19,38.48718,19,39
c0,0.55231,0.44769,1,1,1h14L34.11658,39.99329z M20,44l-0.11658,0.00671C19.38599,44.06451,19,44.48718,19,45
c0,0.55231,0.44769,1,1,1h12l0.11658-0.00671C32.61401,45.93549,33,45.51282,33,45c0-0.55231-0.44769-1-1-1H20z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -419,6 +419,17 @@ class ApplicationController < ActionController::Base
prepend_view_path "app/custom_views"
end
def try_nav_bar_profile_from_referrer
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)
controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?
controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end
# Extract a value from params based on the "path"
#
# params: { dossiers: { champs_public_attributes: { 1234 => { value: "hello" } } } }

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class ErrorsController < ApplicationController
def nav_bar_profile = try_nav_bar_profile_from_referrer
def not_found
render(status: 404)
end
end

View file

@ -21,16 +21,7 @@ class ReleaseNotesController < ApplicationController
render "scrollable_list" if params[:page].present?
end
def nav_bar_profile
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)
controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?
controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end
def nav_bar_profile = try_nav_bar_profile_from_referrer
private

View file

@ -0,0 +1,9 @@
.fr-col-12.fr-col-md-3.fr-col-offset-md-1.fr-px-6w.fr-px-md-0.fr-py-0
%svg.fr-responsive-img.fr-artwork{ xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", width: "160", height: "200", viewBox: "0 0 160 200" }
%use.fr-artwork-motif{ href: image_path("dsfr/artwork/background/ovoid.svg#artwork-motif") }
%use.fr-artwork-background{ href: image_path('dsfr/artwork/background/ovoid.svg#artwork-background') }
%g{ transform: "translate(40, 60)" }
%use.fr-artwork-decorative{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-decorative') }
%use.fr-artwork-minor{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-minor') }
%use.fr-artwork-major{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-major') }

View file

@ -0,0 +1,20 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Page not found
%p.fr-text--sm.fr-mb-3w Error 404
%p.fr-text--lead.fr-mb-3w The page you are looking for cannot be found. We apologize for the inconvenience.
%p.fr-text--sm.fr-mb-5w
If you typed the web address in the browser, check that it is correct. The page may no longer be available.
%br
In this case, to continue your visit you can check our homepage.
%br
Otherwise, contact us so we can direct you to the correct information.
%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Homepage", root_path, class: "fr-btn")
%li
= link_to("Contact us", contact_path, class: "fr-btn fr-btn--secondary")
= render partial: "artwork"

View file

@ -0,0 +1,22 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Page non trouvée
%p.fr-text--sm.fr-mb-3w Erreur 404
%p.fr-text--lead.fr-mb-3w La page que vous cherchez est introuvable. Excusez-nous pour la gène occasionnée.
%p.fr-text--sm.fr-mb-3w
Si vous avez tapé ladresse web dans le navigateur, vérifiez quelle est correcte. La page nest peut-être plus disponible.
%br
Dans ce cas, pour continuer votre visite vous pouvez consulter notre page daccueil.
%br
Sinon contactez-nous pour que lon puisse vous rediriger vers la bonne information.
%p.fr-text--sm.fr-mb-5w
Pour le laissez-passer A-38, relatif à lenregistrement d'une galère, veuillez vous adresser à la capitainerie au port.
%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Page daccueil", root_path, class: "fr-btn")
%li
= link_to("Contactez-nous", contact_path, class: "fr-btn fr-btn--secondary")
= render partial: "artwork"

View file

@ -104,6 +104,8 @@ module TPS
config.active_record.encryption.primary_key = Rails.application.secrets.active_record_encryption.fetch(:primary_key)
config.active_record.encryption.key_derivation_salt = Rails.application.secrets.active_record_encryption.fetch(:key_derivation_salt)
config.exceptions_app = self.routes
# Copied from rgeo/activerecord-postgis-adapter
ActiveRecord::SchemaDumper.ignore_tables |= [
'geography_columns',

View file

@ -698,6 +698,8 @@ Rails.application.routes.draw do
resources :release_notes, only: [:index]
get '/404', to: 'errors#not_found'
if Rails.env.test?
scope 'test/api_geo' do
get 'regions' => 'api_geo_test#regions'

View file

@ -1,67 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>La page que vous cherchez nexiste pas (erreur 404)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>La page que vous cherchez nexiste pas (erreur 404).</h1>
<p>La page que vous cherchez a sans doute changé dadresse, ou vous navez pas les droits nécessaires pour y accéder.</p>
</div>
</div>
</body>
</html>