forked from fixin.me/fixin.me
		
	Merging from main master to my repo master. #4
@ -123,6 +123,10 @@ module ApplicationHelper
 | 
			
		||||
    "Turbo.renderStreamMessage('#{j(render partial: partial, locals: locals)}'); return false;"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def disabled_attributes(disabled)
 | 
			
		||||
    disabled ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  # Converts value to HTML formatted scientific notation
 | 
			
		||||
 | 
			
		||||
@ -57,13 +57,12 @@ class Unit < ApplicationRecord
 | 
			
		||||
            )
 | 
			
		||||
          ).as('portable')
 | 
			
		||||
        ),
 | 
			
		||||
      # TODO: replace AS and MIN with Arel
 | 
			
		||||
      # TODO: turn off ONLY_FULL_GROUP_BY
 | 
			
		||||
      # Add missing base Units. Duplicates will be removed by final group(), as
 | 
			
		||||
      # actionable Units will differ on 'portable' column and can't be UNION-ed.
 | 
			
		||||
      # NOTE: turn off ONLY_FULL_GROUP_BY or is it incompatible with other DBs?
 | 
			
		||||
      # Fill base Units to display proper hierarchy. Duplicates will be removed
 | 
			
		||||
      # by final group() - can't be deduplicated with UNION due to 'portable' field.
 | 
			
		||||
      arel_table.join(actionable_units).on(actionable_units[:base_id].eq(arel_table[:id]))
 | 
			
		||||
        .project(arel_table[Arel.star], 'NULL AS portable')
 | 
			
		||||
    ]).select(units: column_names)#, 'MIN(units.portable)' => :portable)
 | 
			
		||||
        .project(arel_table[Arel.star], Arel::Nodes.build_quoted(nil).as('portable'))
 | 
			
		||||
    ]).select(units: column_names).select(units[:portable].minimum.as('portable'))
 | 
			
		||||
      .from(units).group(Unit.column_names)
 | 
			
		||||
  }
 | 
			
		||||
  scope :ordered, ->{
 | 
			
		||||
 | 
			
		||||
@ -1,20 +1,22 @@
 | 
			
		||||
<%= 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 %>
 | 
			
		||||
  </td>
 | 
			
		||||
 | 
			
		||||
  <td class="actions">
 | 
			
		||||
    <% unless unit.portable.nil? %>
 | 
			
		||||
      <% if current_user.at_least(:active) && unit.default? %>
 | 
			
		||||
        <%= image_button_to t('.import'), 'download-outline', import_default_unit_path(unit),
 | 
			
		||||
        !unit.portable? ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {}  %>
 | 
			
		||||
          disabled_attributes(!unit.portable?) %>
 | 
			
		||||
      <% end %>
 | 
			
		||||
      <% if current_user.at_least(:admin) %>
 | 
			
		||||
      <% if !unit.default? %>
 | 
			
		||||
        <%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit),
 | 
			
		||||
          !unit.portable? ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {}  %>
 | 
			
		||||
        <% if unit.default? %>
 | 
			
		||||
          <%= image_button_to t('.delete'), 'delete-outline', unit_path(unit), method: :delete %>
 | 
			
		||||
        <% else %>
 | 
			
		||||
        <%= image_button_to t('.delete'), 'delete-outline', unit_path(unit),
 | 
			
		||||
          method: :delete %>
 | 
			
		||||
          <%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit),
 | 
			
		||||
            disabled_attributes(!unit.portable?) %>
 | 
			
		||||
        <% end %>
 | 
			
		||||
      <% end %>
 | 
			
		||||
    <% end %>
 | 
			
		||||
  </td>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user