forked from fixin.me/fixin.me
Preliminary support for default Units import
This commit is contained in:
parent
be48d6fd7f
commit
846eb6da14
@ -14,6 +14,24 @@ class Unit < ApplicationRecord
|
|||||||
validates :multiplier, numericality: {other_than: 0}, if: :base
|
validates :multiplier, numericality: {other_than: 0}, if: :base
|
||||||
|
|
||||||
scope :defaults, ->{ where(user: nil) }
|
scope :defaults, ->{ where(user: nil) }
|
||||||
|
scope :with_defaults, ->{ self.or(Unit.where(user: nil)) }
|
||||||
|
scope :default_diff, ->{
|
||||||
|
other_units = Unit.arel_table.alias('other_units')
|
||||||
|
other_bases_units = Unit.arel_table.alias('other_bases_units')
|
||||||
|
constraints = other_bases_units[:id].eq(other_units[:base_id])
|
||||||
|
.and(other_units[:symbol].eq(arel_table[:symbol]))
|
||||||
|
.and(other_units[:user_id].not_eq(arel_table[:user_id]))
|
||||||
|
|
||||||
|
with_defaults
|
||||||
|
.joins(
|
||||||
|
arel_table.create_join(
|
||||||
|
arel_table.grouping([other_units, other_bases_units]),
|
||||||
|
arel_table.create_on(constraints),
|
||||||
|
Arel::Nodes::OuterJoin
|
||||||
|
).to_sql
|
||||||
|
)
|
||||||
|
.where({other_units: {id: nil}})
|
||||||
|
}
|
||||||
scope :ordered, ->{
|
scope :ordered, ->{
|
||||||
left_outer_joins(:base)
|
left_outer_joins(:base)
|
||||||
.order(arel_table.coalesce(Arel::Table.new(:bases_units)[:symbol], arel_table[:symbol]),
|
.order(arel_table.coalesce(Arel::Table.new(:bases_units)[:symbol], arel_table[:symbol]),
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<%= image_link_to t('.add_unit'), 'plus-outline', new_unit_path, id: :add_unit,
|
<%= image_link_to t('.add_unit'), 'plus-outline', new_unit_path, id: :add_unit,
|
||||||
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
<%= image_link_to t('.import_units'), 'import', new_unit_path, class: 'tools',
|
<%= image_link_to t('.import_units'), 'import', units_defaults_path, class: 'tools',
|
||||||
data: {turbo_stream: true} %>
|
data: {turbo_stream: true} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,7 +9,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
namespace :units do
|
namespace :units do
|
||||||
get 'defaults/index'
|
resources :defaults, only: :index
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :users, only: [:index, :show, :update] do
|
resources :users, only: [:index, :show, :update] do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user