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