Compare commits
3 Commits
279f9bd6ac
...
bdc4ec4644
Author | SHA1 | Date | |
---|---|---|---|
bdc4ec4644 | |||
1d439928e2 | |||
e157c17e0e |
@ -18,9 +18,10 @@ class Default::UnitsController < ApplicationController
|
||||
end
|
||||
|
||||
def import
|
||||
params = @unit.slice(Unit::ATTRIBUTES - [:symbol, :base_id])
|
||||
current_user.units
|
||||
.find_or_initialize_by(symbol: @unit.symbol)
|
||||
.update!(base: @base, **@unit.slice(:name, :multiplier))
|
||||
.update!(base: @base, **params)
|
||||
run_and_render :index
|
||||
end
|
||||
|
||||
@ -40,6 +41,6 @@ class Default::UnitsController < ApplicationController
|
||||
|
||||
def find_unit(user)
|
||||
@unit = Unit.find_by!(id: params[:id], user: user)
|
||||
@base = Unit.find_by!(symbol: @unit.base.symbol, user: user? ? nil : user) if @unit.base
|
||||
@base = Unit.find_by!(symbol: @unit.base.symbol, user: user ? nil : current_user) if @unit.base
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ class UnitsController < ApplicationController
|
||||
private
|
||||
|
||||
def unit_params
|
||||
params.require(:unit).permit(:symbol, :name, :base_id, :multiplier)
|
||||
params.require(:unit).permit(Unit::ATTRIBUTES)
|
||||
end
|
||||
|
||||
def find_unit
|
||||
|
@ -1,4 +1,6 @@
|
||||
class Unit < ApplicationRecord
|
||||
ATTRIBUTES = [:symbol, :name, :multiplier, :base_id]
|
||||
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :base, optional: true, class_name: "Unit"
|
||||
has_many :subunits, class_name: "Unit", dependent: :restrict_with_error, inverse_of: :base
|
||||
|
@ -1,6 +1,7 @@
|
||||
<div class="rightside buttongrid">
|
||||
<% if current_user.at_least(:active) %>
|
||||
<%= image_link_to t('.import_all'), 'download-multiple-outline',
|
||||
<%# TODO: implement Import all %>
|
||||
<%#= image_link_to t('.import_all'), 'download-multiple-outline',
|
||||
import_all_default_units_path, data: {turbo_stream: true} %>
|
||||
<% end %>
|
||||
<%= image_link_to t('.back'), 'arrow-left-bold-outline', units_path, class: 'tools' %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user