Display Defaults hierarchy including same base Units

This commit is contained in:
cryptogopher 2024-11-22 03:10:08 +01:00
parent 6c678b6560
commit 279f9bd6ac
3 changed files with 23 additions and 18 deletions

View File

@ -123,6 +123,10 @@ module ApplicationHelper
"Turbo.renderStreamMessage('#{j(render partial: partial, locals: locals)}'); return false;" "Turbo.renderStreamMessage('#{j(render partial: partial, locals: locals)}'); return false;"
end end
def disabled_attributes(disabled)
disabled ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {}
end
private private
# Converts value to HTML formatted scientific notation # Converts value to HTML formatted scientific notation

View File

@ -57,13 +57,12 @@ class Unit < ApplicationRecord
) )
).as('portable') ).as('portable')
), ),
# TODO: replace AS and MIN with Arel # NOTE: turn off ONLY_FULL_GROUP_BY or is it incompatible with other DBs?
# TODO: turn off ONLY_FULL_GROUP_BY # Fill base Units to display proper hierarchy. Duplicates will be removed
# Add missing base Units. Duplicates will be removed by final group(), as # by final group() - can't be deduplicated with UNION due to 'portable' field.
# actionable Units will differ on 'portable' column and can't be UNION-ed.
arel_table.join(actionable_units).on(actionable_units[:base_id].eq(arel_table[:id])) arel_table.join(actionable_units).on(actionable_units[:base_id].eq(arel_table[:id]))
.project(arel_table[Arel.star], 'NULL AS portable') .project(arel_table[Arel.star], Arel::Nodes.build_quoted(nil).as('portable'))
]).select(units: column_names)#, 'MIN(units.portable)' => :portable) ]).select(units: column_names).select(units[:portable].minimum.as('portable'))
.from(units).group(Unit.column_names) .from(units).group(Unit.column_names)
} }
scope :ordered, ->{ scope :ordered, ->{

View File

@ -1,20 +1,22 @@
<%= tag.tr do %> <%= tag.tr do %>
<td class="<%= class_names({subunit: unit.base, grayed: unit.default?}) %>"> <td class="<%= class_names({subunit: unit.base,
grayed: unit.default? && !unit.portable.nil? }) %>">
<%= unit.symbol %> <%= unit.symbol %>
</td> </td>
<td class="actions"> <td class="actions">
<% if current_user.at_least(:active) && unit.default? %> <% unless unit.portable.nil? %>
<%= image_button_to t('.import'), 'download-outline', import_default_unit_path(unit), <% if current_user.at_least(:active) && unit.default? %>
!unit.portable? ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {} %> <%= image_button_to t('.import'), 'download-outline', import_default_unit_path(unit),
<% end %> disabled_attributes(!unit.portable?) %>
<% if current_user.at_least(:admin) %> <% end %>
<% if !unit.default? %> <% if current_user.at_least(:admin) %>
<%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit), <% if unit.default? %>
!unit.portable? ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {} %> <%= image_button_to t('.delete'), 'delete-outline', unit_path(unit), method: :delete %>
<% else %> <% else %>
<%= image_button_to t('.delete'), 'delete-outline', unit_path(unit), <%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit),
method: :delete %> disabled_attributes(!unit.portable?) %>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
</td> </td>