Upgraded defaults import to include future fields by default
Added Quantity index formula checkmark display
This commit is contained in:
parent
80d49de30e
commit
6433621fa7
@ -8,9 +8,11 @@ class BodyTrackersController < ApplicationController
|
||||
def defaults
|
||||
# Units
|
||||
available = @project.units.pluck(:shortname)
|
||||
defaults = Unit.where(project: nil).pluck(:name, :shortname)
|
||||
defaults.delete_if { |n, s| available.include?(s) }
|
||||
@project.units.create(defaults.map { |n, s| {name: n, shortname: s} })
|
||||
defaults = Unit.where(project: nil).map do |u|
|
||||
u.attributes.except('id', 'project_id', 'created_at', 'updated_at')
|
||||
end
|
||||
defaults.delete_if { |u| available.include?(u['shortname']) }
|
||||
@project.units.create(defaults)
|
||||
|
||||
new_units = defaults.length
|
||||
flash[:notice] = "Loaded #{new_units > 0 ? new_units : "no" } new" \
|
||||
@ -22,13 +24,10 @@ class BodyTrackersController < ApplicationController
|
||||
defaults = Quantity.where(project: nil)
|
||||
Quantity.each_with_level(defaults) do |q, level|
|
||||
unless available.has_key?([q.name, q.domain])
|
||||
obj = @project.quantities.create({
|
||||
domain: q.domain,
|
||||
parent: q.parent ? available[[q.parent.name, q.parent.domain]] : nil,
|
||||
name: q.name,
|
||||
description: q.description,
|
||||
primary: q.primary
|
||||
})
|
||||
attrs = q.attributes.except('id', 'project_id', 'parent_id', 'lft', 'rgt',
|
||||
'created_at', 'updated_at')
|
||||
attrs['parent'] = q.parent ? available[[q.parent.name, q.parent.domain]] : nil
|
||||
obj = @project.quantities.create(attrs)
|
||||
available[[q.name, q.domain]] = obj
|
||||
end
|
||||
end
|
||||
@ -39,9 +38,11 @@ class BodyTrackersController < ApplicationController
|
||||
|
||||
# Sources
|
||||
available = @project.sources.pluck(:name)
|
||||
defaults = Source.where(project: nil).pluck(:name, :description)
|
||||
defaults.delete_if { |n, d| available.include?(n) }
|
||||
@project.sources.create(defaults.map { |n, d| {name: n, description: d} })
|
||||
defaults = Source.where(project: nil).map do |s|
|
||||
s.attributes.except('id', 'project_id', 'created_at', 'updated_at')
|
||||
end
|
||||
defaults.delete_if { |s| available.include?(s['name']) }
|
||||
@project.sources.create(defaults)
|
||||
|
||||
new_sources = defaults.length
|
||||
flash[:notice] += " and #{new_sources > 0 ? new_sources : "no" } new" \
|
||||
|
@ -9,6 +9,7 @@
|
||||
<th><%= l(:field_order) %></th>
|
||||
<th><%= l(:field_domain) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_formula) %></th>
|
||||
<th><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -47,6 +48,7 @@
|
||||
</td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="formula"><%= checked_image q.formula.present? %></td>
|
||||
<td class="action">
|
||||
<%=
|
||||
link_to l(:button_edit), edit_quantity_path(q), {
|
||||
@ -69,7 +71,8 @@
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<%=
|
||||
link_to l(:button_cancel), "#",
|
||||
onclick: '$(this).closest("tr").remove(); $("#quantities a.icon-edit").css("visibility", "visible"); '
|
||||
onclick: '$(this).closest("tr").remove();
|
||||
$("#quantities a.icon-edit").css("visibility", "visible");'
|
||||
%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user