Improve logic for custom logos on error pages [SCI-9147]

- Switch to dynamic ERB templates.
- Move text to I18n
This commit is contained in:
sboursen-scinote 2023-09-21 20:43:58 +02:00
parent 006705fcf1
commit adc0a460bd
5 changed files with 303 additions and 3 deletions

View file

@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
def render_403(style = 'danger')
respond_to do |format|
format.html do
render file: 'public/403.html', status: :forbidden, layout: false
render 'errors/403', status: :forbidden, layout: false
end
format.json do
render json: { style: style }, status: :forbidden
@ -60,7 +60,7 @@ class ApplicationController < ActionController::Base
def render_404
respond_to do |format|
format.html do
render file: 'public/404.html', status: :not_found, layout: false
render 'errors/404', status: :not_found, layout: false
end
format.json do
render json: {}, status: :not_found
@ -74,7 +74,7 @@ class ApplicationController < ActionController::Base
def render_422(message = t('client_api.permission_error'))
respond_to do |format|
format.html do
render file: 'public/422.html', status: :unprocessable_entity, layout: false
render 'errors/422', status: :unprocessable_entity, layout: false
end
format.json do
render json: { message: message }, status: :unprocessable_entity

View file

@ -0,0 +1,118 @@
<!DOCTYPE html>
<html>
<head>
<title><%= t("errors.forbidden.title") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #F0F0F6;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.navbar {
background: #FFFFFF;
box-shadow: 0px 1px 4px rgba(35, 31, 32, 0.15);
height: 52px;
left: 0%;
position: absolute;
right: 0%;
top: 0%;
}
div.navbar img {
width: 121px;
height: 24px;
left: 21px;
position: absolute;
top: calc(50% - 24px/2 - 0px);
}
div.dialog {
width: 95%;
margin: 4em auto 0;
}
div.dialog > h1 {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: bold;
font-size: 1.5em;
line-height: 29px;
margin: 0.5em;
text-align: center;
}
div.dialog > p {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: normal;
font-size: 1.1em;
margin: 0.5em;
}
div.dialog > img {
margin: 1em;
}
div.back-button {
margin-top: 3em;
text-align: center;
}
a.back-button {
background: #104DA9;
border-radius: 4px;
color: #FFFFFF;
display: inline-block;
font-family: Lato;
font-style: normal;
font-weight: normal;
font-size: 0.9em;
margin-top: 3em;
padding: 0.8em 1em;
text-decoration: none;
}
a.back-button > img {
filter: invert(100%);
width: 1em;
height: 1em;
margin-right: 0.5em;
vertical-align:middle;
}
a.back-button > span {
color: #FFFFFF;
width: 1em;
height: 1em;
}
.illustration {
margin-top: 64px !important;
}
</style>
</head>
<body data-turbolinks="false">
<div class="navbar">
<a href="/">
<img id="logo" src="/images/scinote_logo.svg" title="SciNote">
</a>
</div>
<div class="dialog">
<img src="/images/undraw_through_the_park.svg" class="illustration">
<h1><%= t("errors.forbidden.dialog.title") %></h1>
<p><%= t("errors.forbidden.dialog.text") %></p>
<a class="back-button" href="/dashboard">
<img src="/images/arrow-left.svg">
<span><%= t("errors.forbidden.dialog.button") %></span>
</a>
</div>
</body>
</html>

View file

@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<title><%= t("errors.not_found.title") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #F0F0F6;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.navbar {
background: #FFFFFF;
box-shadow: 0px 1px 4px rgba(35, 31, 32, 0.15);
height: 52px;
left: 0%;
position: absolute;
right: 0%;
top: 0%;
}
div.navbar img {
width: 121px;
height: 24px;
left: 21px;
position: absolute;
top: calc(50% - 24px/2 - 0px);
}
div.dialog {
width: 95%;
margin: 4em auto 0;
}
div.dialog > h1 {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: bold;
font-size: 1.5em;
line-height: 29px;
margin: 0.5em;
text-align: center;
}
div.dialog > p {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: normal;
font-size: 1.1em;
margin: 0.5em;
}
div.dialog > img {
margin: 1em;
}
.illustration {
margin-top: 64px !important;
}
</style>
</head>
<body data-turbolinks="false">
<div class="navbar">
<a href="/">
<img id="logo" src="/images/scinote_logo.svg" title="SciNote">
</a>
</div>
<div class="dialog">
<img src="/images/genericError.svg" class="illustration">
<h1><%= t("errors.not_found.dialog.title") %></h1>
<p><%= t("errors.not_found.dialog.text_1") %></p>
<p><%= t("errors.not_found.dialog.text_2_html", home_url: root_url, search_url: new_search_url) %></p>
</div>
</body>
</html>

View file

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title><%= t("errors.unprocessable_entity.title") %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #F0F0F6;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.navbar {
background: #FFFFFF;
box-shadow: 0px 1px 4px rgba(35, 31, 32, 0.15);
height: 52px;
left: 0%;
position: absolute;
right: 0%;
top: 0%;
}
div.navbar img {
width: 121px;
height: 24px;
left: 21px;
position: absolute;
top: calc(50% - 24px/2 - 0px);
}
div.dialog {
width: 95%;
margin: 4em auto 0;
}
div.dialog > h1 {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: bold;
font-size: 1.5em;
line-height: 29px;
margin: 0.5em;
text-align: center;
}
div.dialog > p {
color: #404048;
font-family: Lato;
font-style: normal;
font-weight: normal;
font-size: 1.1em;
margin: 0.5em;
}
div.dialog > img {
margin: 1em;
}
.illustration {
margin-top: 64px !important;
}
</style>
</head>
<body data-turbolinks="false">
<div class="navbar">
<a href="/">
<img id="logo" src="/images/scinote_logo.svg" title="SciNote">
</a>
</div>
<div class="dialog">
<img src="/images/genericError.svg" class="illustration">
<h1><%= t("errors.unprocessable_entity.dialog.title") %></h1>
<p><%= t("errors.unprocessable_entity.dialog.text") %></p>
</div>
</body>
</html>

View file

@ -3759,3 +3759,24 @@ en:
canvas_view: "Canvas view"
active_state: "Active state"
archived_state: "Archived state"
errors:
forbidden:
title: "Access to this page is denied (403)."
dialog:
title: "It would seem that you are not allowed in here."
text: "You should request access from your team administrators."
button: "Go back"
not_found:
title: "This page could not be found (404)."
dialog:
title: "This page could not be found (404)."
text_1: "You may have mistyped the address or the page may have moved."
text_2_html: |
"If you are the application owner check the logs for more information.
You can go back to <a href="%{home_url}">home page</a> or try <a href="%{search_url}">searching.</a>"
unprocessable_entity:
title: "The change you wanted was rejected (422)."
dialog:
title: "Ooops, something went wrong."
text: "Please contact your SciNote administrator."