forked from fixin.me/fixin.me
Prevent table columns' width change on form toggle
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M19.78,2.2L24,6.42L8.44,22L0,13.55L4.22,9.33L8.44,13.55L19.78,2.2M19.78,5L8.44,16.36L4.22,12.19L2.81,13.55L8.44,19.17L21.19,6.42L19.78,5Z" /></svg>
|
||||||
|
After Width: | Height: | Size: 227 B |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M13,7H11V11H7V13H11V17H13V13H17V11H13V7Z" /></svg>
|
|
||||||
|
Before Width: | Height: | Size: 297 B |
@@ -72,10 +72,20 @@
|
|||||||
fill: var(--color-border-gray) !important;
|
fill: var(--color-border-gray) !important;
|
||||||
pointer-events: none !important;
|
pointer-events: none !important;
|
||||||
}
|
}
|
||||||
/* Styles set `display` without distinguishing between [hidden] elements, making
|
/* For hidden elements that need to influence layout and/or are only temporarily
|
||||||
* them visible. */
|
* hidden use [hidden=until-found] instead of [hidden] to:
|
||||||
|
* - avoid hiding with `display: none` as `display` may be overridden by
|
||||||
|
* selectors with greater specificity and element may become visible,
|
||||||
|
* - use `visibility: collapse` for hiding, to avoid excessive resizing.
|
||||||
|
* TODO: change to `until-found` after upgrade to Rails > 8.1.4 (#59338)
|
||||||
|
* - change hidden values in index <tr>s
|
||||||
|
* - check if toggleAttribute("hidden") works properly (use turbo action #hide?)
|
||||||
|
[hidden=until-found] {
|
||||||
|
visibility: collapse;
|
||||||
|
}*/
|
||||||
[hidden] {
|
[hidden] {
|
||||||
display: none !important;
|
display: revert;
|
||||||
|
visibility: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,6 +239,7 @@ pre {
|
|||||||
display: flex;
|
display: flex;
|
||||||
fill: var(--color-gray);
|
fill: var(--color-gray);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.button {
|
.button {
|
||||||
border: 1px solid var(--color-gray);
|
border: 1px solid var(--color-gray);
|
||||||
@@ -252,6 +263,7 @@ table .button {
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0.4em;
|
padding: 0.4em;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
.button:focus-visible,
|
.button:focus-visible,
|
||||||
.tab:focus-visible,
|
.tab:focus-visible,
|
||||||
@@ -460,25 +472,26 @@ header {
|
|||||||
.tabular-form table td:last-child {
|
.tabular-form table td:last-child {
|
||||||
padding-inline-end: 0;
|
padding-inline-end: 0;
|
||||||
}
|
}
|
||||||
.tabular-form table :is(form, input, select, textarea):only-child {
|
.tabular-form table :is(input, select, textarea) {
|
||||||
margin-inline-start: 0;
|
margin-inline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* FIXME: <button> has different height (28px) inside <td> than <a> (29px) */
|
||||||
.items-table {
|
.items-table {
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 0.25em;
|
|
||||||
border-spacing: 0;
|
border-spacing: 0;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
.items-table:has(tbody > tr > td) {
|
.items-table:has(> tbody > tr > td) {
|
||||||
border: 1px solid var(--color-border-gray);
|
border: 1px solid var(--color-border-gray);
|
||||||
|
border-radius: 0.25em;
|
||||||
}
|
}
|
||||||
.items-table:has(tbody > tr > td) caption {
|
.items-table:has(> tbody > tr > td) caption {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.items-table tbody:not(:has(tr > td)){
|
.items-table tbody:not(:has(> tr > td)) {
|
||||||
visibility: collapse;
|
visibility: collapse;
|
||||||
}
|
}
|
||||||
.items-table th,
|
.items-table th,
|
||||||
@@ -496,13 +509,18 @@ header {
|
|||||||
.items-table td {
|
.items-table td {
|
||||||
border-top: 1px solid var(--color-border-gray);
|
border-top: 1px solid var(--color-border-gray);
|
||||||
height: 2.4em;
|
height: 2.4em;
|
||||||
padding: 0.1em 0 0.1em calc(1em + var(--depth) * 0.8em);
|
padding: 0.1em 0.5em;
|
||||||
}
|
}
|
||||||
|
.items-table td[style*="--depth"] {
|
||||||
|
padding-inline-start: calc(1em + var(--depth) * 0.8em);
|
||||||
|
}
|
||||||
|
.items-table td:has(> .button, > :where(form) > .button),
|
||||||
.items-table td:last-child {
|
.items-table td:last-child {
|
||||||
padding-inline-end: 0.1em;
|
padding-inline-end: 0.1em;
|
||||||
}
|
}
|
||||||
.items-table :is(form, input, select, textarea):only-child {
|
/* Vertically align text inside form controls with ordinary data cells. */
|
||||||
margin-inline-start: calc(-0.4em - 0.9px);
|
.items-table :is(input, select, textarea) {
|
||||||
|
margin-inline: calc(-0.4em - 0.9px);
|
||||||
}
|
}
|
||||||
/* For <a> to fill table cell completely, we use an `::after` pseudoelement. */
|
/* For <a> to fill table cell completely, we use an `::after` pseudoelement. */
|
||||||
/* TODO: expand to whole row? will require adjusting z-index on inputs/buttons */
|
/* TODO: expand to whole row? will require adjusting z-index on inputs/buttons */
|
||||||
|
|||||||
@@ -127,8 +127,7 @@ module ApplicationHelper
|
|||||||
private
|
private
|
||||||
|
|
||||||
def submit_default_value
|
def submit_default_value
|
||||||
svg_name = object ? (object.persisted? ? 'update' : 'plus-circle-outline') : ''
|
@template.svg_tag('check-outline', I18n.t(:"save"))
|
||||||
@template.svg_tag(svg_name, super)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -151,6 +150,8 @@ module ApplicationHelper
|
|||||||
def svg_tag(source, label = nil, options = {})
|
def svg_tag(source, label = nil, options = {})
|
||||||
label, options = nil, label if label.is_a? Hash
|
label, options = nil, label if label.is_a? Hash
|
||||||
svg_tag = tag.svg(**options) do
|
svg_tag = tag.svg(**options) do
|
||||||
|
# TODO: move pictograms to 1 file with unique IDs instead of `icon`
|
||||||
|
# TODO: add test/rake task to detect unused and missing pictograms
|
||||||
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)
|
label.blank? ? svg_tag : svg_tag + tag.span(label)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ window.numberValidate = numberValidate
|
|||||||
function formProcessKey(event) {
|
function formProcessKey(event) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "Escape":
|
case "Escape":
|
||||||
event.currentTarget.querySelector("a[name=cancel]").click()
|
event.currentTarget.querySelector("a[name=discard]").click()
|
||||||
break
|
break
|
||||||
// TODO: allow new line inside <textarea> (submit with ctrl-enter?)
|
// TODO: allow new line inside <textarea> (submit with ctrl-enter?)
|
||||||
case "Enter":
|
case "Enter":
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ class Quantity < ApplicationRecord
|
|||||||
# characters); this doesn't seem to apply to :string (implemented as varchar)
|
# characters); this doesn't seem to apply to :string (implemented as varchar)
|
||||||
validates :description, length: {maximum: type_for_attribute(:description).limit}
|
validates :description, length: {maximum: type_for_attribute(:description).limit}
|
||||||
|
|
||||||
|
# TODO: initialize `depth` to `parent.depth + 1`
|
||||||
|
|
||||||
# Update :depths of progenies after parent change
|
# Update :depths of progenies after parent change
|
||||||
before_save if: :parent_changed? do
|
before_save if: :parent_changed? do
|
||||||
self[:depth] = parent&.depth&.succ || 0
|
self[:depth] = parent&.depth&.succ || 0
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
<div class="flex reverse">
|
<div class="flex reverse">
|
||||||
<%= form.button id: :create_measurement_button, disabled: true -%>
|
<%= form.button id: :create_measurement_button, disabled: true -%>
|
||||||
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
<%= image_link_to t(:discard), "close-outline", measurements_path, name: :discard,
|
||||||
class: 'auxiliary dangerous', onclick: render_turbo_stream('form_close') %>
|
class: 'auxiliary dangerous', onclick: render_turbo_stream('form_close') %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<%= tabular_fields_for @quantity, form: form_tag do |form| %>
|
<%# locals: (record: Quantity.new, **attrs) %>
|
||||||
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
|
<%= tabular_fields_for record, form: attrs.dig(:data, :form) do |form| %>
|
||||||
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
|
<%- tag.tr class: "form", onkeydown: "formProcessKey(event)", **attrs do %>
|
||||||
|
|
||||||
<td style="--depth:<%= @quantity.depth %>">
|
<td style="--depth:<%= form.object.depth %>">
|
||||||
<%= form.text_field :name, autofocus: true, class: 'hstretch', required: true %>
|
<%= form.text_field :name, autofocus: true, class: 'hstretch', required: true %>
|
||||||
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
||||||
|
|
||||||
<td class="flex">
|
<td><%= form.button %>
|
||||||
<%= form.button %>
|
|
||||||
<%= image_link_to t(:cancel), "close-outline", quantities_path,
|
|
||||||
class: 'dangerous', name: :cancel,
|
|
||||||
onclick: render_turbo_stream('form_close', {row: row}) %>
|
|
||||||
<td>
|
<td>
|
||||||
|
<%= image_link_to t(:discard), "close-outline", quantities_path,
|
||||||
|
class: 'dangerous', name: :discard,
|
||||||
|
onclick: render_turbo_stream('form_close', {id: attrs[:id]}) %>
|
||||||
|
<td><!-- TODO: add aria-disabled drag handle with proper vertical alignment? -->
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<%= turbo_stream.close_form row %>
|
<%= turbo_stream.close_form id %>
|
||||||
<%= turbo_stream.update :flashes %>
|
<%= turbo_stream.update :flashes %>
|
||||||
|
|||||||
@@ -12,11 +12,11 @@
|
|||||||
<td><%= quantity.description %>
|
<td><%= quantity.description %>
|
||||||
|
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<td class="flex">
|
<td>
|
||||||
<%= image_link_to t('.new_subquantity'), 'plus-outline',
|
<%= image_link_to t('.new_subquantity'), 'plus-outline',
|
||||||
new_quantity_path(quantity), id: dom_target(:new, quantity, :link),
|
new_quantity_path(quantity), id: dom_target(:new, quantity, :link),
|
||||||
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
|
<td>
|
||||||
<%= image_button_to_if quantity.destroyable?, t('.destroy'), 'delete-outline',
|
<%= image_button_to_if quantity.destroyable?, t('.destroy'), 'delete-outline',
|
||||||
quantity_path(quantity), method: :delete %>
|
quantity_path(quantity), method: :delete %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<% ids = {row: dom_target(:edit, @quantity),
|
<% attrs = {record: @quantity,
|
||||||
|
id: dom_target(:edit, @quantity),
|
||||||
|
data: {form: dom_target(:edit, @quantity, :form),
|
||||||
hidden_row: dom_target(@quantity),
|
hidden_row: dom_target(@quantity),
|
||||||
link: nil,
|
link: nil}} %>
|
||||||
form_tag: dom_target(:edit, @quantity, :form)} %>
|
|
||||||
|
|
||||||
<%= turbo_stream.append_all 'body' do %>
|
<%= turbo_stream.append_all 'body' do %>
|
||||||
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do %>
|
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= turbo_stream.hide ids[:hidden_row] %>
|
<%= turbo_stream.hide attrs[:data][:hidden_row] %>
|
||||||
<%= turbo_stream.after @quantity, partial: 'form', locals: ids -%>
|
<%= turbo_stream.after @quantity, partial: 'form', locals: attrs -%>
|
||||||
|
|||||||
@@ -15,17 +15,22 @@
|
|||||||
<th class="hmintext"><%= Quantity.human_attribute_name(:name) %>
|
<th class="hmintext"><%= Quantity.human_attribute_name(:name) %>
|
||||||
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %>
|
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %>
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<th><%= t :actions %>
|
<th colspan="3"><%= t :actions %>
|
||||||
<th>
|
|
||||||
|
|
||||||
<tr id="quantity_" hidden
|
<tr id="quantity_" hidden
|
||||||
ondragover="dragOver(event)" ondrop="drop(event)"
|
ondragover="dragOver(event)" ondrop="drop(event)"
|
||||||
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
||||||
data-drop-id="quantity_"
|
data-drop-id="quantity_"
|
||||||
data-drop-id-param="<%= field_name(:quantity, :parent_id) %>">
|
data-drop-id-param="<%= field_name(:quantity, :parent_id) %>">
|
||||||
<th colspan="4"><%= t '.top_level_drop' %>
|
<th colspan="5"><%= t '.top_level_drop' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render @quantities %>
|
<%= render @quantities %>
|
||||||
|
|
||||||
|
<% if current_user.at_least(:active) %>
|
||||||
<tr id="endmark" hidden>
|
<tr id="endmark" hidden>
|
||||||
|
|
||||||
|
<tfoot>
|
||||||
|
<%= render partial: 'form', locals: {hidden: true} %>
|
||||||
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<% target_id = dom_target(:new, @quantity.parent || :quantity) %>
|
<% target_id = dom_target(:new, @quantity.parent || :quantity) %>
|
||||||
<% ids = {row: target_id,
|
<% attrs = {record: @quantity,
|
||||||
|
id: target_id,
|
||||||
|
data: {form: dom_target(target_id, :form),
|
||||||
hidden_row: nil,
|
hidden_row: nil,
|
||||||
link: dom_target(target_id, :link),
|
link: dom_target(target_id, :link)}} %>
|
||||||
form_tag: dom_target(target_id, :form)} %>
|
|
||||||
|
|
||||||
<%= turbo_stream.disable ids[:link] -%>
|
<%= turbo_stream.disable attrs[:data][:link] -%>
|
||||||
|
|
||||||
<%= turbo_stream.append_all 'body' do %>
|
<%= turbo_stream.append_all 'body' do %>
|
||||||
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do |form| %>
|
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do |form| %>
|
||||||
<%= form.hidden_field :parent_id if @quantity.parent_id? %>
|
<%= form.hidden_field :parent_id if @quantity.parent_id? %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: ids %>
|
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: attrs %>
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
<%= tabular_fields_for @unit, form: form_tag do |form| %>
|
<%# locals: (record: Unit.new, **attrs) %>
|
||||||
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
|
<%= tabular_fields_for record, form: attrs.dig(:data, :form) do |form| %>
|
||||||
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
|
<%- tag.tr class: "form", onkeydown: "formProcessKey(event)", **attrs do %>
|
||||||
|
|
||||||
<td style="--depth:<%= @unit.base_id? ? 1 : 0 %>">
|
<td style="--depth:<%= form.object.base_id? ? 1 : 0 %>">
|
||||||
<%= form.text_field :symbol, autofocus: true, class: 'hstretch', required: true %>
|
<%= form.text_field :symbol, autofocus: true, class: 'hstretch', required: true %>
|
||||||
<td>
|
<td>
|
||||||
<% if @unit.base_id? %>
|
<% if form.object.base_id? %>
|
||||||
<%= form.number_field :multiplier, class: 'hstretch', required: true %>
|
<%= form.number_field :multiplier, class: 'hstretch', required: true %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
||||||
|
|
||||||
<td class="flex">
|
<td><%= form.button %>
|
||||||
<%= form.button %>
|
|
||||||
<%= image_link_to t(:cancel), "close-outline", units_path, class: 'dangerous',
|
|
||||||
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
|
||||||
<td>
|
<td>
|
||||||
|
<%= image_link_to t(:discard), "close-outline", units_path, class: 'dangerous',
|
||||||
|
name: :discard, onclick: render_turbo_stream('form_close', {id: attrs[:id]}) %>
|
||||||
|
<td><!-- TODO: add aria-disabled drag handle with proper vertical alignment? -->
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<%= turbo_stream.close_form row %>
|
<%= turbo_stream.close_form id %>
|
||||||
<%= turbo_stream.update :flashes %>
|
<%= turbo_stream.update :flashes %>
|
||||||
|
|||||||
@@ -14,13 +14,13 @@
|
|||||||
<td><%= unit.description %>
|
<td><%= unit.description %>
|
||||||
|
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<td class="flex">
|
<td>
|
||||||
<% unless unit.base_id? %>
|
<% unless unit.base_id? %>
|
||||||
<%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit),
|
<%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit),
|
||||||
id: dom_target(:new, unit, :link), onclick: 'this.blur();',
|
id: dom_target(:new, unit, :link), onclick: 'this.blur();',
|
||||||
data: {turbo_stream: true} %>
|
data: {turbo_stream: true} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<td>
|
||||||
<%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline',
|
<%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline',
|
||||||
unit_path(unit), method: :delete %>
|
unit_path(unit), method: :delete %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<% ids = {row: dom_target(:edit, @unit),
|
<% attrs = {record: @unit,
|
||||||
|
id: dom_target(:edit, @unit),
|
||||||
|
data: {form: dom_target(:edit, @unit, :form),
|
||||||
hidden_row: dom_target(@unit),
|
hidden_row: dom_target(@unit),
|
||||||
link: nil,
|
link: nil}} %>
|
||||||
form_tag: dom_target(:edit, @unit, :form)} %>
|
|
||||||
|
|
||||||
<%= turbo_stream.append_all 'body' do %>
|
<%= turbo_stream.append_all 'body' do %>
|
||||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
<%- tabular_form_with model: @unit, html: {id: attrs[:data][:form]} do %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= turbo_stream.hide ids[:hidden_row] %>
|
<%= turbo_stream.hide attrs[:data][:hidden_row] %>
|
||||||
<%= turbo_stream.after @unit, partial: 'form', locals: ids -%>
|
<%= turbo_stream.after @unit, partial: 'form', locals: attrs -%>
|
||||||
|
|||||||
@@ -16,18 +16,26 @@
|
|||||||
<th class="hminnumber"><%= Unit.human_attribute_name(:multiplier) %>
|
<th class="hminnumber"><%= Unit.human_attribute_name(:multiplier) %>
|
||||||
<th class="hexpand"><%= Unit.human_attribute_name(:description) %>
|
<th class="hexpand"><%= Unit.human_attribute_name(:description) %>
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<th><%= t :actions %>
|
<th colspan="3"><%= t :actions %>
|
||||||
<th>
|
|
||||||
|
|
||||||
<tr id="unit_" hidden
|
<tr id="unit_" hidden
|
||||||
ondragover="dragOver(event)" ondrop="drop(event)"
|
ondragover="dragOver(event)" ondrop="drop(event)"
|
||||||
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
||||||
data-drop-id="unit_" data-drop-id-param="<%= field_name(:unit, :base_id) %>">
|
data-drop-id="unit_" data-drop-id-param="<%= field_name(:unit, :base_id) %>">
|
||||||
<th colspan="5"><%= t '.top_level_drop' %>
|
<th colspan="6"><%= t '.top_level_drop' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render @units %>
|
<%= render @units %>
|
||||||
<%# Hidden rows with IDs allow simplier row insertion by using only
|
|
||||||
|
<% if current_user.at_least(:active) %>
|
||||||
|
<%# Hidden header and `#endmark` rows allows simplier row insertion by using only
|
||||||
turbo_stream #after/#before instead of #after + #prepend/#before + #append. %>
|
turbo_stream #after/#before instead of #after + #prepend/#before + #append. %>
|
||||||
|
<%# TODO: replace with custom turbo_stream action, e.g. #afterrow that #prepend-s
|
||||||
|
if ID has `rows` property (`rows` in object) and #after otherwise? %>
|
||||||
<tr id="endmark" hidden>
|
<tr id="endmark" hidden>
|
||||||
|
|
||||||
|
<tfoot>
|
||||||
|
<%# Insert form to prevent actions column width change on form toggle. %>
|
||||||
|
<%= render partial: 'form', locals: {hidden: true} %>
|
||||||
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
<% target_id = dom_target(:new, @unit.base || :unit) %>
|
<% target_id = dom_target(:new, @unit.base || :unit) %>
|
||||||
<% ids = {row: target_id,
|
<% attrs = {record: @unit,
|
||||||
|
id: target_id,
|
||||||
|
data: {form: dom_target(target_id, :form),
|
||||||
hidden_row: nil,
|
hidden_row: nil,
|
||||||
link: dom_target(target_id, :link),
|
link: dom_target(target_id, :link)}} %>
|
||||||
form_tag: dom_target(target_id, :form)} %>
|
|
||||||
|
|
||||||
<%= turbo_stream.disable ids[:link] -%>
|
<%= turbo_stream.disable attrs[:data][:link] -%>
|
||||||
|
<%# TODO: disable base unit delete button if subunit; same for quantities %>
|
||||||
|
|
||||||
<%= turbo_stream.append_all 'body' do %>
|
<%= turbo_stream.append_all 'body' do %>
|
||||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do |form| %>
|
<%- tabular_form_with model: @unit, html: {id: attrs[:data][:form]} do |form| %>
|
||||||
<%= form.hidden_field :base_id if @unit.base_id? %>
|
<%= form.hidden_field :base_id if @unit.base_id? %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= turbo_stream.after @unit.base || :unit_, partial: 'form', locals: ids %>
|
<%= turbo_stream.after @unit.base || :unit_, partial: 'form', locals: attrs %>
|
||||||
|
|||||||
@@ -3,3 +3,4 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<%= turbo_stream.remove @unit %>
|
<%= turbo_stream.remove @unit %>
|
||||||
<%= turbo_stream.before @before || :endmark, @unit %>
|
<%= turbo_stream.before @before || :endmark, @unit %>
|
||||||
|
<%# TODO: move new subunit form as well if open %>
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ en:
|
|||||||
unconfirmed_email_html: >
|
unconfirmed_email_html: >
|
||||||
Awaiting confirmation for:<br><em>(since %{confirmation_sent_at})</em>
|
Awaiting confirmation for:<br><em>(since %{confirmation_sent_at})</em>
|
||||||
submit:
|
submit:
|
||||||
create: Create
|
|
||||||
update: Update
|
|
||||||
user:
|
user:
|
||||||
update: Update profile
|
update: Update profile
|
||||||
layouts:
|
layouts:
|
||||||
@@ -181,10 +179,11 @@ en:
|
|||||||
add: Add
|
add: Add
|
||||||
apply: Apply
|
apply: Apply
|
||||||
back: Back
|
back: Back
|
||||||
cancel: Cancel
|
|
||||||
delete: Delete
|
delete: Delete
|
||||||
|
discard: Discard
|
||||||
:no: 'no'
|
:no: 'no'
|
||||||
register: Register
|
register: Register
|
||||||
|
save: Save
|
||||||
sign_in: Sign in
|
sign_in: Sign in
|
||||||
recover_password: Recover password
|
recover_password: Recover password
|
||||||
resend_confirmation: Resend confirmation
|
resend_confirmation: Resend confirmation
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
|||||||
|
|
||||||
# Override to count only data rows, to make it consistent with #match_row.
|
# Override to count only data rows, to make it consistent with #match_row.
|
||||||
def match_row_count(size)
|
def match_row_count(size)
|
||||||
XPath.descendant(:tr).where(XPath.descendant(:td)).count.equals(size)
|
XPath.descendant(:tbody).descendant(:tr)[XPath.descendant(:td)].count.equals(size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,15 +92,22 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
|||||||
# Based on Capybara :table and :table_row selectors.
|
# Based on Capybara :table and :table_row selectors.
|
||||||
Capybara.add_selector(:table_cell, locator_type: [String, Symbol]) do
|
Capybara.add_selector(:table_cell, locator_type: [String, Symbol]) do
|
||||||
xpath do |locator|
|
xpath do |locator|
|
||||||
|
xpath = XPath.descendant(:td)
|
||||||
|
case locator
|
||||||
|
when String, Symbol
|
||||||
# TODO: make sure to only include visible column headers
|
# TODO: make sure to only include visible column headers
|
||||||
column = XPath.string.n.is(locator.to_s)
|
column = XPath.string.n.is(locator.to_s)
|
||||||
header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[column]
|
header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[column]
|
||||||
position_xp = XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
|
position_xp = XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
|
||||||
XPath.descendant(:td).where(header_xp.boolean & position_xp)
|
xpath.where(header_xp.boolean & position_xp)
|
||||||
|
else
|
||||||
|
xpath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
expression_filter(:fillable) do |xpath, value|
|
expression_filter(:fillable) do |xpath, value|
|
||||||
value ? xpath.where(XPath.descendant(:input, :select, :textarea)) : xpath
|
value ? xpath[XPath.descendant(:input, :select, :textarea)
|
||||||
|
.where(!XPath.attr(:type).one_of('submit', 'hidden'))] : xpath
|
||||||
end
|
end
|
||||||
|
|
||||||
node_filter(:value) do |node, expected|
|
node_filter(:value) do |node, expected|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
[name, value]
|
[name, value]
|
||||||
end
|
end
|
||||||
|
|
||||||
click_on t('helpers.submit.create')
|
click_on t(:save)
|
||||||
end
|
end
|
||||||
attributes = attributes.to_h
|
attributes = attributes.to_h
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
click_on t('units.index.new_unit')
|
click_on t('units.index.new_unit')
|
||||||
end
|
end
|
||||||
find(:table_cell, column(:symbol), fillable: true).fill_in with: unit.symbol
|
find(:table_cell, column(:symbol), fillable: true).fill_in with: unit.symbol
|
||||||
click_on t('helpers.submit.create')
|
click_on t(:save)
|
||||||
|
|
||||||
within :table_row, index+1 do
|
within :table_row, index+1 do
|
||||||
assert_selector :table_cell, column(:symbol), exact_text: symbol
|
assert_selector :table_cell, column(:symbol), exact_text: symbol
|
||||||
@@ -190,7 +190,7 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
else
|
else
|
||||||
assert_matches_selector link, :link, disabled: true
|
assert_matches_selector link, :link, disabled: true
|
||||||
end
|
end
|
||||||
click_on t(:cancel)
|
click_on t(:discard)
|
||||||
|
|
||||||
assert_no_selector '.flash.alert'
|
assert_no_selector '.flash.alert'
|
||||||
# TODO: change to assert_selector :table, rows: ...
|
# TODO: change to assert_selector :table, rows: ...
|
||||||
@@ -258,13 +258,27 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
sign_in
|
sign_in
|
||||||
click_on t('units.index.new_unit')
|
click_on t('units.index.new_unit')
|
||||||
within 'tbody' do
|
within 'tbody' do
|
||||||
find(:link_or_button, exact_text: t(:cancel)).click
|
find(:link_or_button, exact_text: t(:discard)).click
|
||||||
assert_no_selector :fillable_field
|
assert_no_selector :fillable_field
|
||||||
end
|
end
|
||||||
click_on t('units.index.new_unit')
|
click_on t('units.index.new_unit')
|
||||||
assert_selector 'tbody > tr:has(input, textarea)'
|
assert_selector 'tbody > tr:has(input, textarea)'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "new and edit forms open without changing table columns width" do
|
||||||
|
sign_in
|
||||||
|
width = if has_selector?(:table_row)
|
||||||
|
-> { all(:table_row).sample.all(:table_cell).map { |c| c.rect.width } }
|
||||||
|
else
|
||||||
|
link_labels.slice!(:new_unit)
|
||||||
|
-> { find(:table).rect.width }
|
||||||
|
end
|
||||||
|
assert_no_changes width do
|
||||||
|
all(:link, exact_text: link_labels.values.sample).sample.click
|
||||||
|
assert_selector :table_cell, fillable: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "rebase" do
|
test "rebase" do
|
||||||
# TODO
|
# TODO
|
||||||
assert true
|
assert true
|
||||||
|
|||||||
Reference in New Issue
Block a user