Fix flashes display after grid introduction

Closes #5
This commit is contained in:
cryptogopher 2024-01-17 21:57:18 +01:00
parent 11ecd8eaed
commit 1227c54e0e
5 changed files with 31 additions and 21 deletions

View File

@ -202,18 +202,28 @@ input[type=text]:read-only {
} }
#flashes {
align-items: center;
display: flex;
flex-direction: column;
left: 0;
pointer-events: none;
position: fixed;
right: 0;
top: 1em;
}
.flash { .flash {
align-items: center; align-items: center;
border-radius: 0.2rem; border-radius: 0.2em;
color: white; color: white;
display: flex; display: flex;
font-size: 1.0rem; pointer-events: auto;
} }
.flash.alert:before { .flash.alert:before {
content: url('pictograms/alert-outline.svg'); content: url('pictograms/alert-outline.svg');
height: 1.4rem; height: 1.4em;
margin: 0 0.5rem; margin: 0 0.5em;
width: 1.4rem; width: 1.4em;
} }
.flash.alert { .flash.alert {
border-color: #ff1f5b; border-color: #ff1f5b;
@ -221,25 +231,24 @@ input[type=text]:read-only {
} }
.flash.notice:before { .flash.notice:before {
content: url('pictograms/check-circle-outline.svg'); content: url('pictograms/check-circle-outline.svg');
height: 1.4rem; height: 1.4em;
margin: 0 0.5rem; margin: 0 0.5em;
width: 1.4rem; width: 1.4em;
} }
.flash.notice { .flash.notice {
border-color: #009ade; border-color: #009ade;
background-color: #009ade; background-color: #009ade;
} }
/* NOTE: currently flash button inherits some unnecessary styles from generic
* button. */
.flash button { .flash button {
background-color: inherit; border: none;
border: inherit;
border-radius: inherit;
color: inherit; color: inherit;
cursor: pointer; cursor: pointer;
font-size: 1.4rem; font-size: 1.4em;
font-weight: bold; font-weight: bold;
margin-left:auto;
opacity: 0.6; opacity: 0.6;
padding: 0.2rem 0.2rem; padding: 0.2em 0.4em;
} }
.flash button:hover { .flash button:hover {
opacity: 1; opacity: 1;

View File

@ -47,6 +47,8 @@ class ApplicationController < ActionController::Base
def run_and_render(action) def run_and_render(action)
send action send action
render action # 2024-01-17, Rails 7.1.2: For unknown reason turbo_stream layout is omitted
# during render on POST method only (GET, DESTROY are ok).
render action, layout: 'application'
end end
end end

View File

@ -19,7 +19,7 @@ class UnitsController < ApplicationController
def create def create
@unit = current_user.units.new(unit_params) @unit = current_user.units.new(unit_params)
if @unit.save if @unit.save
flash[:notice] = t(".success") flash.now[:notice] = t(".success")
run_and_render :index run_and_render :index
else else
render :new render :new
@ -31,7 +31,7 @@ class UnitsController < ApplicationController
def update def update
if @unit.update(unit_params) if @unit.update(unit_params)
flash[:notice] = t(".success") flash.now[:notice] = t(".success")
run_and_render :index run_and_render :index
else else
render :edit render :edit
@ -40,7 +40,7 @@ class UnitsController < ApplicationController
def destroy def destroy
if @unit.destroy if @unit.destroy
flash[:notice] = t(".success") flash.now[:notice] = t(".success")
end end
run_and_render :index run_and_render :index
end end

View File

@ -93,7 +93,7 @@ module ApplicationHelper
flash.map do |entry, message| flash.map do |entry, message|
tag.div class: "flash #{entry}" do tag.div class: "flash #{entry}" do
tag.div(sanitize(message)) + tag.button(sanitize("&times;"), tabindex: -1, tag.div(sanitize(message)) + tag.button(sanitize("&times;"), tabindex: -1,
onclick: "this.parentElement.style.display='none';") onclick: "this.parentElement.remove();")
end end
end.join.html_safe end.join.html_safe
end end

View File

@ -41,8 +41,7 @@ class UnitsTest < ApplicationSystemTestCase
assert_selector 'tr', count: @user.units.count assert_selector 'tr', count: @user.units.count
end end
assert_selector :link_or_button, text: t('units.index.add_unit') assert_selector :link_or_button, text: t('units.index.add_unit')
assert_selector '.flash.notice', text: t('units.create.success')
# assert_selector flash
end end
test "close new unit form with escape" do test "close new unit form with escape" do