+ <%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
+ class: 'dangerous', onclick: render_turbo_stream('form_close') %>
+
<% end %>
+
+
diff --git a/app/views/measurements/_form_close.html.erb b/app/views/measurements/_form_close.html.erb
index a171e26..78511d4 100644
--- a/app/views/measurements/_form_close.html.erb
+++ b/app/views/measurements/_form_close.html.erb
@@ -1,2 +1,4 @@
-<%= turbo_stream.update :new_readouts_form %>
<%= turbo_stream.update :flashes %>
+<%= turbo_stream.remove :measurement_form %>
+<%= turbo_stream.show :no_items -%>
+<%= turbo_stream.enable :new_measurement_link -%>
diff --git a/app/views/measurements/_form_frame.html.erb b/app/views/measurements/_form_frame.html.erb
deleted file mode 100644
index fa7e7de..0000000
--- a/app/views/measurements/_form_frame.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-<%= tabular_fields_for Readout.new do |form| %>
-
+<%# TODO: show hint when no quantities/units defined %>
+
+
+
+
+ <%= render(@measurements) || render_no_items %>
+
+
diff --git a/app/views/measurements/new.turbo_stream.erb b/app/views/measurements/new.turbo_stream.erb
index 23f5364..253ac8a 100644
--- a/app/views/measurements/new.turbo_stream.erb
+++ b/app/views/measurements/new.turbo_stream.erb
@@ -1,9 +1,5 @@
-<%= turbo_stream.update :new_readouts_form do %>
- <%= render partial: 'form_frame' %>
-<% end if @prev_quantities.empty? %>
-
-<%= render partial: 'form_repath' %>
-
-<%= turbo_stream.before :new_readouts_actions do %>
+<%= turbo_stream.disable :new_measurement_link -%>
+<%= turbo_stream.hide :no_items -%>
+<%= turbo_stream.append_all 'body' do %>
<%= render partial: 'form' %>
<% end %>
diff --git a/app/views/quantities/_form.html.erb b/app/views/quantities/_form.html.erb
index 0e5a39d..3597590 100644
--- a/app/views/quantities/_form.html.erb
+++ b/app/views/quantities/_form.html.erb
@@ -1,5 +1,5 @@
<%= tabular_fields_for @quantity, form: form_tag do |form| %>
- <%- tag.tr id: row, class: "form", onkeydown: "processKey(event)",
+ <%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb
index 0ed1454..ea42e34 100644
--- a/app/views/quantities/index.html.erb
+++ b/app/views/quantities/index.html.erb
@@ -1,7 +1,8 @@
<% if current_user.at_least(:active) %>
<%= image_link_to t('.new_quantity'), 'plus-outline', new_quantity_path,
- id: dom_id(Quantity, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
+ id: dom_id(Quantity, :new, :link), onclick: 'this.blur();',
+ data: {turbo_stream: true} %>
<% end %>
<%#= image_link_to t('.import_quantities'), 'download-outline', default_quantities_path,
class: 'tools' %>
diff --git a/app/views/readouts/_form.html.erb b/app/views/readouts/_form.html.erb
new file mode 100644
index 0000000..d769a23
--- /dev/null
+++ b/app/views/readouts/_form.html.erb
@@ -0,0 +1,25 @@
+<%# TODO: add readout reordering by dragging %>
+<%= tabular_fields_for 'readouts[]', readout do |form| %>
+ <%- tag.tr id: dom_id(readout.quantity, :new, :readout) do %>
+ |
+ <%# 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.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 %>
+ |
+ <% end %>
+<% end %>
diff --git a/app/views/readouts/_form_repath.html.erb b/app/views/readouts/_form_repath.html.erb
new file mode 100644
index 0000000..5743dec
--- /dev/null
+++ b/app/views/readouts/_form_repath.html.erb
@@ -0,0 +1,7 @@
+<%= turbo_stream.update(:measurement_form_legend) { @superquantity&.pathname } %>
+
+<% @prev_quantities.each do |pq| %>
+ <%= turbo_stream.update dom_id(pq, nil, :pathname) do %>
+ <%= pq.relative_pathname(@superquantity) %>
+ <% end %>
+<% end %>
diff --git a/app/views/readouts/discard.turbo_stream.erb b/app/views/readouts/discard.turbo_stream.erb
new file mode 100644
index 0000000..6966b40
--- /dev/null
+++ b/app/views/readouts/discard.turbo_stream.erb
@@ -0,0 +1,4 @@
+<%= turbo_stream.disable :create_measurement_button if @prev_quantities.one? %>
+<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
+<%= 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
new file mode 100644
index 0000000..04ae31e
--- /dev/null
+++ b/app/views/readouts/new.turbo_stream.erb
@@ -0,0 +1,8 @@
+<% @readouts.each do |r| %>
+ <%= turbo_stream.disable dom_id(r.quantity) %>
+<% end %>
+<%= render partial: 'form_repath' %>
+<%= turbo_stream.append :readouts do %>
+ <%= render partial: 'form', collection: @readouts, as: :readout %>
+<% end %>
+<%= turbo_stream.enable :create_measurement_button if @prev_quantities.empty? %>
diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb
index 7fc73af..c419874 100644
--- a/app/views/units/_form.html.erb
+++ b/app/views/units/_form.html.erb
@@ -1,5 +1,5 @@
<%= tabular_fields_for @unit, form: form_tag do |form| %>
- <%- tag.tr id: row, class: "form", onkeydown: "processKey(event)",
+ <%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
diff --git a/config/initializers/core_ext.rb b/config/initializers/core_ext.rb
index e73da73..1233f1b 100644
--- a/config/initializers/core_ext.rb
+++ b/config/initializers/core_ext.rb
@@ -1,3 +1,4 @@
+require 'core_ext/array_delete_bang'
require 'core_ext/big_decimal_scientific_notation'
ActiveSupport.on_load :action_dispatch_system_test_case do
diff --git a/config/initializers/turbo_streams_tag_builder.rb b/config/initializers/turbo_streams_tag_builder.rb
index 6de180a..70fc9c1 100644
--- a/config/initializers/turbo_streams_tag_builder.rb
+++ b/config/initializers/turbo_streams_tag_builder.rb
@@ -19,7 +19,19 @@ ActiveSupport.on_load :turbo_streams_tag_builder do
action :hide, target, allow_inferred_rendering: false
end
+ def show(target)
+ action :show, target, allow_inferred_rendering: false
+ end
+
+ #def collapse(target)
+ # action :collapse, target, allow_inferred_rendering: false
+ #end
+
def close_form(target)
action :close_form, target, allow_inferred_rendering: false
end
+
+ def unselect(target)
+ action :unselect, target, allow_inferred_rendering: false
+ end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 91d310f..2d4286a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -64,10 +64,14 @@ en:
source_code: Get code
measurements:
navigation: Measurements
+ no_items: There are no measurements taken. You can Add some now.
+ form:
+ select_quantity: select the measured quantities...
index:
- new_quantity: Selected
- new_children: Children
- new_subtree: Subtree
+ new_measurement: Add measurement
+ readouts:
+ form:
+ select_unit: ...
quantities:
navigation: Quantities
no_items: There are no configured quantities. You can Add some or Import from defaults.
@@ -149,6 +153,7 @@ en:
other: (%{count} characters minimum)
actions: Actions
add: Add
+ apply: Apply
back: Back
cancel: Cancel
delete: Delete
diff --git a/config/routes.rb b/config/routes.rb
index 6218a39..7d3035d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,8 @@
Rails.application.routes.draw do
- resources :measurements, path_names: {new: '/new(/:scope)'},
- constraints: {scope: /children|subtree/}, defaults: {scope: nil} do
+ resources :measurements
- get 'discard/:id', on: :new, action: :discard, as: :discard
+ resources :readouts, only: [:new] do
+ collection {get 'new/:id/discard', action: :discard, as: :discard}
end
resources :quantities, except: [:show], path_names: {new: '(/:id)/new'} do
diff --git a/lib/core_ext/array_delete_bang.rb b/lib/core_ext/array_delete_bang.rb
new file mode 100644
index 0000000..c10f974
--- /dev/null
+++ b/lib/core_ext/array_delete_bang.rb
@@ -0,0 +1,10 @@
+module CoreExt
+ module ArrayDeleteBang
+ def delete!(obj)
+ self.delete(obj)
+ self
+ end
+ end
+end
+
+Array.prepend CoreExt::ArrayDeleteBang
|