Disable Unit destuction for base units with subunits

Closes #40
This commit is contained in:
cryptogopher 2024-12-28 23:57:47 +01:00
parent bd40727231
commit 8552571526
6 changed files with 15 additions and 8 deletions

View File

@ -12,7 +12,7 @@ class Default::UnitsController < ApplicationController
end end
def index def index
@units = current_user.units.defaults_diff.includes(:base).ordered @units = current_user.units.defaults_diff.includes(:base).includes(:subunits).ordered
end end
def import def import

View File

@ -9,7 +9,7 @@ class UnitsController < ApplicationController
end end
def index def index
@units = current_user.units.includes(:subunits).ordered @units = current_user.units.includes(:base).includes(:subunits).ordered
end end
def new def new

View File

@ -12,7 +12,7 @@
<% if current_user.at_least(:admin) %> <% if current_user.at_least(:admin) %>
<% if unit.default? %> <% if unit.default? %>
<%= image_button_to t('.delete'), 'delete-outline', default_unit_path(unit), <%= image_button_to t('.delete'), 'delete-outline', default_unit_path(unit),
method: :delete %> method: :delete, **disabled_attributes(!unit.movable?) %>
<% else %> <% else %>
<%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit), <%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit),
disabled_attributes(!unit.portable?) %> disabled_attributes(!unit.portable?) %>

View File

@ -17,8 +17,8 @@
id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %> id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
<% end %> <% end %>
<%= image_button_to t('.delete_unit'), 'delete-outline', unit_path(unit), <%= image_button_to t('.destroy'), 'delete-outline', unit_path(unit),
method: :delete %> method: :delete, **disabled_attributes(!unit.movable?) %>
</td> </td>
<% if unit.movable? %> <% if unit.movable? %>
<td class="handle" draggable="true">&#x283F</td> <td class="handle" draggable="true">&#x283F</td>

View File

@ -59,7 +59,7 @@ en:
no_items: There are no configured units. You can Add some or Import from defaults. no_items: There are no configured units. You can Add some or Import from defaults.
unit: unit:
new_subunit: Subunit new_subunit: Subunit
delete_unit: Delete destroy: Delete
index: index:
new_unit: Add unit new_unit: Add unit
import_units: Import import_units: Import

View File

@ -162,6 +162,13 @@ class UnitsTest < ApplicationSystemTestCase
assert_selector 'tbody > tr:has(input, textarea)' assert_selector 'tbody > tr:has(input, textarea)'
end end
#test "destroy" do test "destroy" do
#end link = all(:link_or_button, exact_text: t('units.unit.destroy')).sample
label = link.ancestor('tr').first(:link)[:text]
assert_difference ->{ @user.units.count }, -1 do
link.click
end
assert_selector 'tbody tr', count: [@user.units.count, 1].max
assert_selector '.flash.notice', text: t('units.destroy.success', unit: label)
end
end end