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
|
def defaults
|
||||||
# Units
|
# Units
|
||||||
available = @project.units.pluck(:shortname)
|
available = @project.units.pluck(:shortname)
|
||||||
defaults = Unit.where(project: nil).pluck(:name, :shortname)
|
defaults = Unit.where(project: nil).map do |u|
|
||||||
defaults.delete_if { |n, s| available.include?(s) }
|
u.attributes.except('id', 'project_id', 'created_at', 'updated_at')
|
||||||
@project.units.create(defaults.map { |n, s| {name: n, shortname: s} })
|
end
|
||||||
|
defaults.delete_if { |u| available.include?(u['shortname']) }
|
||||||
|
@project.units.create(defaults)
|
||||||
|
|
||||||
new_units = defaults.length
|
new_units = defaults.length
|
||||||
flash[:notice] = "Loaded #{new_units > 0 ? new_units : "no" } new" \
|
flash[:notice] = "Loaded #{new_units > 0 ? new_units : "no" } new" \
|
||||||
@ -22,13 +24,10 @@ class BodyTrackersController < ApplicationController
|
|||||||
defaults = Quantity.where(project: nil)
|
defaults = Quantity.where(project: nil)
|
||||||
Quantity.each_with_level(defaults) do |q, level|
|
Quantity.each_with_level(defaults) do |q, level|
|
||||||
unless available.has_key?([q.name, q.domain])
|
unless available.has_key?([q.name, q.domain])
|
||||||
obj = @project.quantities.create({
|
attrs = q.attributes.except('id', 'project_id', 'parent_id', 'lft', 'rgt',
|
||||||
domain: q.domain,
|
'created_at', 'updated_at')
|
||||||
parent: q.parent ? available[[q.parent.name, q.parent.domain]] : nil,
|
attrs['parent'] = q.parent ? available[[q.parent.name, q.parent.domain]] : nil
|
||||||
name: q.name,
|
obj = @project.quantities.create(attrs)
|
||||||
description: q.description,
|
|
||||||
primary: q.primary
|
|
||||||
})
|
|
||||||
available[[q.name, q.domain]] = obj
|
available[[q.name, q.domain]] = obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -39,9 +38,11 @@ class BodyTrackersController < ApplicationController
|
|||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
available = @project.sources.pluck(:name)
|
available = @project.sources.pluck(:name)
|
||||||
defaults = Source.where(project: nil).pluck(:name, :description)
|
defaults = Source.where(project: nil).map do |s|
|
||||||
defaults.delete_if { |n, d| available.include?(n) }
|
s.attributes.except('id', 'project_id', 'created_at', 'updated_at')
|
||||||
@project.sources.create(defaults.map { |n, d| {name: n, description: d} })
|
end
|
||||||
|
defaults.delete_if { |s| available.include?(s['name']) }
|
||||||
|
@project.sources.create(defaults)
|
||||||
|
|
||||||
new_sources = defaults.length
|
new_sources = defaults.length
|
||||||
flash[:notice] += " and #{new_sources > 0 ? new_sources : "no" } new" \
|
flash[:notice] += " and #{new_sources > 0 ? new_sources : "no" } new" \
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<th><%= l(:field_order) %></th>
|
<th><%= l(:field_order) %></th>
|
||||||
<th><%= l(:field_domain) %></th>
|
<th><%= l(:field_domain) %></th>
|
||||||
<th><%= l(:field_description) %></th>
|
<th><%= l(:field_description) %></th>
|
||||||
|
<th><%= l(:field_formula) %></th>
|
||||||
<th><%= l(:field_action) %></th>
|
<th><%= l(:field_action) %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -47,6 +48,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="domain"><%= q.domain %></td>
|
<td class="domain"><%= q.domain %></td>
|
||||||
<td class="description"><%= q.description %></td>
|
<td class="description"><%= q.description %></td>
|
||||||
|
<td class="formula"><%= checked_image q.formula.present? %></td>
|
||||||
<td class="action">
|
<td class="action">
|
||||||
<%=
|
<%=
|
||||||
link_to l(:button_edit), edit_quantity_path(q), {
|
link_to l(:button_edit), edit_quantity_path(q), {
|
||||||
@ -69,7 +71,8 @@
|
|||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<%=
|
<%=
|
||||||
link_to l(:button_cancel), "#",
|
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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user