Measurements#new form improvements

This commit is contained in:
cryptogopher 2025-05-13 22:30:58 +02:00
parent ef3484dfdf
commit e12369cea1
8 changed files with 50 additions and 34 deletions

View File

@ -111,7 +111,6 @@ textarea {
} }
.button, .button,
button, button,
fieldset,
input, input,
select, select,
textarea { textarea {
@ -126,14 +125,25 @@ textarea {
.tab > svg, .tab > svg,
button > svg { button > svg {
height: 1.8em; height: 1.8em;
padding-right: 0.4em;
width: 1.8em; width: 1.8em;
} }
.button > svg:not(:last-child),
.tab > svg:not(:last-child),
button > svg:not(:last-child) {
padding-right: 0.4em;
}
fieldset { fieldset {
padding: 0.4em; padding: 0.4em;
} }
legend { legend {
color: var(--color-gray); color: var(--color-gray);
display: flex;
gap: 0.4em;
width: 100%;
}
legend span {
align-content: center;
flex-grow: 1;
} }
/* TODO: move normal non-button links (<a>:hover/:focus) styling here (i.e. /* TODO: move normal non-button links (<a>:hover/:focus) styling here (i.e.
@ -204,6 +214,7 @@ textarea:focus-visible {
accent-color: var(--color-dark-blue); accent-color: var(--color-dark-blue);
background-color: var(--color-focus-gray); background-color: var(--color-focus-gray);
} }
fieldset,
input[type=text]:read-only, input[type=text]:read-only,
textarea:read-only { textarea:read-only {
border: none; border: none;
@ -429,6 +440,9 @@ table.items .actions {
gap: 0.4em; gap: 0.4em;
justify-content: end; justify-content: end;
} }
table.items .actions.centered {
justify-content: center;
}
table.items tr.dropzone { table.items tr.dropzone {
position: relative; position: relative;
} }
@ -519,6 +533,11 @@ table.items select:focus-visible {
color: black; color: black;
} }
form a[name=cancel] {
border-color: var(--color-border-gray);
color: var(--color-nav-gray);
fill: var(--color-nav-gray);
}
form table.items { form table.items {
border: none; border: none;
} }

View File

@ -98,7 +98,7 @@ module ApplicationHelper
def submit_default_value def submit_default_value
svg_name = object ? (object.persisted? ? 'update' : 'plus-circle-outline') : '' svg_name = object ? (object.persisted? ? 'update' : 'plus-circle-outline') : ''
@template.svg_tag("pictograms/#{svg_name}") + super @template.svg_tag("pictograms/#{svg_name}", super)
end end
def except_pattern(value, pattern = nil) def except_pattern(value, pattern = nil)
@ -122,10 +122,11 @@ module ApplicationHelper
form_with(**options, &block) form_with(**options, &block)
end end
def svg_tag(source, options = {}) def svg_tag(source, label, options = {})
content_tag :svg, options do svg_tag = content_tag :svg, options do
tag.use(href: "#{image_path(source + ".svg")}#icon") tag.use(href: "#{image_path(source + ".svg")}#icon")
end end
label.blank? ? svg_tag : svg_tag + tag.span(label)
end end
def navigation_menu def navigation_menu
@ -138,7 +139,7 @@ module ApplicationHelper
menu_tabs.map do |name, image, status, css_class| menu_tabs.map do |name, image, status, css_class|
if current_user.at_least(status) if current_user.at_least(status)
link_to svg_tag("pictograms/#{image}") + t("#{name}.navigation"), link_to svg_tag("pictograms/#{image}", t("#{name}.navigation")),
{controller: "/#{name}", action: "index"}, {controller: "/#{name}", action: "index"},
class: class_names('tab', css_class, active: name == current_tab) class: class_names('tab', css_class, active: name == current_tab)
end end
@ -203,7 +204,7 @@ module ApplicationHelper
private private
def link_or_button_options(type, name, image = nil, html_options) def link_or_button_options(type, name, image = nil, html_options)
name = (image ? svg_tag("pictograms/#{image}") : '') + name.to_s name = svg_tag("pictograms/#{image}", name) if image
html_options[:class] = class_names( html_options[:class] = class_names(
html_options[:class], html_options[:class],

View File

@ -165,6 +165,6 @@ class Quantity < ApplicationRecord
end end
def relative_pathname(ancestor) def relative_pathname(ancestor)
pathname.delete_prefix(ancestor&.pathname || '') pathname.delete_prefix(ancestor ? ancestor.pathname + PATHNAME_DELIMITER : '')
end end
end end

View File

@ -15,7 +15,7 @@
</td> </td>
<td class="actions"> <td class="actions">
<%= image_button_tag t(:delete), 'delete-outline', class: 'dangerous', <%= image_button_tag '', 'delete-outline', class: 'dangerous',
formaction: discard_new_measurement_path(readout.quantity), formaction: discard_new_measurement_path(readout.quantity),
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %> formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
<%= form.hidden_field :quantity_id %> <%= form.hidden_field :quantity_id %>

View File

@ -1,21 +1,16 @@
<%= tabular_form_with url: new_measurement_path, html: {id: :new_readouts_form} do %> <%= tabular_fields_for Readout.new do |form| %>
<% if @readouts&.present? %> <fieldset>
<fieldset> <legend>
<%= tag.legend id: :new_readouts_form_legend %> <%= tag.span id: :new_readouts_form_legend %>
<table class="items centered"> <%= image_link_to '', "close-outline", measurements_path, name: :cancel,
<tbody id="readouts"> class: 'dangerous', onclick: render_turbo_stream('form_close') %>
<tr id="new_readouts_actions"> </legend>
<td></td> <table class="items centered">
<td></td> <tbody id="readouts">
<td><div class="actions"><%= button_tag %></div></td> <tr id="new_readouts_actions">
<td><div class="actions"> <td colspan="4"><div class="actions centered"><%= form.button %></div></td>
<%= image_link_to t(:cancel), "close-outline", measurements_path, </tr>
class: 'dangerous', name: :cancel, </tbody>
onclick: render_turbo_stream('form_close') %> </table>
</div></td> </fieldset>
</tr>
</tbody>
</table>
</fieldset>
<% end %>
<% end %> <% end %>

View File

@ -1,15 +1,16 @@
<div class="topside vflex"> <div class="topside vflex">
<% if current_user.at_least(:active) %> <% if current_user.at_least(:active) %>
<%= render partial: 'form_frame' %>
<%# TODO: show hint when no quantities/units defined %> <%# TODO: show hint when no quantities/units defined %>
<%= tabular_form_with url: new_measurement_path,
html: {id: :new_readouts_form} do |f| %>
<% end %>
<div class="hflex"> <div class="hflex">
<%= select_tag :id, options_from_collection_for_select( <%= select_tag :id, options_from_collection_for_select(
@quantities, :id, ->(q){ sanitize('&emsp;' * q.depth + q.name) } @quantities, :id, ->(q){ sanitize('&emsp;' * q.depth + q.name) }
), form: :new_readouts_form %> ), form: :new_readouts_form %>
<% common_options = {form: :new_readouts_form, formmethod: :get, <% common_options = {form: :new_readouts_form, formmethod: :get,
formnovalidate: true, data: {turbo_stream: true}} %> formnovalidate: true, data: {turbo_stream: true}} %>
<%= image_button_tag t('.new_quantity'), 'plus-outline', <%= image_button_tag t('.new_quantity'), 'plus-outline', **common_options -%>
formaction: new_measurement_path, **common_options -%>
<%= image_button_tag t('.new_children'), 'plus-multiple-outline', <%= image_button_tag t('.new_children'), 'plus-multiple-outline',
formaction: new_measurement_path(:children), **common_options -%> formaction: new_measurement_path(:children), **common_options -%>
<%= image_button_tag t('.new_subtree'), 'plus-multiple-outline', <%= image_button_tag t('.new_subtree'), 'plus-multiple-outline',

View File

@ -1,4 +1,4 @@
<%= turbo_stream.replace :new_readouts_form do %> <%= turbo_stream.update :new_readouts_form do %>
<%= render partial: 'form_frame' %> <%= render partial: 'form_frame' %>
<% end if @prev_quantities.empty? %> <% end if @prev_quantities.empty? %>

View File

@ -1,5 +1,5 @@
<% content_for :navigation, flush: true do %> <% content_for :navigation, flush: true do %>
<%= link_to svg_tag("pictograms/arrow-left-bold-outline") + t(:back), <%= link_to svg_tag("pictograms/arrow-left-bold-outline", t(:back)),
request.referer.present? ? :back : root_path, class: 'tab' %> request.referer.present? ? :back : root_path, class: 'tab' %>
<% end %> <% end %>