diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index c4132b5..02d4998 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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; diff --git a/app/controllers/readouts_controller.rb b/app/controllers/readouts_controller.rb index e47f271..01ec0fe 100644 --- a/app/controllers/readouts_controller.rb +++ b/app/controllers/readouts_controller.rb @@ -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]) diff --git a/app/views/measurements/_form.html.erb b/app/views/measurements/_form.html.erb index 8f1470a..976a614 100644 --- a/app/views/measurements/_form.html.erb +++ b/app/views/measurements/_form.html.erb @@ -1,28 +1,23 @@ -<%= tabular_form_with model: Measurement.new, id: :measurement_form, - class: 'topside-area vflex', html: {onkeydown: 'formProcessKey(event)'} do |form| %> - - -
- -
- <%# TODO: right-click selection %> -
- - - - <%= t('.select_quantity') %> - - <%= image_button_tag t(:apply), "update", name: nil, disabled: true, - formaction: new_readout_path, formmethod: :get, formnovalidate: true, - data: {turbo_stream: true} %> - - -
- <%= form.button id: :create_measurement_button, disabled: true -%> -
- -
+<%= tabular_form_with model: Measurement.new do |form| %> +
+ + + + + + +
+ <%= 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} %> +
+
+
+ <%= form.button -%> <%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel, class: 'dangerous', onclick: render_turbo_stream('form_close') %>
diff --git a/app/views/measurements/_form_close.html.erb b/app/views/measurements/_form_close.html.erb index 78511d4..f552647 100644 --- a/app/views/measurements/_form_close.html.erb +++ b/app/views/measurements/_form_close.html.erb @@ -1,3 +1,4 @@ +<%= turbo_stream.update :measurement_form %> <%= turbo_stream.update :flashes %> <%= turbo_stream.remove :measurement_form %> <%= turbo_stream.show :no_items -%> diff --git a/app/views/measurements/index.html.erb b/app/views/measurements/index.html.erb index bac10e1..5cc12e9 100644 --- a/app/views/measurements/index.html.erb +++ b/app/views/measurements/index.html.erb @@ -1,5 +1,5 @@ <%# TODO: show hint when no quantities/units defined %> -
+
<% 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 %>
- +<%= tag.div class: 'topside', id: :measurement_form %> + +
<%= render(@measurements) || render_no_items %> diff --git a/app/views/measurements/new.turbo_stream.erb b/app/views/measurements/new.turbo_stream.erb index 253ac8a..1adc328 100644 --- a/app/views/measurements/new.turbo_stream.erb +++ b/app/views/measurements/new.turbo_stream.erb @@ -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 %> diff --git a/app/views/readouts/_form.html.erb b/app/views/readouts/_form.html.erb index d769a23..a9f0d37 100644 --- a/app/views/readouts/_form.html.erb +++ b/app/views/readouts/_form.html.erb @@ -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 %> - + <%- tag.tr id: dom_id(readout.quantity, :new, :readout), + onkeydown: 'processKey(event)' do %> + <% end %> <% end %> diff --git a/app/views/readouts/discard.turbo_stream.erb b/app/views/readouts/discard.turbo_stream.erb index 6966b40..ae275ca 100644 --- a/app/views/readouts/discard.turbo_stream.erb +++ b/app/views/readouts/discard.turbo_stream.erb @@ -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) %> diff --git a/app/views/readouts/new.turbo_stream.erb b/app/views/readouts/new.turbo_stream.erb index 04ae31e..241bc21 100644 --- a/app/views/readouts/new.turbo_stream.erb +++ b/app/views/readouts/new.turbo_stream.erb @@ -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? %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 25be67f..2496f7f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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. diff --git a/config/routes.rb b/config/routes.rb index cdd04a5..0c65d86 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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
- <%# 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} %> - <%= readout.quantity.relative_pathname(@superquantity) %> - <%= 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 %> <%= 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) } %> + + <%= image_button_tag '', 'delete-outline', class: 'dangerous', name: :discard, + formaction: discard_readouts_path(readout.quantity), + formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>