forked from fixin.me/fixin.me
Implement Measurements#new
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header class="htoolbox">
|
||||
<header class="hflex">
|
||||
<%= image_link_to t(".source_code"), "code-braces", source_code_url %>
|
||||
<%= image_link_to t(".issue_tracker"), "bug-outline", issue_tracker_url,
|
||||
class: "extendedright" %>
|
||||
|
||||
45
app/views/measurements/_form.html.erb
Normal file
45
app/views/measurements/_form.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<%= tabular_form_with model: current_user, html: {id: :new_readouts_form} do |user| %>
|
||||
<% if @readouts&.present? %>
|
||||
<fieldset>
|
||||
<%= tag.legend @ancestor_fullname unless @ancestor_fullname.empty? %>
|
||||
<table class="items centered">
|
||||
<tbody id="readouts">
|
||||
<%= user.fields_for :readouts, @readouts do |form| %>
|
||||
<% row = dom_id(form.object.quantity, :new, :readout) %>
|
||||
<%- tag.tr id: row, onkeydown: 'processKey(event)' do %>
|
||||
<td>
|
||||
<%= form.object.quantity.fullname.delete_prefix(@ancestor_fullname) %>
|
||||
<%= form.hidden_field :quantity_id %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.number_field :value, required: true, autofocus: true,
|
||||
size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.select :unit_id, options_from_collection_for_select(
|
||||
@units, :id, ->(u){ sanitize(' '*(u.base_id ? 1 : 0) + u.symbol) }
|
||||
) %>
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<%= image_link_to t(:delete), 'delete-outline', quantities_path,
|
||||
class: 'dangerous',
|
||||
onclick: render_turbo_stream('form_destroy_row', {row: row}) %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<tr id="new_readouts_actions">
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td><div class="actions"><%= user.button %></div></td>
|
||||
<td><div class="actions">
|
||||
<%= image_link_to t(:cancel), "close-outline", measurements_path,
|
||||
class: 'dangerous', name: :cancel,
|
||||
onclick: render_turbo_stream('form_close') %>
|
||||
</div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
<% end %>
|
||||
2
app/views/measurements/_form_close.html.erb
Normal file
2
app/views/measurements/_form_close.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= turbo_stream.update :new_readouts_form %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
2
app/views/measurements/_form_destroy_row.html.erb
Normal file
2
app/views/measurements/_form_destroy_row.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= turbo_stream.remove row %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
@@ -1,16 +1,20 @@
|
||||
<div class="main">
|
||||
<div class="topside vflex">
|
||||
<% if current_user.at_least(:active) %>
|
||||
<%= render partial: 'form' %>
|
||||
<%# TODO: show hint when no quantities/units defined %>
|
||||
<%= form_tag new_measurement_path, method: :get, class: "htoolbox",
|
||||
data: {turbo_stream: true} do %>
|
||||
<%= select_tag :id,
|
||||
options_from_collection_for_select(@quantities, :id,
|
||||
->(q) { sanitize('- '*q.depth + q.name) }) %>
|
||||
<%= image_button_tag t('.new_quantity'), 'plus-outline', name: :scope -%>
|
||||
<div class="hflex">
|
||||
<%= select_tag :id, options_from_collection_for_select(
|
||||
@quantities, :id, ->(q){ sanitize(' '*q.depth + q.name) }
|
||||
), form: :new_readouts_form %>
|
||||
<% common_options = {form: :new_readouts_form, formaction: new_measurement_path,
|
||||
formmethod: :get, formnovalidate: true,
|
||||
data: {turbo_stream: true}} %>
|
||||
<%= image_button_tag t('.new_quantity'), 'plus-outline', name: :scope,
|
||||
**common_options -%>
|
||||
<%= image_button_tag t('.new_children'), 'plus-multiple-outline', name: :scope,
|
||||
value: :children -%>
|
||||
value: :children, **common_options -%>
|
||||
<%= image_button_tag t('.new_subtree'), 'plus-multiple-outline', name: :scope,
|
||||
value: :subtree -%>
|
||||
<% end %>
|
||||
value: :subtree, **common_options -%>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
3
app/views/measurements/new.turbo_stream.erb
Normal file
3
app/views/measurements/new.turbo_stream.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= turbo_stream.replace :new_readouts_form, method: :morph do %>
|
||||
<%= render partial: 'form' %>
|
||||
<% end %>
|
||||
@@ -7,7 +7,7 @@
|
||||
class: 'tools' %>
|
||||
</div>
|
||||
|
||||
<%= tag.div id: :quantity_form %>
|
||||
<%= tag.div class: 'main', id: :quantity_form %>
|
||||
|
||||
<table class="main items">
|
||||
<thead>
|
||||
|
||||
Reference in New Issue
Block a user