From 544c0c52930a9288dc598fcb6b62d4542967e07c Mon Sep 17 00:00:00 2001
From: cryptogopher
Date: Mon, 17 Feb 2020 22:15:30 +0100
Subject: [PATCH] Updating Quantity to use Formula, WIP
---
app/controllers/quantities_controller.rb | 9 ++++++---
app/views/quantities/_form.html.erb | 6 ++++--
config/locales/en.yml | 1 +
test/unit/formula_test.rb | 2 +-
4 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb
index 994abf4..3e054bc 100644
--- a/app/controllers/quantities_controller.rb
+++ b/app/controllers/quantities_controller.rb
@@ -79,18 +79,21 @@ class QuantitiesController < ApplicationController
end
def quantity_params
- params[:quantity].delete(:formula) if params[:quantity][:formula].blank?
params.require(:quantity).permit(
:domain,
:parent_id,
:name,
:description,
- :formula
+ formula_attributes:
+ [
+ :code,
+ :zero_nil
+ ]
)
end
def prepare_quantities
@quantities = @project.quantities.filter(@project, session[:q_filters])
- .includes(:column_views)
+ .includes(:column_views, :formula)
end
end
diff --git a/app/views/quantities/_form.html.erb b/app/views/quantities/_form.html.erb
index 772643f..301d28c 100644
--- a/app/views/quantities/_form.html.erb
+++ b/app/views/quantities/_form.html.erb
@@ -11,6 +11,8 @@
{required: true, label: :field_parent_quantity, include_blank: t('.null_parent')} %>
<%= f.text_field :name, size: 25, required: true %>
<%= f.text_field :description, style: "width: 100%;" %>
- <%= f.text_field :formula, placeholder: t('.formula_placeholder'),
- style: "width: 100%;" %>
+ <%= f.fields_for :formula do |ff| %>
+ <%= ff.text_field :code, placeholder: t('.formula_placeholder'),
+ style: "width: 100%;" %>
+ <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 95286f7..53cb108 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -14,6 +14,7 @@ en:
field_domain: 'Domain'
field_parent_quantity: 'Parent'
field_formula: 'Formula'
+ field_code: 'Formula'
field_shortname: 'Short name'
button_retake: 'Retake'
activerecord:
diff --git a/test/unit/formula_test.rb b/test/unit/formula_test.rb
index 7446b9b..570430c 100644
--- a/test/unit/formula_test.rb
+++ b/test/unit/formula_test.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../test_helper', __FILE__)
class FormulaTest < ActiveSupport::TestCase
- include BodyTracking::Formula
+ include BodyTracking::FormulaBuilder
def setup
end