forked from fixin.me/fixin.me
Merge upstream/final-form into master
Incorporates WIP alternative measurement form (single select form with multiple select actions) and readouts controller. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,16 +57,7 @@
|
||||
:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
/* NOTE: move to higher priority layer instead of using !important? */
|
||||
[disabled] {
|
||||
border-color: var(--color-border-gray) !important;
|
||||
color: var(--color-border-gray) !important;
|
||||
/* NOTE: cannot set cursor with `pointer-events: none`; can be fixed by setting
|
||||
* `cursor` on wrapping element.
|
||||
cursor: not-allowed; */
|
||||
fill: var(--color-border-gray) !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* [hidden] submit elements cannot have `display` set as it makes them visible. */
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
@@ -584,17 +575,11 @@ form table select {
|
||||
display: flex;
|
||||
gap: 0.8em;
|
||||
}
|
||||
.hflex.reverse {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
.hflex.centered {
|
||||
justify-content: center;
|
||||
}
|
||||
.hint {
|
||||
color: var(--color-table-gray);
|
||||
font-style: italic;
|
||||
font-size: 0.9rem;
|
||||
text-align: center;
|
||||
.vexpand {
|
||||
width: 100%;
|
||||
}
|
||||
.vflex {
|
||||
display: flex;
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
class ReadoutsController < ApplicationController
|
||||
before_action :find_quantities, only: [:new]
|
||||
before_action :find_quantity, only: [:discard]
|
||||
before_action :find_quantity, only: [:new, :discard]
|
||||
before_action :find_prev_quantities, only: [:new, :discard]
|
||||
|
||||
def new
|
||||
@quantities -= @prev_quantities
|
||||
# TODO: raise ParameterInvalid if new_quantities.empty?
|
||||
@readouts = current_user.readouts.build(@quantities.map { |q| {quantity: q} })
|
||||
new_quantities =
|
||||
case params[:button]
|
||||
when 'children'
|
||||
@quantity.subquantities
|
||||
when 'subtree'
|
||||
@quantity.progenies
|
||||
else
|
||||
[@quantity]
|
||||
end
|
||||
new_quantities -= @prev_quantities
|
||||
@readouts = current_user.readouts.build(new_quantities.map { |q| {quantity: q} })
|
||||
|
||||
@user_units = current_user.units.ordered
|
||||
|
||||
quantities = @prev_quantities + @quantities
|
||||
quantities = @prev_quantities + new_quantities
|
||||
@superquantity = current_user.quantities
|
||||
.common_ancestors(quantities.map(&:parent_id)).first
|
||||
end
|
||||
@@ -24,9 +31,6 @@ class ReadoutsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def find_quantities
|
||||
@quantities = current_user.quantities.find(params[:quantity])
|
||||
end
|
||||
|
||||
def find_quantity
|
||||
@quantity = current_user.quantities.find_by!(id: params[:id])
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
<%= tabular_form_with model: Measurement.new, id: :measurement_form,
|
||||
class: 'topside-area vflex', html: {onkeydown: 'formProcessKey(event)'} do |form| %>
|
||||
<table class="items centered">
|
||||
<tbody id="readouts"></tbody>
|
||||
</table>
|
||||
|
||||
<div class="hflex">
|
||||
<%# TODO: right-click selection %>
|
||||
<details id="quantity_select" class="hexpand" open
|
||||
onkeydown="detailsProcessKey(event)">
|
||||
<summary autofocus>
|
||||
<!-- TODO: Set content with CSS when span empty to avoid duplication -->
|
||||
<span data-prompt="<%= t('.select_quantity') %>">
|
||||
<%= t('.select_quantity') %>
|
||||
</span>
|
||||
<%= image_button_tag t(:apply), "update", name: nil, disabled: true,
|
||||
formaction: new_readout_path, formmethod: :get, formnovalidate: true,
|
||||
data: {turbo_stream: true} %>
|
||||
</summary>
|
||||
<ul><%= quantities_check_boxes %></ul>
|
||||
</details>
|
||||
<%= form.button id: :create_measurement_button, disabled: true -%>
|
||||
</div>
|
||||
|
||||
<div class="hflex reverse">
|
||||
<%= tabular_form_with model: Measurement.new do |form| %>
|
||||
<fieldset>
|
||||
<table class="items centered">
|
||||
<tbody id="readouts">
|
||||
<tr id="readouts_form">
|
||||
<td colspan="4">
|
||||
<%= collection_select :quantity, :id, @quantities, :id, :to_s_with_depth,
|
||||
{prompt: t('.select_quantity'), disabled: '', selected: ''},
|
||||
{name: :id, class: 'quantity vexpand',
|
||||
onchange: "this.form.requestSubmit(new_readout_submit);"} %>
|
||||
<%= form.submit id: :new_readout_submit, name: nil, value: nil,
|
||||
formaction: new_readout_path, formmethod: :get, formnovalidate: true,
|
||||
hidden: true, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<div class="hflex centered">
|
||||
<%= form.button -%>
|
||||
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
||||
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<%= turbo_stream.update :measurement_form %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
<%= turbo_stream.remove :measurement_form %>
|
||||
<%= turbo_stream.show :no_items -%>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<%# TODO: show hint when no quantities/units defined %>
|
||||
<div class="rightside-area buttongrid">
|
||||
<div class="rightside buttongrid">
|
||||
<% if current_user.at_least(:active) %>
|
||||
<%= image_link_to t('.new_measurement'), 'plus-outline', new_measurement_path,
|
||||
id: :new_measurement_link, onclick: 'this.blur();',
|
||||
@@ -7,7 +7,9 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<table class="main-area">
|
||||
<%= tag.div class: 'topside', id: :measurement_form %>
|
||||
|
||||
<table class="main">
|
||||
<tbody id="measurements">
|
||||
<%= render(@measurements) || render_no_items %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<%= turbo_stream.disable :new_measurement_link -%>
|
||||
<%= turbo_stream.hide :no_items -%>
|
||||
<%= turbo_stream.append_all 'body' do %>
|
||||
<%= turbo_stream.update :measurement_form do %>
|
||||
<%= render partial: 'form' %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
<%# TODO: add readout reordering by dragging %>
|
||||
<%= tabular_fields_for 'readouts[]', readout do |form| %>
|
||||
<%- tag.tr id: dom_id(readout.quantity, :new, :readout) do %>
|
||||
<td class="actions">
|
||||
<%# TODO: change to _link_ after giving up displaying relative paths %>
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: nil,
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
<%- tag.tr id: dom_id(readout.quantity, :new, :readout),
|
||||
onkeydown: 'processKey(event)' do %>
|
||||
<td>
|
||||
<%= readout.quantity.relative_pathname(@superquantity) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.number_field :value, required: true,
|
||||
size: readout.type_for_attribute(:value).precision / 2,
|
||||
autofocus: readout_counter == 0 %>
|
||||
<%= form.number_field :value, required: true, autofocus: true, size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.hidden_field :quantity_id %>
|
||||
<%= form.collection_select :unit_id, @user_units, :id,
|
||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) },
|
||||
{prompt: t('.select_unit'), disabled: '', selected: ''}, required: true %>
|
||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) } %>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: :discard,
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= turbo_stream.disable :create_measurement_button if @prev_quantities.one? %>
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= turbo_stream.disable_all 'button[name="discard"]' if @prev_quantities.one? %>
|
||||
<%= turbo_stream.enable_all "select.quantity option[value='#{@quantity.id}']" %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
<%= turbo_stream.unselect dom_id(@quantity) %>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<% @readouts.each do |r| %>
|
||||
<%= turbo_stream.disable dom_id(r.quantity) %>
|
||||
<% end %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
<%= turbo_stream.append :readouts do %>
|
||||
<%# is .one? proper condition? can @readouts be empty? %>
|
||||
<%= turbo_stream.enable_all 'button[name="discard"]' if @prev_quantities.one? %>
|
||||
<% @readouts.each do |r| %>
|
||||
<%= turbo_stream.disable_all "select.quantity option[value='#{r.quantity_id}']" %>
|
||||
<% end %>
|
||||
<%= turbo_stream.before :readouts_form do %>
|
||||
<%= render partial: 'form', collection: @readouts, as: :readout %>
|
||||
<% end %>
|
||||
<%= turbo_stream.enable :create_measurement_button if @prev_quantities.empty? %>
|
||||
|
||||
@@ -85,7 +85,7 @@ en:
|
||||
navigation: Measurements
|
||||
no_items: There are no measurements taken. You can Add some now.
|
||||
form:
|
||||
select_quantity: select the measured quantities...
|
||||
select_quantity: select the measured quantity...
|
||||
index:
|
||||
new_measurement: Add measurement
|
||||
create:
|
||||
@@ -97,6 +97,7 @@ en:
|
||||
readouts:
|
||||
form:
|
||||
select_unit: ...
|
||||
new_children: Children
|
||||
quantities:
|
||||
navigation: Quantities
|
||||
no_items: There are no configured quantities. You can Add some or Import from defaults.
|
||||
|
||||
@@ -4,6 +4,7 @@ Rails.application.routes.draw do
|
||||
|
||||
resources :measurements
|
||||
|
||||
|
||||
resources :readouts, only: [:new] do
|
||||
collection {get 'new/:id/discard', action: :discard, as: :discard}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user